PDA

View Full Version : converting string to number


drwarne
10-05-01, 05:18 PM
Help!
I am an artist using basic robotics for a show in a few weeks. I have been learning forth for the NMIS-21 & 2-NMIS-L-7056's. I have a C program sending position & velocity strings through the serial port to the board. This data is read by a Forth v3.5 loop which converts the strings to values and sets the motors going. This is working just great, but a little slowly. Right now i can send about 20 strings a second, but i am hoping to get at least 30Hz.

By trial & error i have decided that the slow down is likely the routine i am using to convert the strings to numbers:

: INPUT_FROM_SERIAL ( --- d )
KEY 48 - 1000 * 1000 UM*
KEY 48 - 100 * 1000 UM* D+
KEY 48 - 10 * 1000 UM* D+
KEY 48 - 1000 UM* D+
KEY 48 - 100 UM* D+
KEY 48 - 10 UM* D+
KEY 48 - D+
;

This of course converts "1234567" to 1,234,567.

I have read some documentation about NUMBER, FNUMBER & CONVERT, but i am doing something wrong. It might have to do with the fact that i dont quite get where the input is being addressed. Is this a better/faster approach? Can someone please include some code to help me get going?

Thanks a million,
David

arodrix
10-18-01, 03:47 PM
Hello David -
I can't tell if any one has replied here; this site is extremely slow for me so I cant navigate it easily.

The input of numbers shouldn't be extra slow; I think the limitation would be the 9600 baud serial connection which gives about one character/digit per millisecond. The 6811 should be able to keep up with that rate and receive numbers.

Without spending time to check your routine just now;
consider
KEY 48 -
6 0 DO 10 UM* KEY 48 - 0 D+ LOOP
( or the general idea).

However a preferable way would be to use EXPECT
and CONVERT, which would accept the string with all digits, and convert it to a number. I have to play with
them a bit to give you correct code. I've done some serial input before, but not something I do all the time.

If you think I can help and are still interested, you can reach me at arodrix@weld.com; and if you are pushed to make the show, I can give you an 800 tel no to reach me.

Cheers! - Anil

MLCarter
10-28-01, 05:58 PM
Hello David,
you could cut the number of characters you have to send back to 2 or 3 if you used the whole acsii character set and multiply up by 256. A 2 byte sequence would give numbers up to 256^2.

Bye Mark.

drwarne
10-29-01, 05:49 PM
Thanks to both!
I have to admit that i really didnt think it was the serial connection, but you're right! It does seems to be the slowdown here. And cutting the numbers of digits sent a simple solution. It is working better. Thanks again.