![]() |
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?
|
Re: swerve drive with arduino mega 2560
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. |
Re: swerve drive with arduino mega 2560
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. |
Re: swerve drive with arduino mega 2560
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 |
Re: swerve drive with arduino mega 2560
This robot is running full 4 wheel swerve on an Arduino...
https://youtu.be/hdAmpk0PQ3I 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. |
Re: swerve drive with arduino mega 2560
If you want trig functions you don't actually need full floating point support: use a look-up table.
http://www.societyofrobots.com/progr...rigtable.shtml BTW there are trig look-ups masked into the Parallex Propeller just for this reason, https://www.parallax.com/sites/defau...anual-v1.2.pdf Page 34. |
Re: swerve drive with arduino mega 2560
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
|
Re: swerve drive with arduino mega 2560
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. |
Re: swerve drive with arduino mega 2560
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. |
Quote:
+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. |
Re: swerve drive with arduino mega 2560
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. |
Re: swerve drive with arduino mega 2560
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 |
Re: swerve drive with arduino mega 2560
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.
|
Re: swerve drive with arduino mega 2560
blob:https%3A//mail.google.com/6927b9bd-8c0e-4b71-91b0-fd0a0535bec7
here it is |
Re: swerve drive with arduino mega 2560
The URL doesn't seem to work for me. Can you try to post the picture or copy it to some other location?
Mike |
Re: swerve drive with arduino mega 2560
Instead of starting with a swerve drive in Arduino, try working through the tutorials first; it'll be a lot of help.
|
Re: swerve drive with arduino mega 2560
|
Re: swerve drive with arduino mega 2560
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.
|
Re: swerve drive with arduino mega 2560
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. |
Re: swerve drive with arduino mega 2560
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? |
Re: swerve drive with arduino mega 2560
it doesn't have any sensors on it yet, i will probably add them soon, but i kinda wanna figure out how to code it first since I don't know C++ at all yet.
|
Re: swerve drive with arduino mega 2560
Have you done the following:?
1. Loaded an example program onto the arduino, i.e. blink 2. Verified that the example program is running |
Re: swerve drive with arduino mega 2560
i don't think so. im not sure how
|
Re: swerve drive with arduino mega 2560
http://lmgtfy.com/?q=how+to+load+code+onto+my+arduino
Check out the first link. :) Arduino is supposed to be easy....so follow their simple guide and get some example code loaded. Then we can discuss doing something like controlling a speed controller etc. |
Re: swerve drive with arduino mega 2560
i tried the one called blink and it seemed to work
|
Re: swerve drive with arduino mega 2560
i have to go until monday since I don't have class again until then, but thanks for your help so far
|
Re: swerve drive with arduino mega 2560
Perfect.
Now you can investigate the "Servo" example. It shows you how to send commands to a hobby servo...this is similar to sending commands to speed controller. I don't recall off the top of my head if it'll just work or if it needs some tweaks...regardless, it'll send PWM commands out a pin on the arduino and make your speed controller request voltage be sent to your motors. |
Re: swerve drive with arduino mega 2560
Quote:
|
Re: swerve drive with arduino mega 2560
Becky,
First off, I think this drive system is an great choice for a first swerve system. Having the steering modules linked together, as well as speed, will make things much easier from a control aspect. Because of this, I wouldn't start with any sensors. They are not needed to be able to drive around, and for someone relatively new to programming, this will make things much easier. I would use a two axis joystick model, where the forward/backwards motion drives the robot, and the side to side motion controls the speed of turning. Sensors can be added later once you get it driving if you want to have more (or more interesting) control. As others have said, you will need to be able to generate PWM signals for the speed controllers and the Arduino servo library has that capability. But before we get to that, one important question comes to mind. Have you thought about how you are going to control this? What type of operater station do you have and how will it communicate with the Mega? Wireless? Wired (tethered?) Somehow you will need to get the information to the mega on what you want it to do, and that will add another layer of complexity to your system depending on the communications you want to use. I would initially like to suggest an idea that could make this project much easier (no programming). Do you have access to an RC style transmitter/receiver? Maybe something like this? Using an RC style controller would allow you to eliminate the mega and just control the speed controllers directly. IIRC, the talons should be able to take a standard servo style input. Just a thought. There may be other better ideas out there, but this happened to come to mind. Would this be a possibility? Mike |
Re: swerve drive with arduino mega 2560
Quote:
|
Re: swerve drive with arduino mega 2560
Quote:
Our free RobotOpen library and driver station will make tele-operation via wifi dead simple once she gets there. RC is an option too, but why not use the stuff designed for Arduino. :) http://www.team221.com/robotopen/index.html I think she can run this thing in autonomous only mode as well...she never mentioned needing tele-operation. |
Re: swerve drive with arduino mega 2560
i would like to make it so that it is possible to drive it with sensors or a remote, as in have them both as an option. but im not sure how to put either a sensor or connect a remote to it. for me, the steps are really the things I need the most help with
|
Re: swerve drive with arduino mega 2560
also, im not sure what kind of sensor i should use
|
Re: swerve drive with arduino mega 2560
im going to use four IR sensors; one in each direction
|
Re: swerve drive with arduino mega 2560
Before this project gets all the way off the rails let's just keep making some forward progress.
The very next step you need to accomplish is to get the speed controller spinning the motor using commands from the Arduino. The "Servo" example is a good starting point. Start there and see if you can get any action. |
Re: swerve drive with arduino mega 2560
I cant find it.... also, i can talk at most points but I can only work on it from about 10-11 each day with maybe half an hour to an hour difference in when, but still only an hour of work
|
Re: swerve drive with arduino mega 2560
In the Arduino IDE
File->examples->servo |
Re: swerve drive with arduino mega 2560
it's not there
|
Re: swerve drive with arduino mega 2560
it has servo mood indicator
|
Re: swerve drive with arduino mega 2560
make sure you have the newest IDE installed....I'm using 1.6.9...servo is under "examples" near the bottom.
|
Re: swerve drive with arduino mega 2560
as in the newest upgrade
|
Re: swerve drive with arduino mega 2560
|
Re: swerve drive with arduino mega 2560
1 Attachment(s)
See attachment.
|
Re: swerve drive with arduino mega 2560
i don't think that there are servos on it yet
|
Re: swerve drive with arduino mega 2560
and it is also arduino 1.6.9
|
Re: swerve drive with arduino mega 2560
and it just appeared
|
Re: swerve drive with arduino mega 2560
its not wrking
|
Re: swerve drive with arduino mega 2560
Basically, the sketch is right and i verified it, but when i uploaded it and everything, it said "uploading" and when it was done, acted as though it was an empty sketch and did nothing
|
Re: swerve drive with arduino mega 2560
Sounds like it may not have the right com port selected.
On menu, go to "tools" then "port" and select port. Then on menu, go to "tools" then "Get Board info" and see if it returns "Mega" If not then go back to "ports" and select a different "port" Then try to "Get board info" Assuming the mega is plugged into the computer via usb cable, one of the ports will respond correctly. Use that one, and try to upload again. When uploading you will see LED activity on Mega board, rx and tx flickering. |
Re: swerve drive with arduino mega 2560
it's definitely the right port, the "blink" example worked
|
Re: swerve drive with arduino mega 2560
i used the sweep example under servo
|
Re: swerve drive with arduino mega 2560
Quote:
The last thing you said was basically "its not wrking". You're going to have to go into a lot more detail than that if you want us to help you make it do what you think it should be doing. What is "it" that should be working? What do you expect it to be doing? Once you tell us that, there will be more questions about how you have "it" connected and what else you have connected to "it". |
Re: swerve drive with arduino mega 2560
Quote:
Did you wire GND of the Mega to the PWM Gnd of the motor controller? You can wire the PWM Red to +5v of the Mega, but I am pretty sure it is not required. The Sweep servo program uses pin(9) in the sketch. *As a debug tool, you could add code to turn on, or blink the LED on pin 13, so you would know that the program is running. |
Re: swerve drive with arduino mega 2560
Becky,
Assuming you still have the speed controllers wired up the same way you had in your picture earlier, I think Scott is on the right track. It looks like you have your speed controllers wired near the pin 0 / pin 14 area. (I would move the wires if you use pin 0 or pin 1 as those are also used for the USB connection.) In order for the speed controllers to work, they each need two wires; a signal wire (which I think is your white wire) and ground wire (the black wire). You can use most any pin for the signal - you just need to change the sketch to attach to the one you use, but you also need a the ground. A ground connection can be found next to pin 13 as well as on the opposite side of the mega in the "power" section. You may already have the ground running from across the board, but it is hard to see in the picture. If you actually have the ground connected, then just change the "9" in the myservo.attach(9) statement in the Sweep example to the pin number you are actually using (not 0 or 1). If you do not the ground connected, and you have a standard 3 pin connector on the end of your PWM cable, then it would be easier to plug one cable direcly to pins 12 (white), 13 (red) & gnd (black). Then change the "9" in the myservo.attach(9) to "12". (just verify that the black wire does indeed go to the ground connection on the Talon). Mike |
Re: swerve drive with arduino mega 2560
FYI, not all Arudino Outputs are PWM compatible.
Code:
PWM: 2 to 13 and 44 to 46. Provide 8-bit PWM output with the analogWrite() function |
Re: swerve drive with arduino mega 2560
Scott - I believe the Servo library uses a timer and software to generate the PWM signal, so it is independent of the hardware generated PWM pins.
Becky – Getting back to one of your older questions. You don’t have to have a steering sensor if you are only going to run it in a “tele-operated” like mode if you want to keep things simple, although it will still be useful if you want it to drive in some modes. However, if you want to do autonomous driving, then you will definitely need a sensor to know the actual wheel position. I’ve had good luck with these. Specifically the 6127V1A360L.5FS. For mounting you really need these to be 1:1 with your wheel modules so the analog value will directly relate to a direction on the wheels. Since your steering motor uses a smaller sprocket than the swerve module, I’d install another shaft with the same size sprocket on one of the other wheels and attach the position sensor to that. This should be fairly easy since you have the double sprockets at each wheel. One thing to remember is that these sensors generally do not like high side loads, so I wouldn't recommend putting the sprocket directly on the sensor shaft. Mike |
Re: swerve drive with arduino mega 2560
If you are having trouble you can use the library I wrote to control FRC motor controllers. check the link below, and consult the wiki for help.
|
Re: swerve drive with arduino mega 2560
Quote:
|
Re: swerve drive with arduino mega 2560
1 Attachment(s)
:)
|
Re: swerve drive with arduino mega 2560
Quote:
https://sourceforge.net/projects/ardurio/ |
Re: swerve drive with arduino mega 2560
i went to the link but it ended up just confusing me
|
Re: swerve drive with arduino mega 2560
Go to the Files tab and download the files, and then when you have it downloaded go to the Wiki tab to learn how to use it. I'm willing to walk you through it.
|
| All times are GMT -5. The time now is 14:34. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi