swerve drive with arduino mega 2560

hi, thus isnt for my team, but in my engineering class at school im working on a swerve drive but, but i have no experience programming since i usually stay on electrical. could someone help me figure out the code?

You will need encoders for each wheel’s rotation, a motor to spin each wheel module, and a motor to drive each wheel. More info on swerve drive mechanics can be found here.

For the programming, check out this document published by Ether which will help you control how your swerve works.

I tried running swerve calculations on an XMOS, which is approximately 20x as powerful as an Arduino Mega. I don’t believe I threaded on it though, so it was only about 5x as powerful.
My advice: don’t do it. Crab drive is very easy to get working, but if you want true swerve motions like snake/ocelot turns, it’s going to be difficult due to the math involved in vector addition. The Arduino is not optimized for the trig functions you need to use, and it will slow you down a lot- and that’s before even trying PID or even just P controls on module rotation.
I believe I got somewhere between 50-100ms per loop, from reading joystick to motor controller outputs. This was however fr from optimized, as I was using a custom PWM generator that ran once per loop to make the motor control signals. Using the Arduino Servo library to control would help reduce the main loop loading.

If you do try it, optimize for speed. Avoid full swerve motion (crab is cool enough anyway, and scrub shouldn’t be a problem on a small scale). If you want to do full swerve, find a way to approximate the trig to add vectors so you don’t bog down the processor.

Running a full swerve system on an Arduino is certainly possible, but it may be more of a challenge than you would like to take on. The biggest issue with the Arduino is that it does not have a floating point execution unit in the CPU. That means that all floating point operations have to be performed in software. Relatively speaking, this is very slow. In a typical swerve application, there are many FP operations required to determine steering angle, and wheel speed utilizing trig functions, PID loops, etc. If you attempted to do this directly on the Arduino, it would not have the processing power to perform these operations in a timely manner. A number of teams had swerve drives in the old IFI controller days. These controllers, while quicker than the Arduino - 40 MHz as opposed to 16 MHz for a Mega, also did not have a FP unit. Several strategies were used as work arounds to minimize or eliminate the need for floating point calculations including fixed point math and integer trig approximations. I would also recommend that you look into efficient interrupt driven routines for, what I will call, background tasks (encoders, analog signal A/D, PWM generation); again to minimize CPU usage and unnecessary delays.

For reference, I used an old IFI controller (2007 vintage - it was free) to make a swerve drive about a year ago using the techniques I mentioned above. It is a full swerve, with multiple modes including snake, and I am confident that I could make it work on an Arduino as well. However, I wouldn’t recommend it unless you are willing to put a fair amount of time as it will not be easy (but a great learning experience!).

Mike

This robot is running full 4 wheel swerve on an Arduino…

The controls code is based on the Ether paper. Ether also helped write some integer based routines to optimize the code…it works great.

More firepower would be great, but it isn’t required.

If you want trig functions you don’t actually need full floating point support: use a look-up table.

http://www.societyofrobots.com/programming_trigtable.shtml

BTW there are trig look-ups masked into the Parallex Propeller just for this reason,


Page 34.

all oof the answers are confusing me, the calculations i can probably figure out on my own, and the whole thing is completely set up except for the code, which is what i need help with. i put the issue in the description of the problem im having. butvtganks anywayb:) also, i cant switch the setup of what im using significantly, like using somethingbother than a swerve drive, arduino, ot talons, but i can out thungs on it. also, sorry for the spelling mistakes, im using a touch screen computer and its hard to type correctly

i just realized I didn’t put the issue in for lack of time, here is what is going wrong:
i clicked burn bootlegger after doing all previous steps correctly and this came up-

Arduino: 1.6.9 (Windows 8.1), Board: “Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)”

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x03
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

I’m not sure why you would have to do “burn bootloader.” Arduino boards come hot out of the gate ready to go.

Under “tools->board” make sure you have the correct Arduino hardware selected. Then check that you have the correct “com” port selected.

Then press the upload arrow and you should be running code. Test this with the supplied examples before trying to upload your own custom code.

+1. It looks to me like they may be saving their compiled code as a .hex file and flashing it to the Arduino. OP, you should try uploading code with the Arduino IDE.

Agreed.

The whole point of an Arduino is to be “foolproof.” Start with using their supplied tool and examples to make sure everything is working as expected…then try your custom config.

Hi Becky,

I just ran through an installation of the Arduino software (I needed to upgrade anyway) and downloaded to a Mega and will list the steps that I went through to get it to work (there may be other ways, this is just what I used). Most of this is just a repeat of what others have said above.

  1. Open a new sketch and cut/paste the Blink code example that can be found here near the bottom of the page. This is just to have a known good sketch to test.
  2. In the menu item Tools->Board select “Arduino/Genuino Mega or Mega 2560”
  3. In the menu item Tools->Programmer select “AVR ISP”
  4. Verify your code by clicking on the left hand button with a Check Mark in it just below the menu items (The word “Verify” should display to the right of the buttons when you hover your mouse over it). It should return some messages at the bottom if the IDE indicating how large the sketch is and global variable use.
  5. Plug in your Mega if you haven’t already done so.
  6. In the menu item Tools->Port, select the your Mega. Mine was labeled “COM3 (Arduino/Genuino Mega or Mega 2560)”. Yours may have a different COM number.
  7. Upload to the Mega the Blink program by pressing the right arrow button next to the verify button you used earlier. To the right of the buttons it should show the word “Upload” when you hover over it with your mouse. After a few seconds a message indicating “Done uploading.” should be shown below your sketch and above the message area it it worked correctly. Also, the led on the mega (yellow on mine) will be blinking at 1 second intervals.

This worked on mine. If this works for you, then you should be able to upload your own sketch, but you may have to change the Board, Programmer & Port again (Steps 2,3 & 6) after you open your sketch. If this doesn’t work, if you can post any error messages you are seeing, that would help us identify the problem.

Mike

it is working now, but I still don’t know how to code more than in extremely basic python, so im not sure what to do. ill post a picture of the whole thing in a few minutes in case that is helpful. the code is empty as of right now.

blob:https%3A//mail.google.com/6927b9bd-8c0e-4b71-91b0-fd0a0535bec7

here it is

The URL doesn’t seem to work for me. Can you try to post the picture or copy it to some other location?

Mike

Instead of starting with a swerve drive in Arduino, try working through the tutorials first; it’ll be a lot of help.

https://drive.google.com/file/d/0B7L-x56rsK8HWk5SU3BRTER6bXd4NTJRdG1MbEhmVzlZc3ZV/view?usp=sharing

this will hopefully work

i have to start with a swerve drive and arduino, the project was to make a swerve drive bot and i only need to do the programming now. i didn’t choose the assignment, plus i spen翶spent too long cadding it for ages until i was the only person left who hadn’t graduated and now I needa finish it on my own.

This is an exceptional challenge…

We can help, but we can’t do everything.

Have you done the following:?

  1. Loaded an example program onto the arduino, i.e. blink
  2. Verified that the example program is running

You have to at least achieve this before attempting to write any robot control code.

Also, it sounds like you’re using a programmer tool. You shouldn’t need this…just a USB cable and the Arduino software.

Also, I can’t see from the image if you have a steering sensor installed?

I presume you have it located on top of the steering module…but I can’t tell.

Is this true? What sensor is it?