|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#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 : 08-14-2012 at 10:43 PM. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|