View Full Version : How to code Macanum ddrive
whcirobotics
24-10-2010, 15:44
In the past we have went with regular wheels and Arcade drive. But just last week (or 2 weeks ago) we got ourselves a set of macanum wheels.
I was wondering if someone can explain the logic behind these wheels and Where to start to actually programming this so we can use 1 joystick and go in all directions using the wheels.
1514
Whcirobotics
(Accidentally named the thread "ddrive" sorry for that its just "drive"
Mark McLeod
24-10-2010, 16:00
There are several whitepapers (http://www.chiefdelphi.com/media/papers/tags/mecanum) you can look at.
Getting the wheels on in the correct orientation is where people seem to have the most trouble.
The code is pretty simple, just be sure you connect the correct PWM to the corresponding wheel.
This code also assumes you've purchased a joystick that twists.
whcirobotics
24-10-2010, 16:09
The code that you have attached in the thumbnails > why does it only have 3 axis? I was told macanum drive or Holononic Drive has 4 axis? And that code is enough? I thought it was more complicated..
But more important than the code provided.. can you explain me how they function. The logic behind it. I want to program it from my understanding and see if it works. If you could explain me the logic please. :)
1514
whcirobotics
whcirobotics
24-10-2010, 16:21
How do we get the macanum - cartesian under the holonmic Drive?
The code that you have attached in the thumbnails > why does it only have 3 axis? I was told macanum drive or Holononic Drive has 4 axis?
A 4-mecanum-wheel robot has 3 degrees of freedom: fwd/rev, strafe, and rotate. To obtain these 3 degrees of freedom, you have to issue coordinated commands to each of the 4 wheels
And that code is enough? I thought it was more complicated...
That code is enough. It is not complicated.
But more important than the code provided.. can you explain me how they function. The logic behind it. I want to program it from my understanding and see if it works. If you could explain me the logic please. :)
This (http://www.chiefdelphi.com/media/papers/download/2722) explains the kinematics (the "logic"). It shows a mathematical derivation of why you must drive each of the 4 wheels at a certain speed in order to obtain a desired vehicle motion.
This (http://www.chiefdelphi.com/media/papers/download/2783) tells how to write your own mecanum code for 3-axis joystick or for two 2-axis joysticks. It includes constants for adjusting the sensitivity of each of the three degrees of freedom.
whcirobotics
24-10-2010, 16:32
O wow .. i thought it would be more complicated. I will try this code with mac wheels and see if it works.
Thanks for clearing up that it only needs 3 axis. I had looked at someones code and seen that they had 4 axis.. there code wasnt working. now i know why..
I will try this and get back with the results :)
You guys may think why i am starting many new threads everyday with different questions, the reason is because last year our robot did not have a functioning kicker code and in the competetion out of the 8 or so games, we only played in 3... because it wasnt communicating wirelessly.
I have been able to fix these problems in the past few days and i am thankful for chiefdelphi :) helped me greatly.
1514
Whcirobotics
RoboMaster
24-10-2010, 17:04
Note that Mark's code is really used for a joystick that twists (the kit joysticks don't).
If you have a joystick that doesn't twist, you usually program 2 buttons to rotate the robot in different directions (you may have experienced this concept in video games, where the rear controller buttons rotate the vehicle/whatever you're in).
If you want to do this, you basically test both buttons and send different values to that Rotation terminal based on which button is pressed, if any. Doing that might get complicated, so if you can't figure it out, feel free to post back or check out this recent thread that is very similar (http://www.chiefdelphi.com/forums/showthread.php?t=87124). They talk about controlling a motor with two buttons.
buildmaster5000
24-10-2010, 17:24
Note that Mark's code is really used for a joystick that twists (the kit joysticks don't).
You can also use a second joystick. The first joystick will control what I call "move" (forward/ backward relative to the robot's center) and "translate" (left/right relative to the robot's center). Assign the Y axis to move and the X axis to rotate the robot. The second joystick can have its X axis assigned to rotate the robot about its center.
Hope this helps!
You can also use a second joystick. The first joystick will control what I call "move" (forward/ backward relative to the robot's center) and "translate" (left/right relative to the robot's center). Assign the Y axis to move and the X axis to rotate the robot. The second joystick can have its X axis assigned to rotate the robot about its center.
I think there's a typo. You have "rotate" assigned twice. One of them should be strafe, right ?
If you have drivers who are already proficient with a tank drive interface, and you want to take advantage of that, you can use two 2-axis joysticks in standard "tank drive" mode to control the mecanum vehicle.
The left and right joystick Y-axes act just like tank drive to control fwd/rev and turning.
The X-axis on one of the joysticks controls strafing. To avoid inadvertent strafing, you can activate the X-axis command only when a trigger held down.
whcirobotics
24-10-2010, 19:09
@ Buildmaster5000 and @ Ether
I have attached a picture of what you guys suggested. Is it correct?
And plus, how do i get "Macanum - Cartesian" under the Holonmic Drive. Like what Mark has in his picture.
@ RoboMaster
so the Joystick, Attack 3 we got in the kit is not sufficient? What joystick is to be used then? And if any what extra bit coding is involved?
1514
Whcirobotics
Joe Ross
24-10-2010, 19:20
And plus, how do i get "Macanum - Cartesian" under the Holonmic Drive. Like what Mark has in his picture.
Have you installed the LabVIEW update released 2/15/2010?
whcirobotics
24-10-2010, 19:22
Have you installed the LabVIEW update released 2/15/2010?
O there is an update :S i will do that right away
Is it correct?
That depends on what driver interface you are trying to implement. Can you explain what you think this will do, from the driver's point of view?
RoboMaster
24-10-2010, 20:25
The Attack 3 joystick is not sufficient for extremely simple, basic wire-up programming and control of holonomic drive. If you want to use it, you'll have to do a little more programming to work with what you've got. But that's where you have options based on how advanced you want to be or what you think is easiest to drive or program.
I think Ether and buildmaster5000 were actually talking about two different drive techniques. But they're both good basic ideas. Let's see if I can describe them:
"Strafing-based holo drive" (what I was describing with buttons and buildmaster5000 with a joystick): one joystick controls strafing (wire up X and Y from joystick to X and Y on holo drive VI), while buttons or another joystick axis control direction/rotation (wire something else up to the Rotation terminal). This means that to turn around a corner you drive straight with the first joystick, but at the same time you need to rotate with your buttons/other joystick so that your direction changes too.
"Tank-based holo drive" (what Ether was describing): robot is driven normally like a tank: two joysticks control the left and right wheels of the robot. But, when the driver presses a button, the robot switches to strafing only, where one joystick controls strafing. This might be a little trickier and would require a combination of the holo drive VI and the tank drive VI (switching between the two based on if the button was pressed). However, this is nice and easy to drive because you normally just drive with the tank drive technique, which is intuitive. The strafing is like an added bonus.
(Note: you could use arcade drive instead of tank drive, which would require only one joystick. The point is that you're switching between that and holo drive to enable strafing).
Sorry if that was super abstract and hard to describe. But there are many ways to actually drive and control the robot with holonomic drive, just like how you can control a basic drive with arcade or tank drive, take your pick. So yes, the holo drive programming itself is easy since we have a nice holo drive VI, but there's still a bit more you have to do to apply it.
I might post visuals of the programming I described if you want. Right now I have to do something else, though. Hope that helps!
whcirobotics
24-10-2010, 20:29
I think the code will enable the Joystick 1 ( also called move joystick) to control the Up and down and Strafing part of the driving. And the Joystick 2 ( also called the Translate Joystick) to control the left to right part of driving.
Mark McLeod
24-10-2010, 21:09
For a first test to make sure everything works the way you expect, I'd suggest using just one of the Attach 3 joysticks and using the simple code as-is.
Assuming you get the LabVIEW update installed.
That just means rotate will be controlled by the throttle on the Attack 3, so make sure that's centered when you start.
Once you're sure the mechanics all work properly and the PWM wiring goes to all the correct motors, then start improving the controls.
"Tank-based holo drive" (what Ether was describing): robot is driven normally like a tank: two joysticks control the left and right wheels of the robot.
Correct. You use the Y axis of each joystick for tank drive.
But, when the driver presses a button, the robot switches to strafing only
That's not what I was describing. When you hold a button down, it enables the X axis of, say, the right joystick. The X-axis controls strafing. But the Y axes are not disabled. The Y axes of the 2 joysticks continue to operate as tank drive in this mode, controlling the fwd/rev and rotate degrees of freedom. So the driver, if skilled enough, can control all three degrees of freedom simultaneously.
The button is not required. You could leave the X-axis (strafe command) enabled all the time. Field experience has shown, however, that it is useful to disable the X-axis unless it is needed. This way, the driver doesn't unintentionally command strafe when he doesn't want it.
This might be a little trickier and would require a combination of the holo drive VI and the tank drive VI (switching between the two based on if the button was pressed).
All it requires is the cartesian mecanum vi. No switching is required. Calculate (Y1+Y2)/2 and feed it to the cartesian mecanum vi "Y" input (fwd/rev). Calculate (Y1-Y2)/2 and feed it to the "rotation" input. Feed X to the X input (strafe). This will provide tank drive with the left and right joystick Y axes; and when X is not zero you will get strafing too.
However, this is nice and easy to drive because you normally just drive with the tank drive technique, which is intuitive. The strafing is like an added bonus.
Exactly.
(Note: you could use arcade drive instead of tank drive, which would require only one joystick. The point is that you're switching between that and holo drive to enable strafing).
You could use 2 joysticks for arcade+strafe with the cartesian mecanum vi: Y1 for fwd/rev, X1 for rotate, and X2 for strafe.
For a first test to make sure everything works the way you expect, I'd suggest using just one of the Attach 3 joysticks and using the simple code as-is.
Wise advice.
Something I've found to be helpful too: Put the robot up on blocks and observe the wheels:
When you command straight forward, all four wheels should spin forward.
When you command straight backward, all four wheels should spin backward.
When you command pure CW rotation, the front and rear port side wheels should spin forward and the front and rear starboard wheels should spin backward.
When you command pure CCW rotation, the front and rear port side wheels should spin backward and the front and rear starboard wheels should spin forward.
When you command pure strafe left, the front port and rear starboard wheels should spin backward, and the front starboard and rear port wheels should spin forward.
When you command pure strafe right, the front port and rear starboard wheels should spin forward, and the front starboard and rear port wheels should spin backward.
Pay careful attention to how you have the mecanum wheels mounted too: Right way (http://car.pege.org/2006-ever-monaco/4-wheels-4-motors.htm) Wrong way (http://www.gizmowatch.com/entry/a-rough-and-rugged-segway/)
RoboMaster
24-10-2010, 22:08
Good points, Ether, thanks.
Yes, I suppose I should have said it was my version of your describe drive, but I was just being general and as simple as (I thought) possible. But you explained your control ideas very well in your (second to) last post, thank you. I new you could probably drive a robot tank style with the holo drive VI, but it would require complex converting of two joystick axis into the X and Y holo drive terminals. Thanks for your explanation of how to do it easily!
whcirobotics
15-12-2010, 19:19
I have finished coding it and i have attached a picture. Is it accurate? i just want to make sure so i dont disappoint the construction crew that worked so hard to make me a test frame with attached macanum wheels.
I have finished coding it and i have attached a picture. Is it accurate?
What user interface are you trying to implement?
I don't recognize Tank, Arcade, or Halo in the code you made.
Did you mean to set the holo vi for polar? If so, doesn't look like direction input is scaled correctly.
Did you mean to use the throttle for rotation? Seems awkward. Driver needs three hands.
whcirobotics
15-12-2010, 22:16
O.o I meant to have it on "cartestian" not polar. slight error woops! I wanted it to be like 1 joystick controls the up and down motion of robot, and the other joystick the starfing part, thats why i attached the y axis to one joystick(up down) and the starfing and x to other joystick. Isnt that what my code is doing? :S
And plus * mark posted this picture earlier in this post > http://www.chiefdelphi.com/forums/attachment.php?attachmentid=9369&d=1287950414 > in which he has 3 wires that can go into the holonomicdrive(cartestian) but i only have 2 terminals :S i did the update , how come he has an extra bit? i only have x, y, rotation and robotdevref and gyro angle ? i connected the x and y but where does the throttle go?
I wanted it to be like 1 joystick controls the up and down motion of robot, and the other joystick the starfing part, thats why i attached the y axis to one joystick(up down) and the starfing and x to other joystick.
You've got Y2 controlling fwd/rev, X1 controlling strafe, and throttle controlling rotation. This sounds like an extremely awkward driver interface to me. Driver needs 3 hands.
Why not use a more standard driver interface like one of the following:
1) Tank Drive plus strafe. See posts 9 and 17 in this thread. Takes advantage of driver's familiarity with tank drive.
2) Halo plus rotate. Y1 controls fwd/rev, X1 controls strafe, X2 controls rotation. Takes advantage of driver's skill at playing Halo-style videogames.
3) Arcade plus strafe. See post 17 in this thread.
You can use the throttle to adjust joystick sensitivity (gain) so different drivers can adjust it to their liking.
whcirobotics
16-12-2010, 07:35
I did the Halo + rotate and attached the up/down to y1, starfing to x1, and rotation to x2. But where does the axis three throttle go? In the picture which mark posted he had it going to one of the terminals in the cartestiandrive, but in the picture i attached, i only have x, and y, and rotation :S am i missing something? an update perhaps? I have attached the code, is it accurate now?
I did the Halo + rotate and attached the up/down to y1, starfing to x1, and rotation to x2. But where does the axis three throttle go? In the picture which mark posted he had it going to one of the terminals in the cartestiandrive, but in the picture i attached, i only have x, and y, and rotation :S am i missing something? an update perhaps? I have attached the code, is it accurate now?
I'm not a LabVIEW programmer so I can't tell you if it's accurate, but I'm pretty sure it's not correct: If you want your robot to go up and down and starfe, you're going to have to write your own vi for that. The built-in LabVIEW vi supports only fwd/rev, strafe, and rotate. :-)
But seriously, as for the throttle, where you "attach" it depends on what you want it to do. What do you want it to do? You need to re-read Mark's post (http://www.chiefdelphi.com/forums/showpost.php?p=978263&postcount=16) to understand that he attached the throttle to the rotation input "For a first test to make sure everything works the way you expect" with one Attack3 joystick. If you now have two joysticks (or a joystick with a twist axis), you don't need to do that.
whcirobotics
16-12-2010, 09:29
I meant the up/down as in forward and reverse. And i am using two joysticks so i guess i wont need to attach throttle to anything. I will try this code(hopefully it works) but you are saying it is wrong so i am not so sure as to try it or not. :S
I meant the up/down as in forward and reverse... but you are saying it is wrong
Yes I assumed that or we couldn't have had this conversation. The smiley at the end was meant to convey that I was just joking.
but you are saying it is wrong so i am not so sure as to try it or not.
All I can tell you is that it looks like you now have the inputs to the holo vi wired correctly for two-joystick "Halo plus rotate" driver interface.
As for the rest of the diagram, I am not a LabVIEW programmer so maybe someone else will take a look at it to see if there are errors.
I will try this code(hopefully it works)
Have you checked to see that the mecanum wheels are mounted correctly (http://www.chiefdelphi.com/forums/showpost.php?p=978270&postcount=18)? This is a common error. Checking this can save you a lot of frustration.
RoboMaster
16-12-2010, 23:48
As a LabVIEW programmer, your newest screen shot looks good to go.
whcirobotics
23-12-2010, 10:02
Hi CD, I got 5 team members and 1 mentor to come on a Wednesday(December 22, 2010) and we build a test robot with the macanum wheels in 4 hours. We finished and i deployed the code and pressed enable on teleop. This is a video of what happend:
http://www.youtube.com/watch?v=es7OF_V-LWU
Is there something wrong with the code? It is the same code as the one attached above. But the problem was that one wheel kept turning. I tried attaching the pwms to other than that of 7, 8 , 9 , 10 and put them in 3 , 4 , 5 , 6 and again that wheel kept turning. :S
The mentor suggested that that one might be calibrated other than 0, but what else could possibly be wrong? Maybe the software? :S Help please.
Hi CD, I got 5 team members and 1 mentor to come on a Wednesday(December 22, 2010) and we build a test robot with the macanum wheels in 4 hours. We finished and i deployed the code and pressed enable on teleop. This is a video of what happend:
http://www.youtube.com/watch?v=es7OF_V-LWU
Is there something wrong with the code? It is the same code as the one attached above. But the problem was that one wheel kept turning. I tried attaching the pwms to other than that of 7, 8 , 9 , 10 and put them in 3 , 4 , 5 , 6 and again that wheel kept turning. :S
The mentor suggested that that one might be calibrated other than 0, but what else could possibly be wrong? Maybe the software? :S Help please.
Others may have different suggestions, but if I were you here's what I'd do in your situation:
- Create a separate new software project with VERY SIMPLE CODE that allows you to control each wheel one at a time. This should be very quick and simple to do.
- Run this code and test each wheel individually to make sure each wheel responds properly (both forward and reverse) and equally with respect to the others.
- If your robot passes this test, it is mechanically and electrically sound. The problem is in your mecanum software.
- If the robot fails this test, first double-check your simple code. Then check the PWM indicator light on the Dashboard for that motor. If everything checks out, then you have a hardware problem. Check the indicator lights on each Jag when it is being commanded. If OK, check the voltages for that circuit (motor out, power in).
whcirobotics
23-12-2010, 11:06
The mentor suggested that we try this and we did try to get 1 victor at a time and it worked fine. Then we tried 2 at a time and it worked fine. Then i tried all together and one of it failed. So i guess it is a software problem, either that or that one is calibrated. But i doubt that it is hardware partly because of the fact that i tried again but this time i opened new project and tried writing the code and then deployed it and this time the front left one did not spin as seen in video but front right did. :S and the front left was moving for 5 seconds and then a jerk. So on and so forth. And secondly because i confirmed all the hardware things with our mentor who is electrical engineer (Mr.Thomas) and he said everything looks good except one might be calibrated. BUT if one was calibrated why did it not spin when i ran the new code, but front right one was spinning :S Something is very wrong somewhere in hardware or software :S
The mentor suggested that we try this and we did try to get 1 victor at a time and it worked fine. Then we tried 2 at a time and it worked fine. Then i tried all together and one of it failed.
Describe in greater detail what you mean by "one of it failed". What exactly did you observe?
whcirobotics
23-12-2010, 11:25
One of them was spinning without any input from the joystick
we did try to get 1 victor at a time and it worked fine.
Just to be perfectly clear: Did you do this for each of the 4 wheels individually, and each of them worked fine?
Then i tried all together and one of it failed.
Again, to be clear:
- After you tested each wheel individually, you then tried running all 4 at the same time?
- And when you did all 4 at the same time, with zero command, one of the wheels was spinning?
- And the wheel that was spinning had previously worked correctly when tested individually?
Is everything above a correct description of what you did and what you observed? If not, please explain what you did.
whcirobotics
23-12-2010, 14:38
Yes that is correct
Yes that is correct
OK, two more questions:
1) How fast was the "failed" wheel spinning, when the command was zero? I don't need a number, just a description, like was it really fast or was it slow?
2) When the command was zero and the motor was spinning, what was your Dashboard saying about the PWM command signal being sent to that motor?
whcirobotics
23-12-2010, 14:49
The speed was about the same speed that the wheel is spinning in the video. The dashboard did NOT say anything about the pwm. No conflict or anything
The dashboard did NOT say anything about the pwm.
I don't know what you mean by the above. The Dashboard always tells you something about the PWM command signal. It tells you what the signal level is... it tells you what your software is commanding. This piece of information is very useful to isolate the cause of the problem.
whcirobotics
23-12-2010, 16:15
Yes i meant to say that it was normal it was not showing anything awkward
Yes i meant to say that it was normal it was not showing anything awkward
I don't mean to belabor the point here, but does "normal" and "not awkward" mean it was reading zero? If you don't remember it's OK, I just need to know in order not to give you a misleading answer.
whcirobotics
23-12-2010, 16:38
I cant remember sorry but i can confirm what is happening accurately on January 3 when the school starts ?
I cant remember sorry but i can confirm what is happening accurately on January 3 when the school starts ?
Sure!
Mark McLeod
23-12-2010, 17:23
Offhand, based on the video evidence, I'd calibrate that Victor.
The status light did not go to Neutral that I could see.
It seems to be controlled properly and reverses fine, but just doesn't appear to go to neutral.
It's easy to tell though if you watch the Victor status lights. When your hand is off the joysticks (neutral) all the Victor status lights should be solid yellow/orange. If a light is not solid then the wheel should be turning.
It's safest to calibrate them while using a brand new simple default framework program. That's Arcade drive and eliminates the possibility of any software errors you may have. However, make SURE the Drive motor Open in Begin.vi gets changed to "Victor." You can also change the Drive to 4 Motors, so you don't have to move PWM cables around. It'll also give you a chance to tell which PWMs may need reversing.
When you get back into school before making any changes test:
Neutral - all Victors = solid yellow/orange
Full Forward - all Victors = solid red or green
Full Reverse - all Victors = solid green or redIf any of these don't happen with the default Arcade drive, then the associated Victor needs calibration.
Mark McLeod
24-12-2010, 09:18
In engineering, it's unusual to throw a lot of new things together, turn it on and expect it all to work together.
Normally, we'd test each sub-system independently, and work out the bugs in each, before trying them together.
Errors in one sub-system can mask errors in another sub-system. Two wrongs can make an inadvertent right, then later on when an unnoticed error gets corrected, suddenly the software that was working so perfectly stops working.
Then, when you begin to put sub-systems together, you want to develop a step-by-step test plan to verify that each piece is working properly. Inspecting the PWM orders coming from the software is one of those tests.
whcirobotics
03-01-2011, 17:05
Hi CD i tried the code it worked fine but it is rather .. complex to use both joysticks .. so i want it to turn when say button 2 is pressed.
I do realize that i cant just take the button and connect it directly to the rotation obviosaly. How do i do it? I am just asking for the sake of having ease of driving. Can someone provide an example? Like if button 2 is pressed then rotation is enabled?
I attached a picuture for what i did but i highly doubt it is correct.
whcirobotics
03-01-2011, 17:50
never mind! sorry for that! that piece of code worked! :)
Note that Mark's code is really used for a joystick that twists (the kit joysticks don't).
Can anyone recommend a compatible joystick that can twist?
whcirobotics
08-01-2011, 17:58
Can anyone recommend a compatible joystick that can twist?
Get a regular ps2 controller and get a USB adapter and connect it to computer. Thats what we are using now. But iam sure there are other joysticks out there, but this one easy to use.
Joe Ross
09-01-2011, 00:04
Can anyone recommend a compatible joystick that can twist?
We have used both the Logitech 3D Pro and the Cyborg X in previous years.
http://www.bestbuy.com/site/Logitech+-+3D+Pro+Joystick/5796515.p?id=1058188350464&skuId=5796515
http://www.bestbuy.com/site/Cyborg+-+X+Flight+Stick/9388824.p?id=1218096957779&skuId=9388824
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.