|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Controlling the individual speed of mecanum wheels within the main programme
Hello! We're on our third day of of four day "build season", and are almost ready to test drive. I've been reading about mecanum wheels here for a while, and am starting to worry that our motors may not be capable of spinning synchronously (well, we haven't tested yet, but it seems to happen to a lot of other people). We're using C++, and I don't currently have one of the developer laptops with the programming environment and WPI source to use as a reference. What I was hoping we could do was to drag the entire Mecanum_Cartesian method out of WPI and insert it into a method below the periodic portion of our code so we could easily manipulate the individual motor values to get the correct speeds (and so that we can see the math involved instead of putting all our faith in the library). Could someone give me some direction? Thanks!
|
|
#2
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
The source for wpilib is included as a project in Java, but I don't know if it's included in the C++ release.
If you want to right your own mecanum code, it's pretty easy. Here's the important part from the Java library. Code:
frontLeft = xIn + yIn + rotation;
frontRight = -xIn + yIn - rotation;
rearLeft = -xIn + yIn + rotation;
rearRight = xIn + yIn - rotation;
As for the wheel speed issue, it can definitely help to use closed loop control for the velocity of the wheels, but it can be fairly difficult to implement well, and it will take a long time to tune it well. I would recommend just sticking with the simpler method unless your robot really isn't controllable. If it is, make sure there's no excess friction in any gearboxes/drive components/rollers on the wheels. |
|
#3
|
|||
|
|||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
How might one go about doing this? Unfortunately my programming skills are lacking at best but I get the feeling it is fairly simple to do.
Last edited by cad321 : 07-09-2013 at 18:53. |
|
#4
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Quote:
Code:
double max2(double a,b){ return (a>b)?a:b; }
double max5(double a,double b,double c,double d,double e){
return max2(max2(max2(a,b),max2(c,d)),e);
}
...
divisor=max5(leftFront,rightFront,leftRear,rightRear,1);
leftFront/=divisor;
rightFront/=divisor;
...
|
|
#5
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
You need to find the max absolute value, since speeds can be +/-. Let fr, fl, rl, and rr be the 4 wheel speed commands in the range +/- 1. Then here's the pseudo-code: Code:
max=fabs(fr);
if (max<fabs(fl)) max=fabs(fl);
if (max<fabs(rl)) max=fabs(rl);
if (max<fabs(rr)) max=fabs(rr);
if (max>1){fr/=max; fl/=max; rl/=max; rr/=max;}
|
|
#6
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Indeed - I implemented exactly what was asked for rather than what was needed.
Now you've taken all the fun out of it! ![]() |
|
#7
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Thank you!! Since we just finished the chassis, we're trying to get it working using the library code... and there have been some complications. We can rotate flawlessly, and we can drive in a more-or-less straight line (probably due to our ancient 2 axis joystick with no deadzone). The problem we're having is that we can't strafe (and the x axis, y axis, and rotation are all mixed up). When we try to strafe, the robot simply spins the wheels towards or away from the central point of the robot (i.e the front two wheels spin inwards and the back two wheels spin inwards xor vice versa) and it stays in place or runs in circles. The rollers are arranged in an "X" pattern when viewed from the top. Here's the code we're using, in case it's related to that...
Code:
#include <WPILib.h>
class DefaultRobot : public SimpleRobot
{
Joystick *Saitek;
Talon *frontLeft;
Talon *frontRight;
Talon *backLeft;
Talon *backRight;
RobotDrive *myRobot;
public:
DefaultRobot(void)
{ //these must be called in the same order as initialized
Saitek = new Joystick(1);
frontLeft = new Talon(2,1);
backLeft = new Talon(2,2);
frontRight = new Talon(2,3);
backRight = new Talon(2,4);
myRobot = new RobotDrive(frontLeft, backLeft,
frontRight, backRight);
}
void Autonomous(void)
{
while(IsAutonomous())
{
}
}
void OperatorControl(void)
{
float tval, sval;
while (IsOperatorControl())
{
float xVal = Saitek->GetRawAxis(1);
float yVal = Saitek->GetRawAxis(2);
bool trigButton = Saitek->GetRawButton(1);
bool leftButton = Saitek->GetRawButton(2);
bool midlButton = Saitek->GetRawButton(3);
bool rightButton = Saitek->GetRawButton(4);
myRobot->MecanumDrive_Cartesian(sval*0.5, tval*0.25, -yVal*0.25, 0.0);
if (leftButton && !rightButton){ tval = -1; }
else if (rightButton && !leftButton) { tval = 1; }
else if (leftButton && rightButton) { tval = 0; }
else tval = 0;
if (midlButton && !trigButton) { sval = -1; }
else if (trigButton && !midlButton) { sval = 1; }
else if (trigButton && midlButton) { sval = 0; }
else sval = 0;
//backRight->Set(0.25);
//backLeft->Set(0.25);
//frontRight->Set(0.25);
//frontLeft->Set(0.25);
}
}
};
START_ROBOT_CLASS(DefaultRobot);
[edit] Also, if we tell an individual motor to do something (i.e just sending a value to a single motor controller), the other motors move and twitch... I have no idea how to fix this Last edited by ekapalka : 08-09-2013 at 16:51. |
|
#8
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Quote:
The code looks like this: Code:
stick_LeftY = stick->GetLeftY(); stick_LeftX = stick->GetLeftX(); stick_RightX = stick->GetRightX(); myRobot->MecanumDrive_Cartesian(stick_LeftY, stick_RightX, stick_LeftX); |
|
#9
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Thanks
How on earth are we supposed to get which motor goes where and which need to be inverted and which need to be switched and...? Is there some standard way of doing this? Also... the twitching and creeping while no commands are being sent really weirds me out... |
|
#10
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Quote:
Forward- all wheels forward Backward- all wheels backward Rotate right- 2 left wheels forward, 2 right wheels backward Rotate left- 2 left wheels backward, 2 right wheels forward Strafe right- front left and back right wheels forward, front right and back left wheels backward Strafe left - front left and back right wheels backward, front right and back left wheels forward This can be due simply to the joysticks being old and not having a proper deadzone. One can easily be programmed in though |
|
#11
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Thanks! We ended up telling identifying each motor as "frontleft" etc, and then calling them one by one and replacing the PWM cables to get the right wheel to correspond with the right motor controller name (regardless of the direction). Then we put the motor values into MacanumDrive_Cartesian and set it to drive in a straight line (while on blocks) and reversed all the motors that needed to be reversed. We don't know how to use "SetInvertedMotor()".... Now we only have one problem... Talon SRs spin signifigantly (and consistently) faster in reverse than while going forwards (so we can't simply multiply individual motor values to regulate them). Thanks, by the way! We printed out your response and cable-tied it to the robot (just the directional stuff). *edit* also, it creeps without the joysticks plugged in. It only creeps and jitters when on blocks or low friction surfaces (although the motor controller lights do change colours while on high-friction surfaces, but don't give the motors enough power to move). *edit2* I just realized that the speed controllers are not initialized in the right order. Fixing that shouldn't mess anything up, right?
Last edited by ekapalka : 08-09-2013 at 20:17. |
|
#12
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Glad I could help! The fact that the wheels twitch when there's no joysticks plugged in is rather bizarre. Unfortunately I'm not really sure what to tell you about that.
If you change the order that the motors are initialized this would change the order they would need to be put into the Mecanum_Cartesian function. This would change things but can be easily fixed on the robot by moving the PWM cables around |
|
#13
|
|||
|
|||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Creeping and twitching. Sounds like me after too much sugar.
Have you changed the calibration on your talons at all? I have no experience with talons at all, but i have plenty with victors. Someone was calibrating a drivetrain to stop creeping, but did it wrong. The victor now only knew full front and full reverse. But your problem is not that extreme. Also, make sure your joysticks are centered when they are first plugged in, and the driver station loads. Otherwise whatever position they were in when they were plugged in will be the new origin. You could also program in a deadzone function to set values between -.01 and .01 to = 0. for both axes, and a function to set a new origin (rezero). Last edited by daniel_dsouza : 08-09-2013 at 21:37. Reason: grammer |
|
#14
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
The twitching is most likely that the Talons are not calibrated. Calibration basically tells the Talons what input values correspond to full forward, full reverse, and neutral.
To calibrate the Talons (from the Talon user manual): Quote:
|
|
#15
|
||||
|
||||
|
Re: Controlling the individual speed of mecanum wheels within the main programme
We just tried calibrating the motor controllers. It fixed the twitching issue, but the motors still spin too fast in reverse. The input voltage for all three motor controllers is the same, but the output for the forwards ones is consistently more than the reversed ones (by around 50%). Would fixing the arrangement of the declarations in the code possibly fix this? Probably not... I'm running out of ideas
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|