Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Controlling the individual speed of mecanum wheels within the main programme (http://www.chiefdelphi.com/forums/showthread.php?t=119054)

ekapalka 07-09-2013 17:07

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!

magnets 07-09-2013 17:23

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;

Just make sure that you invert your y axis on the joystick. Also, you should have you code check to see if any of the wheels speeds are > 1, and if so, divide them all by the largest value present to make sure that you still get the right response.

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.

cad321 07-09-2013 18:50

Re: Controlling the individual speed of mecanum wheels within the main programme
 
Quote:

Originally Posted by magnets (Post 1290360)
Also, you should have you code check to see if any of the wheels speeds are > 1, and if so, divide them all by the largest value present to make sure that you still get the right response.

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.

SoftwareBug2.0 07-09-2013 19:38

Re: Controlling the individual speed of mecanum wheels within the main programme
 
Quote:

Originally Posted by cad321 (Post 1290368)
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.

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;
...


Ether 08-09-2013 01:00

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;}


SoftwareBug2.0 08-09-2013 01:19

Re: Controlling the individual speed of mecanum wheels within the main programme
 
Quote:

Originally Posted by Ether (Post 1290402)
You need to find the max absolute value, since speeds can be +/-.

Indeed - I implemented exactly what was asked for rather than what was needed.

Now you've taken all the fun out of it! :D

ekapalka 08-09-2013 16:30

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);

Thanks!

[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

mschwab013 08-09-2013 17:17

Re: Controlling the individual speed of mecanum wheels within the main programme
 
Quote:

Originally Posted by ekapalka (Post 1290480)
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.

I had a similar problem this past year while programming our mecanum drive. I fixed it by putting the axis' in this order: y axis, rotation, x axis.

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);

I was using a logitech gamepad but I believe the principles would be the same for sending commands. I hope this helps! If you have any questions you can PM me. I've been working with mecanum for several years now and may be able to help

ekapalka 08-09-2013 18:02

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...

mschwab013 08-09-2013 18:15

Re: Controlling the individual speed of mecanum wheels within the main programme
 
Quote:

Originally Posted by ekapalka (Post 1290490)
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?

You just need to know which way the wheels need to be spinning. I'll try to explain. Here goes.

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

Quote:

Originally Posted by ekapalka (Post 1290490)
Also... the twitching and creeping while no commands are being sent really weirds me out...

This can be due simply to the joysticks being old and not having a proper deadzone. One can easily be programmed in though

ekapalka 08-09-2013 19:12

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?

mschwab013 08-09-2013 20:54

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

daniel_dsouza 08-09-2013 21:36

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).

Chris_Ely 09-09-2013 09:25

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:

1. Press and hold the button labeled “CAL” with a paper clip. The
LED should begin to blink red/green.
2. Continue to keep the button pressed while moving the joystick
full forward and full reverse. You may do this as many times as
you like.
3. Center the joystick and then release the CAL button.
4. If calibration was successful, the LED will blink green several
times. If the LED blinks red several times, the calibration was
not valid. If this happens, the Talon will use the last valid
calibration values.
All calibration values are retained after power cycle or reset.

ekapalka 09-09-2013 18:57

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


All times are GMT -5. The time now is 19:51.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi