Go to Post You valuable advice has prevented me from killing myself and others numerous times =) - Stephen Kowski [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-02-2010, 04:43
mika.perlin mika.perlin is offline
Registered User
FRC #0955
 
Join Date: Jan 2010
Location: Corvallis, OR
Posts: 17
mika.perlin is an unknown quantity at this point
Mecanum Drive Not Working

So for some reason we can't get our mecanum drive working. Our code (in C++) looks like this:
Code:
[This just calculates the motor speeds which will be set later.
-myAbs(float) is just a function which finds the absolute value of a float.
-largest(float ...) is a function which finds the largest any number of inputted float values.
-these two functions have been tested and work correctly.]

   //Square Joystick inputs for better precision control
    x = mainStick.GetX(); x = x*x;
    y = mainStick.GetY(); y = y*y;
    twist = secondaryStick.GetX();
    //[0, 1] Throttle value which may be used to artificially decrease speed
    throttleFactor = -(mainStick.GetThrottle()-1)/2;
    //Set minimum threshold on Joystick inputs
    if(myAbs(x) + myAbs(y) + myAbs(twist) > JOY_THRESHOLD)
    {
    	//Calculate raw motor speeds for vector drive
        Speed[NW] = y + x + twist;    Speed[NE] = y - x - twist;
        Speed[SW] = y - x + twist;    Speed[SE] = y + x - twist;
        
        //Calculate magnitude of largest motor speed
        topSpeed = largest(myAbs(Speed[NW]), myAbs(Speed[NE]), myAbs(Speed[SW]), myAbs(Speed[SE]));
        
        //If the calculated largest speed is greater than 1, scale everything down
        if(topSpeed > 1)
        {
            Speed[NW] /= topSpeed;    Speed[NE] /= topSpeed;
            Speed[SW] /= topSpeed;    Speed[SE] /= topSpeed;
        }

        //Give option artificially slow down with throttle while holding down a button
        if (mainStick.GetRawButton(THROTTLE_BUTTON))
        {
            Speed[NW] *= throttleFactor;    Speed[NE] *= throttleFactor;
            Speed[SW] *= throttleFactor;    Speed[SE] *= throttleFactor;
        }
    }
    else  //If Joystick inputs not within threshold
    {
        Speed[NW] = 0;    Speed[NE] = 0;
        Speed[SW] = 0;    Speed[SE] = 0;
    }
We later set the motors in a separate function:
Code:
    //Invert motors in code instead of electronically
    NWMotor.Set(Speed[NW]*NW_MOTOR_INVERT);
    NEMotor.Set(Speed[NE]*NE_MOTOR_INVERT);
    SWMotor.Set(Speed[SW]*SW_MOTOR_INVERT);
    SEMotor.Set(Speed[SE]*SE_MOTOR_INVERT);
The motors do move, but in weird ways (for example if we push the main joystick full forward, I believe only two motors on opposite corners moved).
Also, if we put default code on the robot it does seem to make all of the motors move, but we don't want to use default code because we feel like it's cheating and it would just be nice to get our own code working so we can mess or with it or change it if we want.
So... anybody got any ideas?

Last edited by mika.perlin : 20-02-2010 at 04:45.
Reply With Quote
  #2   Spotlight this post!  
Unread 20-02-2010, 11:40
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Mecanum Drive Not Working

Quote:
Originally Posted by mika.perlin View Post
//Square Joystick inputs for better precision control
x = mainStick.GetX(); x = x*x;
y = mainStick.GetY(); y = y*y;
When you square x (and y) you change their range from [-1 to +1] to [0 to +1] .

Perhaps you accounted for this in your code but I didn't see it with a cursory review.

Try x*x*x instead of x*x. That preserves the sign.

See the following posts:

TUNABLE JOYSTICK SENSITIVITY
http://www.chiefdelphi.com/forums/sh...d.php?p=921992

MECANUM CODE
http://www.chiefdelphi.com/forums/sh...383#post916383




~
Reply With Quote
  #3   Spotlight this post!  
Unread 21-02-2010, 02:51
mika.perlin mika.perlin is offline
Registered User
FRC #0955
 
Join Date: Jan 2010
Location: Corvallis, OR
Posts: 17
mika.perlin is an unknown quantity at this point
Re: Mecanum Drive Not Working

Hmm... that's true. Thanks. It still does not explain, however, why drive does not work correctly even if I just move the joystick forward, making the only input a positive y value...
Reply With Quote
  #4   Spotlight this post!  
Unread 21-02-2010, 07:51
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Mecanum Drive Not Working

Quote:
Originally Posted by mika.perlin View Post
I believe only two motors on opposite corners moved
Check it again, with the bot on blocks so you can see which wheels are moving, and observe the jag LEDs.


~
Reply With Quote
  #5   Spotlight this post!  
Unread 21-02-2010, 09:50
TheDominis TheDominis is offline
Registered User
FRC #2152
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Port Orange, Florida
Posts: 88
TheDominis has a spectacular aura aboutTheDominis has a spectacular aura about
Re: Mecanum Drive Not Working

You can use the absolute value function to square inputs.

Code:
#include <cmath>

x *= fabs(x);
y *= fabs(y);
Reply With Quote
  #6   Spotlight this post!  
Unread 21-02-2010, 12:27
AlftanSr AlftanSr is offline
Registered User
FRC #1013
 
Join Date: Feb 2010
Location: Arizona
Posts: 12
AlftanSr is an unknown quantity at this point
Re: Mecanum Drive Not Working

Quote:
Originally Posted by Ether View Post
When you square x (and y) you change their range from [-1 to +1] to [0 to +1] .

Perhaps you accounted for this in your code but I didn't see it with a cursory review.

Try x*x*x instead of x*x. That preserves the sign.

See the following posts:

TUNABLE JOYSTICK SENSITIVITY
http://www.chiefdelphi.com/forums/sh...d.php?p=921992

MECANUM CODE
http://www.chiefdelphi.com/forums/sh...383#post916383




~
or you could have an if statement, so there's less multiplying...

if (x<0.0) x = -(x*x); else x = x*x;
Reply With Quote
  #7   Spotlight this post!  
Unread 21-02-2010, 12:39
AlftanSr AlftanSr is offline
Registered User
FRC #1013
 
Join Date: Feb 2010
Location: Arizona
Posts: 12
AlftanSr is an unknown quantity at this point
Re: Mecanum Drive Not Working

Squaring is a funny thing. All of your inputs are between -1 and 1.

If: -1 < x < 1
then: x > x^2

If you do away with squaring, the following calculations will be easier to debug:

Speed[NW] = y + x + twist;
Speed[NE] = y - x - twist;
Speed[SW] = y - x + twist;
Speed[SE] = y + x - twist;

Last edited by AlftanSr : 21-02-2010 at 12:43.
Reply With Quote
  #8   Spotlight this post!  
Unread 21-02-2010, 17:02
mika.perlin mika.perlin is offline
Registered User
FRC #0955
 
Join Date: Jan 2010
Location: Corvallis, OR
Posts: 17
mika.perlin is an unknown quantity at this point
Re: Mecanum Drive Not Working

Well I guess we'll just cube inputs later instead of squaring to take care of the sign change problem; the point of doing that is to have better precision control (it's easier to make small movements). For testing we can just take that out; this has no impact, however, on how the motors are moving right now (i.e. in weird directions), which means something else is wrong...
Reply With Quote
  #9   Spotlight this post!  
Unread 21-02-2010, 17:13
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Mecanum Drive Not Working

Quote:
Originally Posted by mika.perlin View Post
the motors are moving right now (i.e. in weird directions), which means something else is wrong...
If you are seeking help, it would help if you would put the bot up on blocks and carefully note which way each wheel spins (forward or backward) for each joystick input (forward, backward, right, left, twist CW, twist CCW)*. Also note what the LED on each jag is doing for each of these cases.

Post your results here and I am quite sure you will get the help you need.


*remove the squaring of the inputs first

~
Reply With Quote
  #10   Spotlight this post!  
Unread 21-02-2010, 17:36
AlftanSr AlftanSr is offline
Registered User
FRC #1013
 
Join Date: Feb 2010
Location: Arizona
Posts: 12
AlftanSr is an unknown quantity at this point
Re: Mecanum Drive Not Working

Aside from 'if we push the main joystick full forward, I believe only two motors on opposite corners moved', what are some of the other symptoms? I'm assuming the others motors move in other joystick positions? Is it the other two motors when full right?
Reply With Quote
  #11   Spotlight this post!  
Unread 04-03-2010, 04:05
mika.perlin mika.perlin is offline
Registered User
FRC #0955
 
Join Date: Jan 2010
Location: Corvallis, OR
Posts: 17
mika.perlin is an unknown quantity at this point
Re: Mecanum Drive Not Working

Okay so we figured out why it wasn't working. A silly problem. Basically we just didn't include the header file for the cpp which included our custom functions [namely float largest() in this case]. Thanks though everyone
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tank Drive Not Working!!! live4u2 NI LabVIEW 2 05-02-2010 20:40
crab drive vs. mecanum drive system superbotman Technical Discussion 33 06-01-2010 03:09
Drive code not working; any suggestions? BrandonD-1528 Programming 9 30-01-2009 21:06
pic: Jester Drive:Mecanum Wheel Drive Train Ken Delaney 357 Technical Discussion 64 29-03-2006 22:16


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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