Society of Robots - Robot Forum
Software => Software => Topic started by: vipulan12 on March 10, 2013, 12:06:52 PM
-
Hey guys, Is it possible to run multiple servos at the exact same time on the arduino uno, i want to see if i could create a walking robot that could move its thigh,heel and foot to create movement
in total it would be six servos
could this work?
-
Yes, it is possible and has been done.
Search the forums here for more info.
Also look up the Webbotlib code to make coding for multiple servos easier.
-
I am new to programming, so could you explain why exactly the webbotlib is helpful?
-
It contains pre-written high level code to setup and use the Atmega's hardware features.
As I said, look it up. There is a lot of info in the SoR forums about webbotlib and how to use it.
Just type "webbotlib" in the text box at the upper right of this screen then click the 'search' button.
-
If you're using a Arduino Uno, I think using the Arduino libraries and IDE is probably the easiest way to go, s it has many, many tutorials all over the web. For example, the Servo library lets you connect and drive up to 12 RC hobby servos (PWM) with reasonable performance. Not saying Webbotlib is bad, but if you're using Arduino specifically
-
Ok, what jwatt said is a better way to start learning.
-
could you send me sample code or something?
I am stuck on the programming aspect since if i were to code the servos normally it go in chronological order rather than the same time
-
could you send me sample code or something?
I am stuck on the programming aspect since if i were to code the servos normally it go in chronological order rather than the same time
Microcontrollers don't do anything at the same time, all is done sequentiality, however it is done so fast that it seams that everything is happening at the same time. Using dedicated PWM pins would be best, but that means that Your Arduino has to have 6 PWM channels. Also, driving many servos can be done by toggling IO pins with software, but, as far as I know, stability falls with extra workload added to microcontroller. You are lucky though, as Arduino Uno has 6 PWM pins, meaning that all 6 servos can be driven in hardware without having an impact on stability and main loop performance.
--> http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM (http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM)
-
The Servo library for the Arduino uses interrupts and a single timer to drive up to 12 servos. It is *reasonably* stable. The code lets you configure the position the servos should take, and the library takes care of actually putting the servos there asynchronously from when you tell the library. So, you'll do something like:
- tell library to put pin 8 at position 1900
- do some work
- tell library to put pin 3 at position 1200
- tell library to put pin 4 at position 700
- do more work
The library will continually (every 30 milliseconds) send the latest set position to each of the pins. This means that pin 3 may actually be told to go to position 1200 right before pin 8 gets told to go to position 1900.
However, this is so fast (30 milliseconds is less than the duration of a single frame of film at the movies) that, from a human point of view, it looks simultaneous.
I highly suggest you try the built-in Servo library with your servos and Arduino. I think it'll work well for your application.
-
could you send me sample code or something?
I am stuck on the programming aspect since if i were to code the servos normally it go in chronological order rather than the same time
A sample code for 2 servos is shown at http://learn.parallax.com/node/179 (http://learn.parallax.com/node/179)
You can see that the servo library is taking care of sending the required signals periodically. You just give an order once: a_servo.writeMicroseconds(a_number);. That order is repeated behind the scene, forever, until you send another order or detach the servo.
... The library will continually (every 30 milliseconds) send the latest set position to each of the pins.
By the way, this is rather every 20 milliseconds, as you can see on the diagram at Wikipedia, http://en.wikipedia.org/wiki/Servo_control (http://en.wikipedia.org/wiki/Servo_control) and on the oscilloscope of the video How do RC Servos work? Part I (http://www.youtube.com/watch?v=nd571nTGjHs#) .