It is currently Tue May 21, 2013 12:56 pm
       


All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Odometre Readings
PostPosted: Wed Jan 18, 2006 3:40 pm 
Offline
arexx.com user

Joined: Fri Jan 06, 2006 3:42 pm
Posts: 7
I have been trying to get information from asuro about how far it has moved.

I'm not sure what information is returned from

unsigned int data[2]; //Allocate memory . .
OdometrieData(data);

Could I do this:

SerWrite (data[2], 10);

I am assuming that the OdometrieData(data); function converts information recevied by the light sensors near the wheels into a numeric value from 0 to 1024 ?

Basically, I want to measure distance and I though I could count the number of times the light sensors pick up a white segment on the cog. Is that how to do it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 10:28 pm 
Offline
arexx.com user

Joined: Fri Jan 06, 2006 3:42 pm
Posts: 7
OdometrieData(data);
if(data[1]<data[2]){
counter++;
SerWrite("count \n", 6);
}else{
SerWrite("no count \n", 9);
}

if(counter < 30){
MotorDir(RWD,RWD);
MotorSpeed(120,180);
}else{
back=0;
}

}

[/code]

Basically, after 30 black segments pass the photosensors, stop going backwards. (this is just a code snippet)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 5:31 pm 
Offline
Administrator
User avatar

Joined: Fri Mar 25, 2005 6:19 pm
Posts: 1378
Location: NRW
Code:
PSEUDO CODE:

unsigned int data[2];
OdometrieData(data);
if(data[0] > xxx) ....
if(data[1] > xxx)...


You have to start counting at ZERO - not one!

unsigned int data[2]; is an array of two integer values, which store left and right encoder value. (Not a counter of segments, but the current phototransistor value)
Counting must be done by the programmer.

THIS IS ALL MENTIONED IN THE MANUAL!


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 10:27 am 
I have read this in the manual, and I understand that I have to count the segments to get the distance.

What I am unsure about is what value is held by data[0] and data[1]. I thought it was an integer from 0 to 1024 as that is the range of the photo sensors, but if I SerWrite(data[1], 10); It just comes out as random characters.

That is why I am confused.

Thanks for pointing out my mistake with using [2] instead of [1]!

I will try again, and post my code with the results.


Top
  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 10:28 am 
Offline
arexx.com user

Joined: Fri Jan 06, 2006 3:42 pm
Posts: 7
forgot to log in!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 2:42 pm 
Offline
Administrator
User avatar

Joined: Fri Mar 25, 2005 6:19 pm
Posts: 1378
Location: NRW
> It just comes out as random characters


Of course, beause you transfer BYTES with serwrite (more excactly the datatype 'char'! )! And each of the byte is interpreted as ASCII Character! It does not automatically convert it to a Number - If you want Numbers, you have to convert it to ASCII characters like 48 (='0'), 49 (='1'), 50 (='2') etc. and write the bytes e.g. 49-50-48 for a Number of '120'...


What serwrite does is actually transferring an array of bytes through the serial interface to the PC. The PC thinks that each byte is a character........


If you want to send Numbers to the PC, you have to convert the integers and then you can transfer them. (or simply use a Terminal software that shows you the byte values and not the character interpretation!)


Oh - forgot: An 'int' consists of TWO bytes!
A 'char' is ONE byte... and it can be signed or unsigned!


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 4:25 pm 
Offline
arexx.com user

Joined: Fri Jan 06, 2006 3:42 pm
Posts: 7
I am a c++ novice, I only know php (the closest thing I have to a programming background)...

How do you convert bytes to ascii to a meaningful number in hyperterminal ?

I have found http://www.hektra.nl/info/asci.html but can't find a function that will convert to them.

So, when the Asuro manual says that the photo sensors output a range from 0 to 1024 this means bytes.

thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 5:01 pm 
Offline
Administrator
User avatar

Joined: Fri Mar 25, 2005 6:19 pm
Posts: 1378
Location: NRW
> this means bytes.

no not bytes, 'int's = TWO bytes!
A byte is 0 to 255 and two bytes are 0 to 65535
for unsigned
and -128 to 127 and -32768 to 32767 for signed.

I usually use PICs, so no guarantee that this is correct, but you can do it LIKE this (you have to change varnames etc. I did not test this code) :


Code:

//You have to include stdlib at top of the source file:
#include <stdlib.h>
//[...]

unsigned char text[5];
itoa(data[0],text,10);  // converts an integer into ascii...
// 10 is the radix of the number,
// 2 for binary, 10 for decimal, 16 for hexadecimal etc.
//...
SerWrite(text,5);



Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 5:09 pm 
Offline
arexx.com user

Joined: Fri Jan 06, 2006 3:42 pm
Posts: 7
I understand. I will try this later. Iwas reading something earlier http://www.cplusplus.com/ref/cstdlib/itoa.html but didn't understand it, now you have used it I will look into it further.

Thanks,
Ed


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group