Thomas
Rookie
Joined: Sun Jan 23, 2011 11:24 am Posts: 5
|
 Final Drive-Code Questions
I believe I have my final code for teleOp before going to my FTC competition this Saturday. I just had some questions and was wondering if anyone could answer them for me regarding this following code:
1.) For some reason, when i toggle back on my joystick, the robot goes forward. I do not know why this occurs. It happens for both sides (y1 & y2)
2.) The robot will not come to a complete stop when I let go of the joystick. I thought I put in the right code but apparently not.
If anyone can answer these questions I would be greatly appreciative. Thanks!
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none) #pragma config(Motor, motorA, kickMotor, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorB, leftGrabber, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorC, rightGrabber, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S1_C1_1, leftMotors, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S1_C1_2, rightMotors, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S1_C2_1, armMotors, tmotorNormal, PIDControl, reversed, encoder) #pragma config(Motor, mtr_S1_C2_2, motorG, tmotorNormal, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
void initializeRobot() { // Place code here to sinitialize servos to starting positions. // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.
return; }
task main() { initializeRobot();
waitForStart(); // wait for start of tele-op phase
int thresholdP = 10; int thresholdN = -10;
while (true) { getJoystickSettings(joystick); if(abs((joystick.joy1_y1)) > thresholdP);
motor[leftMotors] = (joystick.joy1_y1);
motor[leftMotors] = 0; { motor[leftMotors] = (joystick.joy1_y1); } if(abs((joystick.joy1_y2)) > thresholdP); { motor[rightMotors] = -(joystick.joy1_y2);
motor[armMotors] = (joystick.joy2_y2);
motor[kickMotor] = (joystick.joy2_y1); } } }
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Final Drive-Code Questions
you want the left wheels to be controlled by joystick.joy1_y1, the right wheels to be controlled by joystick.joy1_y2 when the joysticks are above the threshold right? This is how you would implement that: When you write an if statement, you write it like this: If you use a semicolon at the end, you're telling it to do nothing. Not to confuse you, but to save space, you can also write the code like this:
_________________ sudo rm -rf /
|
Thomas
Rookie
Joined: Sun Jan 23, 2011 11:24 am Posts: 5
|
 Re: Final Drive-Code Questions
Ok thank-you that helped a lot. This might also be a stupid question, but how do you make the buttons work on the joystick?
I know that joystick.joy1_y1 or y2 are the toggles, but how does it connect to a button?
Would it be something like (joystick.joy1_btn2)?
Thanks!
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Final Drive-Code Questions
For all your syntax questions, there are a host of RobotC sample programs. I don't have RobotC in front of me right now, but it's something like joy1Btn(Button Number).
_________________ sudo rm -rf /
|