Programming+Syntax+and+Code


 * For the teleop:**

/* This code will program the robot to move using the two joystick controls. The left joy stick will control the robot's left motors and the right joystick will control the robot's right motors. We are not placing the complete controls on one controller as it makes the program very complicated. Unlike games, we don't need to do that as the robot doesn't have to look around unlike call of duty.

I have left out the pragma statements in this example as the program will generate them. Also, instead of the motors named motorA and motorB or whatever, I changed the name to left and right motor. This can be altered on robotC in the pragma statements. We can work on that, don't worry about it.

task main { while(true){ // make an infinite loop for teleop so it takes readings all the time getJoystickSettings(joystick); // this gets the values from the joystick to use

if (joystick.joy1_y1<5 && joystick.joy1_y1>-5){ // I'm not sure if you guys got here yet, but this prevents movement when in the joystick control dead zone. motor[leftMotor] = joystick.joy1_y1*100/127; // this ensures that the motors are assigned values between -100 and 100 and not outside of that range }

if(joystick.joy1_y2<5 && joystick.joy1_y2>-5){ //do the same for the right motor but with the right joystick. motor[rightMotor] = joystick.joy1_y2 *100/127; } } }

/* This code will make the robot move infinitely forward. You guys may want to try something else (e.g. move it right and left) up to you. Just get it moving. Once that's done, get the servos moving.
 * For the autonomous:**

I have left out the pragma statements in this example as the program will generate them. Also, instead of the motors named motorA and motorB or whatever, I changed the name to left and right motor. This can be altered on robotC in the pragma statements. We can work on that, don't worry about it.

task main{ while(true) { // infinite loop will ensure that the robot moves infinitely forward motor[leftMotor] = 100; //set the left motor to 100% power motor[rightMotor] = 100; //set the right motor to 100% power } }