Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Swerve vs. Mecanum Programming (http://www.chiefdelphi.com/forums/showthread.php?t=85313)

kgzak 17-04-2010 13:29

Swerve vs. Mecanum Programming
 
I have seen many people talk about the advantages and disadvantages of Swerve vs. Mecanum. I have seen one argument that a swerve is harder to program than a mecanum but I think it is the other way around. I have built at least 2 VIs (I use LabView) for a swerve drive and my dad has built at least 5. I still have yet to figure out how to program a mecanum drive.

So my two questions
1. What is you opinion on Swerve vs. Mecanum Programing difficulty.
2 Am I missing an equation or formula that can be used in programing a mecanum drive that makes it easier?

Ether 17-04-2010 14:16

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by kgzak (Post 954457)

I have seen one argument that a swerve is harder to program than a mecanum but I think it is the other way around.

I still have yet to figure out how to program a mecanum drive.

Am I missing an equation or formula that can be used in programing a mecanum drive that makes it easier?

Here are two simple algorithms:

2 JOYSTICK TANK DRIVE MECANUM SEPARATION OF VARIABLES
http://www.chiefdelphi.com/forums/sh...94&postcount=1

3-AXIS JOYSTICK MECANUM ALGORITHM
http://www.chiefdelphi.com/forums/sh...383#post916383

The above algorithms are not optimum, but they work.

~

buchanan 17-04-2010 14:42

Re: Swerve vs. Mecanum Programming
 
Without getting into detailed equations, the mathematical principles of fully holonomic omni/mecanum drives are relatively simple and can be approached this way:

Each wheel has a direction vector along which it can transmit force in either direction. For a mecanum this is at 45 degrees to the plane of the wheel, parallel to the axle of the roller contacting the ground. For an omni it's along the flat plane of the wheel. No force is or can be transmitted except along this vector.

To get the wheel speeds necessary for any desired motion, you need to compute the projection of the motion vector onto each wheel's direction vector. For mecanums there's an additional constant to correct for the 45 degree angle. This can be done with dot products and no trigonometry.

For simple directional motion, regardless of direction, that's all there is to it. To handle rotation, the motion vectors are tangent to a circle about the center of rotation, projected on the same wheel vectors, and scaled by relative radius. For rotation about the center of a normally configured robot, these end up the same for each wheel. Rotation about other points or for odd wheel configurations is a bit more complex but conceptually the same. You can rotate and move simultaneously by solving the wheel speeds for each separately, then adding the motion and rotation components for each wheel to get its final drive speed.

This approach lends itself well to a two stick motion/rotation or single stick/twist control setup, and the vector math shouldn't take more than a couple of dozen lines of Java or C. It handles any motion physically possible with the robot. The motor drive functions needed for swerve drives, especially for complex motions, are considerably more complicated.

It should be noted that there are simpler but still useful ways to employ mecanum/omni wheels short of full holonomic, and other ways to program swerves short of the "almost holonomic" of which they're capable.

kgzak 17-04-2010 15:27

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by Ether (Post 954463)
Here are two simple algorithms:

2 JOYSTICK TANK DRIVE MECANUM SEPARATION OF VARIABLES
http://www.chiefdelphi.com/forums/sh...94&postcount=1

3-AXIS JOYSTICK MECANUM ALGORITHM
http://www.chiefdelphi.com/forums/sh...383#post916383

The above algorithms are not optimum, but they work.

~

I want to be able to go any direction with mecanum wheels not just forward backward and strafe. I have seen it done before and want to use that to create a field oriented drive so I press the joystick in any direction and it moves in that direction.

kgzak 17-04-2010 15:42

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by buchanan (Post 954468)
Without getting into detailed equations, the mathematical principles of fully holonomic omni/mecanum drives are relatively simple and can be approached this way:

Each wheel has a direction vector along which it can transmit force in either direction. For a mecanum this is at 45 degrees to the plane of the wheel, parallel to the axle of the roller contacting the ground. For an omni it's along the flat plane of the wheel. No force is or can be transmitted except along this vector.

To get the wheel speeds necessary for any desired motion, you need to compute the projection of the motion vector onto each wheel's direction vector. For mecanums there's an additional constant to correct for the 45 degree angle. This can be done with dot products and no trigonometry.

For simple directional motion, regardless of direction, that's all there is to it. To handle rotation, the motion vectors are tangent to a circle about the center of rotation, projected on the same wheel vectors, and scaled by relative radius. For rotation about the center of a normally configured robot, these end up the same for each wheel. Rotation about other points or for odd wheel configurations is a bit more complex but conceptually the same. You can rotate and move simultaneously by solving the wheel speeds for each separately, then adding the motion and rotation components for each wheel to get its final drive speed.

This approach lends itself well to a two stick motion/rotation or single stick/twist control setup, and the vector math shouldn't take more than a couple of dozen lines of Java or C. It handles any motion physically possible with the robot. The motor drive functions needed for swerve drives, especially for complex motions, are considerably more complicated.

It should be noted that there are simpler but still useful ways to employ mecanum/omni wheels short of full holonomic, and other ways to program swerves short of the "almost holonomic" of which they're capable.

Thanks, that helped. Between you and Ether I figured it out. I thank both of you.

Ether 17-04-2010 15:43

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by kgzak (Post 954486)
I want to be able to go any direction with mecanum wheels not just forward backward and strafe.

The algorithms in both links allow all 3 degrees of freedom: forward/reverse, stafe left/right, and rotate clockwise/counterclockwise.

Quote:

Originally Posted by kgzak (Post 954486)
I want to use that to create a field oriented drive so I press the joystick in any direction and it moves in that direction.

The 3-axis joystick algorithm can be made field-oriented simply by doing a coordinate axis rotation of the X,Y joystick values before feeding them to the algorithm.

x' = xcos(theta) - ysin(theta)

y' = xsin(theta) + ycos(theta)

... but Buchanan's approach is technically more correct and will yield more optimal control (more accurate directional control, smoother operation, and less scrubbing of the wheels)


~

kgzak 17-04-2010 15:59

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by Ether (Post 954493)
The algorithms in both links allow all 3 degrees of freedom: forward/reverse, stafe left/right, and rotate clockwise/counterclockwise.



The 3-axis joystick algorithm can be made field-oriented simply by doing a coordinate axis rotation of the X,Y joystick values before feeding them to the algorithm.

x' = xcos(theta) - ysin(theta)

y' = xsin(theta) + ycos(theta)

... but Buchanan's approach is technically more correct and will yield more optimal control (more accurate directional control, smoother operation, and less scrubbing of the wheels)


~

Thanks. That'll help. I think I have it figured out. Now if only our coach will do off season stuff :(

buildmaster5000 17-04-2010 19:00

Re: Swerve vs. Mecanum Programming
 
AM has a great powerpoint about omnidirectional drive, which has several diagrams that may make seeing the vectors talked about above easier to see.

http://www.andymark.biz/presentations.html

Also, if you use a gamepad or similar control device, using the left joystick to control the movement of the actual robot and using the right joystick x axis to rotate the robot, it makes it very easy for someone who has played Halo to figure out how to drive your robot.

kgzak 17-04-2010 19:03

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by buildmaster5000 (Post 954596)
Also, if you use a gamepad or similar control device, using the left joystick to control the movement of the actual robot and using the right joystick x axis to rotate the robot, it makes it very easy for someone who has played Halo to figure out how to drive your robot.

I was thinking that and since I am not only the programer, I am the driver I can basically make any driver station I want. :D

buildmaster5000 17-04-2010 19:21

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by kgzak (Post 954601)
I was thinking that and since I am not only the programer, I am the driver I can basically make any driver station I want. :D

Then use whatever works for you. We need to get a gamepad to work with Java before we start to tackle programming a swerve...

tanguma26 21-05-2010 21:15

Re: Swerve vs. Mecanum Programming
 
Hey we are team 647 and we are trying to develop our own swerve drive and I was wondering if you can post some examples of your program we are having some troble with our program and we are using Lab View.

Thank You :D

kgzak 22-05-2010 12:49

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by tanguma26 (Post 963332)
Hey we are team 647 and we are trying to develop our own swerve drive and I was wondering if you can post some examples of your program we are having some troble with our program and we are using Lab View.

Thank You :D

I can post some examples. I will post them later right now I am at my friends house and don't have the ability to do so.

Baisically what my code does is it compares two numbers and if the pos_in(position the feedback tells you you are in) is greater than pos_to(Position to go to) then it sets the speed to -1 and 1 if it is the other way around. I also have a lot of safeties built in such as: If the feedback isn't counting, if it is turning the wrong way, etc. You may have a few questions because I really haven't commented any of it and it even confused my dad at first, so I will be willing to answer any other questions you have.

apalrd 23-05-2010 00:03

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by kgzak (Post 963402)
I can post some examples. I will post them later right now I am at my friends house and don't have the ability to do so.

Baisically what my code does is it compares two numbers and if the pos_in(position the feedback tells you you are in) is greater than pos_to(Position to go to) then it sets the speed to -1 and 1 if it is the other way around. I also have a lot of safeties built in such as: If the feedback isn't counting, if it is turning the wrong way, etc. You may have a few questions because I really haven't commented any of it and it even confused my dad at first, so I will be willing to answer any other questions you have.

a simpler way to do this exists.
it's called proportional control. p from pid.

Basically, you say;
Code:

error = setpoint - process_variable
output = error * Kp

And Kp (gain) is constant. Nice and easy. You should only need a safety at the left/right boundaries to cut off the output when it gets out of range, and possibly some functions to invert motor and rotate inverse. You tune the gain so that it goes as fast as it can without oscillating.

Edit: Forgot to talk about I and D:
Integral (I):
Basically you integrate the error and add it to the output:
Code:

integral += error
output += integral * kI

Ki is Integral Gain. You also need to reset integral to prevent integral windup. Generally you do not need to implement I unless you cannot get enough accuracy with P alone.

Derivative (D):
You calculate the derivative of the previous action to determine how momentum will affect the stopping ability. Basically, it works against P and I to slow it down when it nears the end, allowing a higher P gain. You will almost certainly not need this with crab steering, as the friction of turning the pods will probably slow their rotation very quickly (D would be useful for, say, a 6' arm that has a lot of mass at the end).

kgzak 23-05-2010 20:00

Re: Swerve vs. Mecanum Programming
 
Quote:

Originally Posted by apalrd (Post 963461)
a simpler way to do this exists.
it's called proportional control. p from pid.

Basically, you say;
Code:

error = setpoint - process_variable
output = error * Kp

And Kp (gain) is constant. Nice and easy. You should only need a safety at the left/right boundaries to cut off the output when it gets out of range, and possibly some functions to invert motor and rotate inverse. You tune the gain so that it goes as fast as it can without oscillating.

Edit: Forgot to talk about I and D:
Integral (I):
Basically you integrate the error and add it to the output:
Code:

integral += error
output += integral * kI

Ki is Integral Gain. You also need to reset integral to prevent integral windup. Generally you do not need to implement I unless you cannot get enough accuracy with P alone.

Derivative (D):
You calculate the derivative of the previous action to determine how momentum will affect the stopping ability. Basically, it works against P and I to slow it down when it nears the end, allowing a higher P gain. You will almost certainly not need this with crab steering, as the friction of turning the pods will probably slow their rotation very quickly (D would be useful for, say, a 6' arm that has a lot of mass at the end).

I do know there are other ways of doing this but I like the challenge of completely writing code from scratch. The safeties are in there because one of our mentors was afraid we were going to break his swerve drive. He was afraid that the encoder/pot was going to fall off and since our drive could not continually rotate without breaking the frame, he was always afraid when we made changes to the code. My code is actually based off the code my dad uses for his drives at his work, minus he torque controllers. I have speed and position/distance controllers.

kgzak 23-05-2010 20:22

Re: Swerve vs. Mecanum Programming
 
1 Attachment(s)
Ok I have attached my code for the swerve drive. I will answer any questions.


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

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