Arduino Servo Programming assistance

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
bt1996
 
Posts: 4
Joined: Tue Oct 15, 2013 11:15 pm

Arduino Servo Programming assistance

Post by bt1996 »

Hello,


Here is my project: I have an Arduino Uno board that controls 2 servos. The 2 Servos sit on the left and right side of the robot, they are continuous rotating servos. It robot leans on ball point in the middle forward tip of the robot.

My goal is to program pre-determined paths. I been attempting to use code like this to make that happen:

myservol.write(100);
myservor.write(100);
delay(450);

That will normally make the robot turn 90 degrees to the left. However it is not very accurate. Factors come to the play including the battery, when it dies down a bit 90 degrees turns into 80, because the Servos move slower.

I can only see two solutions: (Open to more ideas)

Solution 1: Somehow get the voltage to stay at an exact constant. (Not sure how, its current getting its power from the 5v power pin on the Arduino board.)

Solution 2: Come up with a more accurate way to code, not one that works off time. (Again open to suggestions im not sure how to do this either)


Im open to any solution thoughts or new ideas!

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Servo Programming assistance

Post by adafruit_support_mike »

What you've described is officially known as an "open loop control system" (OLCS). You send commands to the actuator and hope everything works as you'd planned.

The accuracy of an OLCS depends on the accuracy of the actuators, as you've learned. If they don't go as far as you thought they would, the error throws everything off. People building OLCSes tend to use stepper motors and gear racks for positioning when they want accuracy. Under normal operting conditions, steppers go to a known position with a known amount of error every time.

Servos are another story.. especially continuous-rotation servos. They aren't made for precise motion.

The alternative is to give your robot senses so it can see where it's going. Instead of "run the motor for 12 seconds", the command becomes, "run the motor until your sensors say you've reached this position". That's called "closed loop control system".

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Servo Programming assistance

Post by adafruit_support_bill »

There are a couple of ways to 'close the loop' with your robot. One common method is to add encoders to the wheels. This gives you feedback on exactly how much the wheels have rotated. Assuming perfect traction on a smooth flat surface, you will be able to make fairly repeatable movements. But that is only closing the loop between the processor and the wheels. It doesn't account for wheel slip or other variations that might affect final position.

Another approach is to add sensors that detect motion. A gyro sensor will detect rotation. An accelerometer will detect linear acceleration. And a magnetometer will detect your orientation relative to the earth's magnetic field. If you put them all together in one package, it is called an "Inertial Measurement Unit" or IMU. http://www.adafruit.com/products/1604

bt1996
 
Posts: 4
Joined: Tue Oct 15, 2013 11:15 pm

Re: Arduino Servo Programming assistance

Post by bt1996 »

I like the idea of adding encoders on the wheels. My robot will always operate on a smooth flat surface so encoders should do the trick. Are there any tutorials our directions anyone would recommend?

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Servo Programming assistance

Post by adafruit_support_bill »

This encoder is designed to work with continuous rotation servos: http://nubotics.com/products/ww11/index.html

bt1996
 
Posts: 4
Joined: Tue Oct 15, 2013 11:15 pm

Re: Arduino Servo Programming assistance

Post by bt1996 »

What sort of coding would I implement for the wheel watcher, in order for Arduino to recognize it and send commands to the servos?

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Servo Programming assistance

Post by adafruit_support_bill »

I haven't used that particular encoder, but they do have an Arduino library and examples for it here: http://www.nubotics.com/products/wc132/software.html

bt1996
 
Posts: 4
Joined: Tue Oct 15, 2013 11:15 pm

Re: Arduino Servo Programming assistance

Post by bt1996 »

If I added an IMU such as the one mentioned, what would the code look like; would I be able to define the wheels to rotate until it goes inches (Code Equivalent) and then turn exact amount of degrees.

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Servo Programming assistance

Post by adafruit_support_bill »

The IMU will be able to give you very direct feedback on orientation via the magnetometer. This will simplify making precise turns. Calculating linear motion from an accelerometer is a bit more complex. The accelerometer will tell you the acceleration rate, and you will need to integrate that over time to determine the distance traveled.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”