Go to Post "This is the year that everyone on CD is going to learn to spell." "This is the year that everyone on CD will make a serious effort to write grammatically correct sentences." "This is the year that everyone on CD will think BEFORE they post." ... nah. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-09-2013, 17:07
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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   Spotlight this post!  
Unread 07-09-2013, 17:23
magnets's Avatar
magnets magnets is offline
Registered User
no team
 
Join Date: Jun 2013
Rookie Year: 2012
Location: United States
Posts: 748
magnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond repute
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.
  #3   Spotlight this post!  
Unread 07-09-2013, 18:50
cad321 cad321 is offline
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 349
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Re: Controlling the individual speed of mecanum wheels within the main programme

Quote:
Originally Posted by magnets View Post
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.

Last edited by cad321 : 07-09-2013 at 18:53.
  #4   Spotlight this post!  
Unread 07-09-2013, 19:38
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: Controlling the individual speed of mecanum wheels within the main programme

Quote:
Originally Posted by cad321 View Post
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;
...
  #5   Spotlight this post!  
Unread 08-09-2013, 01:00
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,103
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: 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   Spotlight this post!  
Unread 08-09-2013, 01:19
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: Controlling the individual speed of mecanum wheels within the main programme

Quote:
Originally Posted by Ether View Post
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!
  #7   Spotlight this post!  
Unread 08-09-2013, 16:30
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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

Last edited by ekapalka : 08-09-2013 at 16:51.
  #8   Spotlight this post!  
Unread 08-09-2013, 17:17
mschwab013's Avatar
mschwab013 mschwab013 is offline
Registered User
AKA: Matt Schwabenbauer
FRC #0291
Team Role: College Student
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Erie, PA
Posts: 88
mschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to all
Re: Controlling the individual speed of mecanum wheels within the main programme

Quote:
Originally Posted by ekapalka View Post
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
__________________


2013 Pittsburgh- Gracious Professionalism award, 7th seed, 6th alliance captian, quarter-finalist(291,3492,4601)
2013 Queen CIty- Chairman's Award, 39th seed
2012 Pittsburgh- 23rd seed
2012 Buckeye- 34th seed, 2nd alliance, quarter-finalist(291,1241,4085)
2011 Pittsburgh- 13th seed, 5th alliance, quarter-finalist(291,337,3504)
2011 Buckeye- 18th seed, 8th alliance, quarter-finalist(279,291,3496)
2010 Finger Lakes- 15th seed, 5th alliance, quarter-finalist(291,1507,1559)
2010 Buckeye- Chairman's Award, Imagery Award, Quality Award, 4th seed, 1st pick, 1st alliance, semi-finalist(291,1014,1629)
  #9   Spotlight this post!  
Unread 08-09-2013, 18:02
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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   Spotlight this post!  
Unread 08-09-2013, 18:15
mschwab013's Avatar
mschwab013 mschwab013 is offline
Registered User
AKA: Matt Schwabenbauer
FRC #0291
Team Role: College Student
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Erie, PA
Posts: 88
mschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to all
Re: Controlling the individual speed of mecanum wheels within the main programme

Quote:
Originally Posted by ekapalka View Post
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 View Post
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
__________________


2013 Pittsburgh- Gracious Professionalism award, 7th seed, 6th alliance captian, quarter-finalist(291,3492,4601)
2013 Queen CIty- Chairman's Award, 39th seed
2012 Pittsburgh- 23rd seed
2012 Buckeye- 34th seed, 2nd alliance, quarter-finalist(291,1241,4085)
2011 Pittsburgh- 13th seed, 5th alliance, quarter-finalist(291,337,3504)
2011 Buckeye- 18th seed, 8th alliance, quarter-finalist(279,291,3496)
2010 Finger Lakes- 15th seed, 5th alliance, quarter-finalist(291,1507,1559)
2010 Buckeye- Chairman's Award, Imagery Award, Quality Award, 4th seed, 1st pick, 1st alliance, semi-finalist(291,1014,1629)
  #11   Spotlight this post!  
Unread 08-09-2013, 19:12
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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   Spotlight this post!  
Unread 08-09-2013, 20:54
mschwab013's Avatar
mschwab013 mschwab013 is offline
Registered User
AKA: Matt Schwabenbauer
FRC #0291
Team Role: College Student
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Erie, PA
Posts: 88
mschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to allmschwab013 is a name known to all
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
__________________


2013 Pittsburgh- Gracious Professionalism award, 7th seed, 6th alliance captian, quarter-finalist(291,3492,4601)
2013 Queen CIty- Chairman's Award, 39th seed
2012 Pittsburgh- 23rd seed
2012 Buckeye- 34th seed, 2nd alliance, quarter-finalist(291,1241,4085)
2011 Pittsburgh- 13th seed, 5th alliance, quarter-finalist(291,337,3504)
2011 Buckeye- 18th seed, 8th alliance, quarter-finalist(279,291,3496)
2010 Finger Lakes- 15th seed, 5th alliance, quarter-finalist(291,1507,1559)
2010 Buckeye- Chairman's Award, Imagery Award, Quality Award, 4th seed, 1st pick, 1st alliance, semi-finalist(291,1014,1629)
  #13   Spotlight this post!  
Unread 08-09-2013, 21:36
daniel_dsouza daniel_dsouza is offline
does what needs to be done.
FRC #2449 (Out of Orbit Robotics)
Team Role: Alumni
 
Join Date: May 2011
Rookie Year: 2011
Location: Chandler, AZ
Posts: 231
daniel_dsouza has a spectacular aura aboutdaniel_dsouza has a spectacular aura about
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   Spotlight this post!  
Unread 09-09-2013, 09:25
Chris_Ely's Avatar
Chris_Ely Chris_Ely is offline
Registered User
AKA: luckof13
FRC #3414 (HackBots)
Team Role: College Student
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Farmington, Michigan
Posts: 366
Chris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond reputeChris_Ely has a reputation beyond repute
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.
__________________
2013: Waterford Finalist, Livonia Winner, MSC Quarterfinalist, Curie Division
2012: Waterford, Northville, Livonia
2011: Waterford Finalist, Livonia
2010: Ann Arbor Rookie Inspiration Award, Troy

Mechanical Engineering Student,
Michigan Technological University
  #15   Spotlight this post!  
Unread 09-09-2013, 18:57
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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
Closed Thread


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


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

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