|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
|||
|
|||
|
Mechanum wheel programming in C++
Has anyone programmed the mechanum wheels using C++?/
if so could you share? thanks |
|
#2
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
The WPI library provides the RobotDrive object that includes a method:
Code:
void RobotDrive::MecanumDrive_Polar(float magnitude, float direction, float rotation) To calculate the magnitude and direction from joystick reading, you can do: Code:
MecanumDrive_Polar(joystick->GetMagnitude(), joystick->GetDirectionDegrees(), 0.0); Last edited by mikets : 10-01-2011 at 20:21. |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
||||
|
||||
|
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
|
|
#5
|
|||
|
|||
|
Re: Mechanum wheel programming in C++
Quote:
|
|
#6
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
Quote:
Last edited by Ether : 18-01-2011 at 11:14. |
|
#7
|
||||
|
||||
|
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)); |
|
#8
|
||||
|
||||
|
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).
|
|
#9
|
||||
|
||||
|
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 : 10-01-2011 at 21:12. |
|
#10
|
|||
|
|||
|
Re: Mechanum wheel programming in C++
Quote:
Quote:
-Joe |
|
#11
|
|||
|
|||
|
Re: Mechanum wheel programming in C++
so does one need only two joysticks or do you need to use 4 with two drivers. seems to me two joysticks would work. Did you find any brand or type better than another. I am looking at the Logitech Extreme 3D Pro. It has the 3 axis capability.
thanks |
|
#12
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
For driving mecanum, two joysticks would work. Even one would work if the joystick has at least 3 axes (e.g. X, Y and Twist). I don't have the Logitech Extreme 3D Pro, so I can't comment on it.
|
|
#13
|
|||
|
|||
|
Re: Mechanum wheel programming in C++
Our team used the 3D Pro to drive a mecanum bot last year and it was very natural. The kids picked up how to control it very quickly.
|
|
#14
|
|||
|
|||
|
Re: Mechanum wheel programming in C++
Quote:
Did you use two joysticks? thanks John |
|
#15
|
|||
|
|||
|
Re: Mechanum wheel programming in C++
Yes, It would be extremely helpful if the sample C++ Code for Mechanum Wheels is provided with a good explaination
![]() Thanks |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|