|
dallasrobotics
Rookie
Joined: Thu Nov 19, 2009 1:21 pm Posts: 11
|
 Servos with the controller
Here is our code, there are no errors. The robot shakes because the program is continually cycling through the if statements, if we go through step by step it will work. However our question is why is it executing the code in the if statements if no buttons are pressed?
#pragma config(Hubs, S1, HTMotor, HTServo, none, none) #pragma config(Motor, mtr_S1_C1_1, motorLeft, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C1_2, motorRight, tmotorNormal, openLoop, reversed) #pragma config(Servo, srvo_S1_C2_1, ScoopLeft, tServoNormal) #pragma config(Servo, srvo_S1_C2_2, ScoopRight, tServoNormal) #pragma config(Servo, srvo_S1_C2_3, Gate, tServoNormal) #pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone) #pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone) #pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone) #pragma config(SrvoPosition, Down, 224, 32, 128, 128, 128, 128, 128, 128) #pragma config(SrvoPosition, Up, 100, 146, 128, 128, 128, 128, 128, 128) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c"
task main() { while(true) {
if(joy1Btn(1)); // If button 1 is pressed { servo[ScoopLeft] = 100; servo[ScoopRight] = 146;
servoChangeRate[ScoopLeft] = 0; servoChangeRate[ScoopRight] = 0;
}
if(joy1Btn(2)); // If button 2 is pressed { servo[ScoopLeft] = 224; servo[ScoopRight] = 32;
servoChangeRate[ScoopLeft] = 5; servoChangeRate[ScoopRight] = 5;
}
if(joy1Btn(3)); // If button 3 is pressed { servo[Gate] = 60;
servoChangeRate[Gate] = 5;
}
if(joy1Btn(4)); // If button 4 is pressed { servo[Gate] = 128;
servoChangeRate[Gate] = 5;
}
} }
|
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: Servos with the controller
Hey there, If there were no errors, surely it would work as intended?  I am not familiar with the workings of the servos (I don't own a controller), but I noticed that you have code for when a button is pressed, but no code for when no buttons are pressed. Do you not need to stop the servos when you are not pressing any buttons at all? Could this be the source of your problems? Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|