Society of Robots - Robot Forum
Software => Software => Topic started by: brightjoey on April 09, 2012, 01:00:08 PM
-
Hi everyone,
I'm following this tutorial http://www.societyofrobots.com/sensors_encoder.shtml. (http://www.societyofrobots.com/sensors_encoder.shtml.) What I'm trying to implement is having an accurate reading of the distance of my robot.
For example if in my program I want my vehicle to move 10m/s. Since I'm using an optical encoder,pretend it needs about 200ticks per second. and my encoder records 5m/s which is about 100 ticks per second. How do I program Is there any example program where I can use to do this?
-
And I'm not using PWM to +/- speed. I am using roboteq Ax500 motor driver communicating over the RS232 serial port. In order to increase or decrease speed, it understands a formated string of characters such as "!a3F".
where !a stands for left wheel forward and the next two characters are hex.(00 > 0% Speed and 7F stands for 100% speed).
How do I increase the number from 00 --> 7F until the optical encoder records 100ticks, then it stops speed increment.
-
And I'm not using PWM to +/- speed. I am using roboteq Ax500 motor driver communicating over the RS232 serial port. In order to increase or decrease speed, it understands a formated string of characters such as "!a3F".
where !a stands for left wheel forward and the next two characters are hex.(00 > 0% Speed and 7F stands for 100% speed).
How do I increase the number from 00 --> 7F until the optical encoder records 100ticks, then it stops speed increment.
If I understand correctly, you want do do feedback control?
You want to find the commanded speed (between 00 and 7f) that results in a reported speed of 100 ticks per second?
A lot depends on how fast you need to get up to speed and how accurate it needs to be - the simplest code would be something like (and you will have to format it for whatever language you are using):
speed_gain = .01; /* you will have to play with this number to get it to work
nicely too big and it will oscillate - make big changes like factors of ten to start
with as you try to find the right value*/
target_speed = 100;
speed_error = reported_speed - target_speed; /* this needs to be a signed
number a positive value means you are going too fast */
commanded_motor = commanded_motor - (speed_gain * speed_error);
/* you are going to have to deal with converting back and forth to hex -
you could have commanded_motor be in decimal and then write it to a
hex variable before you send it out */
/* you need to clip commanded_motor here also to avoid it going out of range */
This is essentially a simple integral controller.