|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
control all driving with one joystick
does anyone know how to program the robot to drive with one joystick
|
|
#2
|
||||
|
||||
|
Re: control all driving with one joystick
Depends, what program are you using? if your using easyC just change the programming from tank to arcade
|
|
#3
|
|||
|
|||
|
Re: control all driving with one joystick
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 |
|
#4
|
|||
|
|||
|
Re: control all driving with one joystick
i am using the 2wd on arcade.
|
|
#5
|
|||
|
|||
|
Re: control all driving with one joystick
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
|
|
#6
|
|||
|
|||
|
Re: control all driving with one joystick
i dont know what that means.
|
|
#7
|
|||
|
|||
|
Re: control all driving with one joystick
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:
This is what our code that processes joystick values into motor values sort of looks like: Code:
/* 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 */
}
Good luck! If you have any other questions, please ask! - Taj |
|
#8
|
|||
|
|||
|
Re: control all driving with one joystick
Quote:
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!! |
|
#9
|
||||
|
||||
|
Re: control all driving with one joystick
Quote:
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! |
|
#10
|
|||
|
|||
|
Re: control all driving with one joystick
Well, its unique enough that it would require some fancy code to make it work so nice.
|
|
#11
|
||||
|
||||
|
Re: control all driving with one joystick
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.....
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| We need help with joystick control | Team ICE #1611 | Control System | 4 | 24-01-2005 15:57 |
| One Joystick Control | KWalsh | Programming | 4 | 24-02-2004 17:53 |
| problem with joystick buttons (top left one) | Richomundo | Programming | 5 | 15-02-2004 17:16 |
| how do i control a piston with a joystick | Ryan Foley | Programming | 2 | 27-05-2003 17:13 |
| Control system with one joystick(or two) | CharlieWilken | Technical Discussion | 3 | 04-02-2002 09:20 |