Author Topic: Optical Encoder and hex character conversion help.  (Read 768 times)

0 Members and 1 Guest are viewing this topic.

Offline brightjoeyTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Optical Encoder and hex character conversion help.
« on: April 09, 2012, 01:00:08 PM »
Hi everyone,

I'm following this tutorial 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?



Offline brightjoeyTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Optical Encoder and hex character conversion help.
« Reply #1 on: April 09, 2012, 01:04:20 PM »
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.

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 269
  • Helpful? 12
Re: Optical Encoder and hex character conversion help.
« Reply #2 on: April 10, 2012, 07:18:17 AM »
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):

Code: [Select]
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.
« Last Edit: April 10, 2012, 07:21:33 AM by jkerns »
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

 


Get Your Ad Here

data_list