|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
West Coast Drive Code
My team, 2582, is switching to the West Coast drive this year. As the team's head programmer, I'm looking for information on the drive code itself. Can anyone help me learn the code?
|
|
#2
|
|||
|
|||
|
Re: West Coast Drive Code
In terms of software, WCD is no different than any other skid steer setup. Differing velocities of the wheels against the ground on either side of the robot create a torque about the center of the robot which causes it to turn.
So, a naive approach to how to control a WCD robot is something like this. In fact if you boot up a robot in WPILib using a single joystick and arcade drive, this is exactly what you will get. Code:
// Throttle is how fast we want to be moving foward or backward. // Turn is how fast we want to spin about the center. left = throttle + turn; right = throttle - turn; Code:
// 0 throttle, .5 turn left = 0 + .5 = .5 right = 0 - .5 = -.5 net difference: 1.0 // 1 throttle, .5 turn left = 1 + .5 = 1.5 = 1.0 (can't go faster than 100% right = 1 - .5 = .5 net difference : .5 Code:
double skim(double v) {
// gain determines how much to skim off the top
if (v > 1.0)
return -((v - 1.0) * gain);
else if (v < -1.0)
return -((v + 1.0) * gain);
return 0;
}
t_left = throttle + turn;
t_right = throttle - turn;
left = t_left + skim(t_right);
right = t_right + skim(t_left);
One approach to fix this is to amp up turn so you can turn harder while going fast Code:
turn = turn * 1.5; ... drive code from above ... Code:
turn = turn * (another_gain * fabs(throttle)); Code:
if (!turnButton) turn = turn * (another_gain * fabs(throttle)); Another way to solve this would be only apply the throttle dependent turning when throttle has reached a certain threshold. This can get a little weird at the transition point, though. Code:
if (throttle > .5)
turn = turn * (another_gain * fabs(throttle));
Last edited by Tom Bottiglieri : 14-08-2012 at 22:43. |
|
#3
|
||||
|
||||
|
Re: West Coast Drive Code
Last edited by Ether : 14-08-2012 at 23:31. |
|
#4
|
||||
|
||||
|
Re: West Coast Drive Code
Here's pseudocode and sample contour maps for a 2-parameter tunable Arcade algorithm. One parameter adjusts the strength of the turn at max throttle, the other adjusts the strength of the turn at zero throttle. The left and right wheel speeds are smoothly interpolated for partial throttle so that the wheel speeds stay in the range -1 to +1 without the need for clipping. Please note: The tunable algorithm attachment is near the bottom of the list1: http://www.chiefdelphi.com/media/papers/2661 1As of 8/17/2012, that is. As new attachments are added, they are put at the bottom of the list. AFAIK, vBulletin provides no way to rearrange the attachments into a more sensible order Last edited by Ether : 17-08-2012 at 19:47. |
|
#5
|
||||
|
||||
|
Re: West Coast Drive Code
@Tom
How does one determine the "gain?" Trial and error, algorithms, etc? Would something like this be correct? Code:
// Xbox Controller
Joystick Xbox = new Joystick(1);
// Drivetrain
public double throttle = Xbox.getRawAxis(3);
public double turn = applyDeadband(Xbox);
public double leftMtr = throttle + turn;
public double rightMtr = throttle + turn;
//This will need to be tuned
public double gain = 1;
private double applyDeadband(Joystick Xbox) {
if(Math.abs(Xbox.getRawAxis(1)) < 0.1) return 0;
else return Xbox.getRawAxis(1);
}
private double skim(double v) {
// gain determines how much to skim off the top
if (v > 1.0)
return -((v - 1.0) * gain);
else if (v < -1.0)
return -((v + 1.0) * gain);
return 0;
}
public double getLeftMotor() {
return leftMtr + skim(rightMtr);
}
public double getRightMotor() {
return rightMtr + skim(leftMtr);
}
Last edited by F22Rapture : 17-08-2012 at 13:44. |
|
#6
|
||||
|
||||
|
Re: West Coast Drive Code
Run the code and create a contour map. Then carefully study the contour map to see if it's what you want.
Quote:
I have pseudocode that takes that a step further and does throttle-dependent nonlinear interpolation of the wheel speeds, but that seems like overkill. However if there's any interest I'll post that too. Quote:
|
|
#7
|
||||
|
||||
|
Re: West Coast Drive Code
Thanks for the plain-english explanation Tom. This is a great explanation of how to take generic C++ and make it speak Robot for brand new programmers.
@Rapture If you want to go the trial & error route: The simplest way for the driver to determine what gain is best suited for the specific style of driving would be to use a throttle or button setup to adjust it on the fly. That way you don't have to re-compile and re-upload code to make adjustments. Or, better yet, the gain could be adjustable from the driver's station. |
|
#8
|
||||
|
||||
|
Re: West Coast Drive Code
OK I can take a hint. Here's a plain-English explanation for arcade linear interpolation: http://www.chiefdelphi.com/media/papers/download/3495 |
|
#9
|
|||
|
|||
|
Re: West Coast Drive Code
Quote:
For the most part, we tune our turning around 100% throttle. Any time spent out of 100% throttle while traversing the field is time wasted. Any time that requires less than 100% throttle is usually a straight line approach. @Ether Nice! We will definitely need to try that out. |
|
#10
|
||||
|
||||
|
Re: West Coast Drive Code
Thanks to everyone who offered advice; this will really help me understand the west coast drive code. Is this all compatible with the Wind River C++ coding program?
|
|
#11
|
||||
|
||||
|
Re: West Coast Drive Code
I've read through this several times. I believe I understand it, but it only seems to be useful in the case where you are using one joystick as the throttle and the other to turn.
Wouldn't using a two joystick setup where you only use the y-axis on both not have the problem all this coding is trying to correct? You can turn at high speeds by feathering one joystick, and turn at lows speeds by slamming the joysticks in opposite directions. Or am I missing a benefit in the throttle/turn joystick setup? Last edited by Tom Line : 08-10-2012 at 13:16. |
|
#12
|
||||
|
||||
|
Re: West Coast Drive Code
Quote:
Quote:
|
|
#13
|
|||
|
|||
|
Re: West Coast Drive Code
Quote:
cheers arun |
|
#14
|
||||
|
||||
|
Re: West Coast Drive Code
Quote:
1for those interested, the derivation is explained here Last edited by Ether : 25-02-2013 at 16:44. |
|
#15
|
|||
|
|||
|
Re: West Coast Drive Code
Great, quick question -
would setting a = 0.25; b = 0.40; be similar to setting: a=0 b=1 and passing the joystick inputs through a cubic? |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|