We are a rookie team, team 2595. We want to use the default code that we got but don’t know if it’ll work. We are running a 2 motor drive and the default code is a 4 motor drive???
How do we change the default code to work for teleoperated for a 2 motor drive?
Alright, are you using MPLAB or EasyC? If you’re using EasyC, I really can’t help… With MPLAB, you should be able to comment out all lines that refer to pwms that don’t exist on your robot and have whatever you’re using work fine.
With MPLAB, the following should work for tank drive:
pwm01 = pwm02 = p1_y;
pwm03 = pwm04 = p2_y;
This assumes pwms 1 and 2 are the left wheels and port 1 is the left joystick; pwms 3 and 4 are the right wheels, and port 2 is the right joystick.
When both joysticks are forwards, all motors are forward and the robot goes forward. When both are back, the robot goes backwards. When one joystick is forward and one is backwards, the left and right motors move in opposite directions and the robot twists clockwise or counterclockwise.
This also assumes that forwards is all motors moving in the same direction or that the wires for one side are hooked up backwards. If this is not the case, your robot will spin when you push both joysticks forwards and go straight with one joystick forwards and the other backwards. To correct this, subtract the offending side (i.e., the side that’s going in reverse when you push the stick forwards) from 254 to reverse the direction.
Back to your original question…
If you choose to use the default code’s “1 Joystick Drive”, read on…
If you are using MPLAB and programming in C, you will not actually need to do anything to the code (except what I said above, except you’d be subtracting the Limit_Mix result from 254) unless you want to use the PWM outputs for the second motors for something else. Simply connect the left-hand motor’s speed controller to PWM 13 or 14, and the right-hand motor’s speed controller to 15 or 16 and leave the other ports unconnected.
If you do want to use those PWM outputs for something else, you need to locate the following lines in user_routines.c:
p1_x = 255 - p1_y;
p1_y = 255 - pwm05;
pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);
…and modify them so that they only use one PWM output each, like so:
p1_x = 255 - p1_y;
p1_y = 255 - pwm05;
pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = Limit_Mix(2000 + p1_y - p1_x + 127);
…which will free up PWM outputs 13 and 16 for other things. Note that you can use any two PWMs you want for driving motor control; it doesn’t have to be 13, 14, 15 and 16, or 14 and 15; if you want to use PWMs 1 and 2 for driving, just change the variables from pwm14 and pwm15 to pwm01 and pwm02, respectively.