does anyone know how to program the robot to drive with one joystick
Depends, what program are you using? if your using easyC just change the programming from tank to arcade
It would also depend on your drivebase. Are you using:
4wd
6wd
Tank Tread
Ackermann
4 wheel 90 offset Omni
3 wheel 120 offset Omni (Kiwi)
Swerve/Crab (4 rotateable pods)
Mecanum
1565-esque Linkage Drive
etc
i am using the 2wd on arcade.
kevin’s code has a limit_mix function by default, so i’d think that you could just use that … just assign your drive motor pwm’s to the value returned by limit_mix
i dont know what that means.
What are you using to program your robot? easyC, the default code, WPILib…?
This year we experimented with two different drive modes: arcade mode and RC-Car style drive (two joysticks, one for forward/backward and one for steering).
If you’re using WPILib or easyC, arcade mode for 2 wheel drive is fairly easy to do. I don’t have experience with easyC, but with WPILib/MPLab, you need to call Arcade2() function in your OperatorControl(). Unfortunately, I appear to have lost the code that I used for it, but check the docs (page 41) for more information. Basically, you just need to pass Arcade2 the joystick port you’re using (PORT_1, PORT_2, etc), the axis of the joystick (X_AXIS, Y_AXIS), the PWM ports that your victors are plugged into (1, 2, etc), and if either your left or right motor is inverted (1=inverted, 0=not, I think).
If you’re not using WPILib, you can still do the mixing of the joysticks manually and achieve the same result. This is what we ended up doing because we wanted more control over how sensitive the joysticks were (and so we could use a gyro to keep our bot driving in a straight line).
Our final code worked something like this:
- Read Joystick Values
- Processed the joystick values through a function that mixed the X and the Y into PWM values for our 2 motors
- Sent the motor values to the PWMs
This is what our code that processes joystick values into motor values sort of looks like:
/* OurDrive
* Takes joystick x and y and converts into motor values.
* Then drives motors.
* WARNING: Unlike the numbers you get from the joysticks,
x and y are signed (-127 - 127). Also, the x val is expected to
go from -127 (full left) to 127 (full right). Make sure you convert
the joystick vals to signed and multiply x by -1.
*/
void OurDrive(int x, int y) {
int rm, lm; // values to send to motors
if ((x==0) && (y==0)) { //not going anywhere
rm=0;
lm=0;
}
else if (x==0) { //driving straight
rm = lm = y;
}
else if (y==0) { //spin turn
rm=(x*-1)/2;
lm=x/2;
}
else if (x<0 && y>0) {//forward left,, y pos & x neg
if (y-x > 127){//turn by decrease
rm= y;
lm=y+x;
}
else{//turn by increase
rm=y-x;
lm=y;
}
}
else if (x<0 && y<0) {//back left, y neg & x neg
if (y-x < -127) { //turn by decrease
rm=y-x;
lm=y;
}
else { //turn by increase
rm=y;//drive backwards
lm=y+x;//add neg x to neg y, lm goes back faster
}
}
else if (x>0 && y>0) {//forward right, y pos & x pos
if (y+x>127) {//turn by decrease
lm = y;
rm = y-x;
}
else {//turn by increase
lm = y+x;
rm = y;
}
}
else if (x>0 && y<0) {//back right, y neg & x pos
if (y-x<-127){//turn by decrease
rm= y;
lm=y+x;
}
else {//turn by increase
rm=y-x;
lm=y;
}
}
/* now, drive your motors with the PWM values of lm and rm. In WPILib, you use Motors(lm,rm);
Make sure you convert the numbers to unsigned if you drive the PWMs directly */
}
Now, just read the x and y axis from the same joystick and send it to the OurDrive() function. You will probably want to process the joystick variables somehow to make the drive more controllable. We gave the drivers the option of dividing by 4 or 6 (selectable by pressing a button on a joystick) to make for a fairly controllable robot.
Good luck! If you have any other questions, please ask!
- Taj
Bwaha, we are on our drive system class
And for the record we only use one joystick, only ever have used one joystick
I think we use blend functions to drive it with one joystick.
Drive foreward: all wheels turn foreward
Drive backward: all wheels turn backwards
Turn left: left wheels turn back, right wheels turn foreward
Turn right: left wheels turn forward, right wheels turn back
Those are the extremes, and then we set up a blend function (not sure if it something we made or not though) to blend the extremes together for any other joystick position.
For the record, I am not the programmer, that all I know about, and I have heard the term blend function so many times from them while they work on the drive program, so it must be important!!
best of luck!!
for the record, yes, we made it. the best example i’ve seen is in the IFI 2007 default code (NOT kevin watson 2008 code). in user_routines.c, look for the limit_mix() function as where as where it is called. that’s basic tank drive. now, if you’re like me, that’s way too complicated. simplify it. make the right side wheels and the left side wheels the actual joystick value, then blend (add to) the x-axis joystick values to what the wheels are already doing.
EX.
pwm01=pwm02=p1_y; //right wheels forward with the joystick
pwm03=pwm04=flip(p1_y); //flip() simply makes 255 into 0, and so on
pwm01=pwm03=blend(pwm01,p1_x); //add p1_x to what pwm01 is already doing
pwm03=pwm04=blend(pwm03,flip(p1_x)); //same with other side.
of course, this is very simple. when you realize that the KOP joysitcks arent the bast things to use and have a lot of error, you’ll want to make a function that returns if it’s around a certain value, say, 127 perhaps?
good luck!
Well, its unique enough that it would require some fancy code to make it work so nice.
not to give away our secret, but it’s remarkable similar to what i described in my earlier post on how basic one joystick drive works…