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)

nuttle 09-09-2013 21:51

Re: Controlling the individual speed of mecanum wheels within the main programme
 
If your robot drives OK, you may not have to do anything. You'll need to check with something close to the expected weight and weight distribution. You probably want to hook things up so that going forward has all four motors running faster than going in reverse -- this may mean you need to reverse the two motor wires that attach to the output of two of the speed controllers. This way, forward and reverse should work well. If rotation and going to one side or the other don't work as you like, you can reduce the power in the forward direction so that it matches that in reverse, via software. Of course, you'll only want to do this when you need to, not for forward and reverse. Hopefully, this makes sense...

ekapalka 09-09-2013 23:15

Re: Controlling the individual speed of mecanum wheels within the main programme
 
I'm going to guess that you meant to do all the other things recommended here in this thread (i.e. write my own Mecanum code and place it into it's own method below the main method) and then modify the motor controller speeds as needed. I'm not on our development laptop right now, so I threw together the following code:
Code:

#include <WPILib.h>
class DefaultRobot : public SimpleRobot
{       
        Joystick *xBox;
        Talon *frontLeft;
        Talon *frontRight;
        Talon *backLeft;
        Talon *backRight;
public:
        DefaultRobot(void)
        {        //these must be called in the same order as initialized
                xBox      = new Joystick(1);
                frontLeft  = new Talon(2,2);
                backLeft  = new Talon(2,1);
                frontRight = new Talon(2,3);               
                backRight  = new Talon(2,4);
        }
        void Autonomous(void)
        {
                while(IsAutonomous())
                {
                }                               
        }
        void OperatorControl(void)
        {
                float lXaxis, lYaxis, triggers, rXaxis, rYaxis;
                while (IsOperatorControl())
                {       
                        //initialize buttons and joystick axes
                        float lXaxis  = xBox -> GetRawAxis(1);
                        float lYaxis  = xBox -> GetRawAxis(2);
                        float triggers = xBox -> GetRawAxis(3);
                        float rXaxis  = xBox -> GetRawAxis(4);
                        float rYaxis  = xBox -> GetRawAxis(5);
                       
                        //call MecanumDrive method
                        MecanumDrive(deadZ(lXaxis), deadZ(lYaxis), deadZ(rXaxis));
                        //order: strafe, forward, rotate
                }
        }
        void MecanumDrive (float xVal, float yVal, float tVal){
                float fL, bL, fR, bR, max;
               
                //step 1: generate speeds for each motor
                fL =  xVal + yVal + tVal;
                fR = -xVal + yVal - tVal;
                bL = -xVal + yVal + tVal;
                bR =  xVal + yVal - tVal;
               
                //step 2: divide by greatest value if greater than 1
                max=fabs(fr);
                if (max < fabs(fL)) max = fabs(fL);
                if (max < fabs(bL)) max = fabs(bL);
                if (max < fabs(bR)) max = fabs(bR);
                if (max > 1){ fR/=max; fL/=max; bL/=max; bR/=max; }
               
                //final step
                frontLeft -> Set(fL * fix(fL));
                backLeft  -> Set(bL * fix(bL));
                frontRight-> Set(fR * fix(fR));
                backRight -> Set(bR * fix(bR));
        }
       
        //deadzone method
        float deadZ (float val) {
                return val > 0.06 || val < -0.6? val: 0;
        }
       
        //method to modify motor values based on direction
        float fix (float fixme) {
                return fixme > 0? 1 : fixme < 0? 0.95 : 0;
                //change '0.95' to the best possible alternative
        }
};

I apparently have a few more days before the big event at which I intend to show off the new robot (new member meeting this Wednesday), so I'll have a little extra time for trial and error :) I'm a decent programmer, but I haven't done much over the summer and don't currently have access to an environment that can do debugging (just good old Notepad++ running off of my flashdrive :P ), so I expect some trivial mistakes. As soon as I can get this to work, I'll go back to using IterativeRobot instead of SimpleRobot (SimpleRobot is the only one I could remember the structure of without looking at already-made code). Logically, does this make sense? I'm thinking about changing 'float fix(float fixme){}' to something like 'float fix(String motor, float fixme){}' so that I can modify each and every motor value more personally ('String motor' would be an identifying string associated with a particular motor).

Ether 09-09-2013 23:34

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

max=fabs(fr); max=fabs(fR);

return fixme > 0? 1 : fixme < 0? 0.95 : 0; return fixme>0? 1:0.95



nuttle 10-09-2013 10:03

Re: Controlling the individual speed of mecanum wheels within the main programme
 
You have the right idea. I imagine a little trial and error will get you there!

It might be good to only apply the 'fix' logic if not all wheels are going in the same direction -- this way, you only cut the power if it is needed.

Good luck, and if you have further trouble, just post...

ekapalka 12-09-2013 19:45

Re: Controlling the individual speed of mecanum wheels within the main programme
 
Hey! I just wanted to let you all know that the robot worked flawlessly :D I'll put up some pictures of the robot we built in four days when we can get a hold of a decent resolution camera. Thank you all so much! This is hands down the most helpful and informative thread I've ever seen. Much appreciated, CD.

nuttle 13-09-2013 08:42

Re: Controlling the individual speed of mecanum wheels within the main programme
 
Thanks for the update!


A further refinement would be to move the normalization to last -- in other words, add the 'fix' logic before the normalization is done.


In case others come across this thread, you can compensate for a lot of things in software but, in general, when you have different wheels behaving differently, you should first look for other possible causes:

- check for mechanical issues, make sure they all have the same feel, etc.;
- check for electrical issues, lose connections, very uneven length wire runs with too-small gage wire, etc.;
- consider swapping various components to see if you can isolate the source of the difference as this will provide insight into what is going on;
- realize that some motors do have some bias for running faster in one direction than the other, this usually is going to be lost in the noise but it could be a factor;
- be on the lookout for non-repeatable results, such as when things shift around without explanation from test-to-test (if you find yourself chasing a moving target, take a break and then think things through again).


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

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