|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Mechanum wheel programming in C++
my understand is that we need to specify each motor/wheel assembly , ie all four individually as each wheel is connected indepedently to a single motor.
so then do we use the above statements for each motor/wheel assembly? thanks have you actually written some code just to move the bot with mechanum wheels? |
|
#2
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
Quote:
You take the commands from the joysticks and you process them (it's called inverse kinematics) to create the 4 wheel speeds. The drive interface could be a single 3-axis joystick, or two 2-axis joysticks, or any other input device(s). Mecanum has three completely independent degrees of freedom: fore/aft strafe (right/left) rotate (turn, yaw) A mecanum vehicle can perform all three of these motions simultaneously. Here's some reference C code for you: Code:
// 3-axis joystick interface to a mecanum drive
// define your driver interface,
// in this case a 3-axis joystick:
forward = -Y;
right = X;
clockwise = Z;
// put any drivability adjustments here for forward, right, and clockwise,
// for example gain, deadband, etc:
// if rotate gain is too hot, tweak it down:
clockwise /= 2;
// add deadband so you don't get strafe when you don't want it:
if ((right>-0.1)&&(right<0.1)) right = 0;
// now apply the inverse kinematic tranformation:
front_left = forward + clockwise + right;
front_right = forward - clockwise - right;
rear_left = forward + clockwise - right;
rear_right = forward - clockwise + right;
// finally, normalize so that no wheel speed command
// exceeds magnitude of 1:
max = abs(front_left);
temp = abs(front_right);
if (temp>max) max = temp;
temp = abs(rear_left);
if (temp>max) max = temp;
temp = abs(rear_right);
if (temp>max) max = temp;
if (max>1)
{front_left/=max; front_right/=max; rear_left/=max; rear_right/=max;}
// you're done. send these four wheel commands to their respective wheels
|
|
#3
|
|||
|
|||
|
Re: Mechanum wheel programming in C++
Quote:
|
|
#4
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
Quote:
Last edited by Ether : 01-18-2011 at 11:14 AM. |
|
#5
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
What about field-centric? My team tried this out a few times but got really weird results. Would the following code snippet be correct?
Code:
[...] gyro->Reset(); float theta = gyro->GetAngle(); [...] yVal2=(float) (yVal*Math.cos(theta) - xVal*Math.sin(theta)); xVal2=(float) (yVal*Math.sin(theta) + xVal*Math.cos(theta)); |
|
#6
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
WPILib now has mecanum code, with field-centric option. Take a look at that (use just use it as-is).
|
|
#7
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
Quote:
Code:
Either:
RobotDrive(UINT32 frontLeftMotorChannel, UINT32 rearLeftMotorChannel,
UINT32 frontRightMotorChannel, UINT32 rearRightMotorChannel,
float sensitivity = 0.5);
Or:
RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
SpeedController *frontRightMotor, SpeedController *rearRightMotor,
float sensitivity = 0.5);
Last edited by mikets : 01-10-2011 at 09:12 PM. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|