PDA

View Full Version : problem in using SCI0 for reciveing data


frontech
08-25-04, 12:10 AM
i want to use SCI0 for reciveing bytes from system running on linux, i wrote my program but found that isopod was missing bytes and not reciveing packets correctly.
to test if isopod is reciveing bytes correctly, i wrote another code for testing this, which is given below:-


: SETBAUD DECIMAL 9600 SCI0 BAUD ; EEWORD


HERE 80 4 + ALLOT CONSTANT RBUFF0 EEWORD


HERE 80 4 + ALLOT CONSTANT TBUFF0 EEWORD
RBUFF0 80 4 + SCI0 RXBUFFER
TBUFF0 80 4 + SCI0 TXBUFFER

VARIABLE MACH1 EEWORD

( MONE has only one state, it checks for data if available on
( serial port and than reads it and print GOT

MACHINE MONE EEWORD
ON-MACHINE MONE
APPEND-STATE M1 EEWORD
IN-STATE M1
CONDITION SCI0 RX?
CAUSES
SCI0 RX MACH1 !
." GOT "
GRNLED ON REDLED OFF YELLED OFF
THEN-STATE M1 TO-HAPPEN IN-EE

: STARTUP
ISOMAX-START
SETBAUD
DECIMAL 10 PERIOD
M1 SET-STATE
INSTALL MONE


; EEWORD


STARTUP





i tested above code from NMITerm .
above code recives bytes from SCI0 and prints "GOT" on console.

what i found was if make PERIOD more than 10 ,then when i press key on my system not always "GOT" is printed , the character i entered is printed.
i think that the foreground process reads it instead of my code. so should i use SCI1 instead of SCI0 or i am doing some mistake somewhere else.

thanks:o

RMDumse
08-25-04, 04:31 PM
Yes, you are likely correct. If you use SCI0 for communications task, and the outer interpreter of the language is running as well, they will compete got get characters out of the input buffers.

So, you can either tie up the foreground with some never ending loop, that does not attempt to take characters from the serial channel, or you can use the other serial channel for your input, and so you separate buffers for each recieveing task.

frontech
08-26-04, 07:14 AM
thanx for the reply,

[So, you can either tie up the foreground with some never ending loop, that does not attempt to take characters from the serial channel]

i am not able to think of how to tie foreground process into never ending loop, can you suggest some method to do this.
using other serial port is not feasible for me.

RMDumse
08-26-04, 09:23 AM
The object is just to give the foreground something to do that will not let it look for operator inputs. But! Sometimes, and certainly durring development, you want to get the foreground back. So the thing to do is give it a Program Counter Capture Loop that you can terminate at will. So perhaps we could pick some port line, and let it look at it to go low, and not come out of the loop until it does.

: HANG BEGIN PA0 OFF? UNTIL ;

Or use any other resource you can signal the end of the loop.

xar
09-14-04, 07:02 PM
Randy,
how much overhead will be added using such a loop?
I am running with the same problem here.

I need to give commands to the 'pod, while isomax is still running.


Is there a way to tell Isomax to stop fetching chars from the serial?

I don't mind resetting it to regain control.

TIA,

Giuseppe Marullo

RMDumse
09-14-04, 08:09 PM
Originally posted by xar
how much overhead will be added using such a loop?

Essentially, such a loop is 100% overhead.

The purpose of the loop is to waste the waste cycles.

All the cycles that are left over from the scheduled run are given to the foreground task of talking to the operator, and if you want the serial channel for some other purpose, you need to tie the foreground up with something else to do, something that will take all the cycles left over, and apply them to something other than talking to the operator. If the foreground is allowed to talk to the operator, the foreground will occassionally "steal" a character from the serial channel intended for the background IsoMax(TM) tasks.

So it's all the better if you have some useful task that can be done in the foreground loop without giving control back to the interpreter of the language. But! if there's nothing for the foreground to do, then no problem, waste the waste cycles.

I am running with the same problem here. I need to give commands to the 'pod, while isomax is still running.

In general, this is no problem. In fact, it is the beauty of the inherently multitasking scheme of IsoMax(TM) that you can put so much into the background, and still have time left over in the foreground to talk to the 'Pod. The problem comes when you are trying to use the "system console" serial channel for some purpose other than the "system console".

Is there a way to tell Isomax to stop fetching chars from the serial?

Ideally, we should be able to revector the system console to some other communications path, but the latest version has not had this added, so the SCI0 is the only communications port built into the language interpreter.

Now, one idea might to be to write another interpreter. That's not as tough or daunting as it might first sound. Basically the language itself has a loop that does QUERY INTERPRET. QUERY gets a line of characters, and INTERPRET translates the characters. Write a different QUERY, call it QUERYNEW here for example, and then make a new loop with QUERYNEW INTERPRET in it, and you would move the language from SCI0 to another form of communications.

But you have to ask, how would you like to communicate with it, if not by a serial port? The SPI might be an example, but PC's don't have SPI's. The CANBus might be an example, but PC's usually don't have CANBus. On parallel ports might be a real possibility, and PC's do have those.

But before I go too far down that road, why don't you tell me more about your needs, and maybe we can work toward them.

xar
09-15-04, 09:50 AM
Hi Randy,
I need to give to the Isopod commands while 3 vmachines are running in parallel.
One machine computes X,Y and theta of the robot, another one compute and execute the trajectory.

The third one waits for commands from the serial port, and changes the state of the second.

It waits for a packet of data, parse it and it should keep monitoring the serial port while the robot is moving.

I would like something like using a C program, where the stdin is redirected to the program while it is running.

I don't care if IsoMax can't regain the serial port, ideally the program never stops.


As a workaround, I am thinking to define very short words, and use the serial port to start the commands.
Something like this:

Define a 'F' Forth word for forward commmand. It will get from the stack the distance to travel forward.
So to make the robot go forward for 1 meter (1000mm):

1000<blank>F<cr>

Should fire the F word. Inside F I will get the parameter from the stack and change the statuses I need to start the robot.

Should I need to stop the robot, I could define a 'S' word that will shut down motors, etc. etc.

Not ideal (I cannot compress the command, it must be forth friendly) but it should work.

I don't want to mess with I2C and other things, just plain old serial (starting up at 38400, thanks to Chris).

Giuseppe Marullo

Isopod is going to be bluetoothed this evening...

RMDumse
09-15-04, 02:46 PM
Originally posted by xar
I need to give to the Isopod commands while 3 vmachines are running in parallel. ...

The third one waits for commands from the serial port, and changes the state of the second.

Ah. That is a bit different than I'd envisioned.

I'd like to make a suggestion. Put the two machines in the Schedule run. The third machine, just run in the foreground, in place of the normal interpreter.

I don't care if IsoMax can't regain the serial port, ideally the program never stops.

Well, generally what I do in situations like that is to have my start up word set up, start the scheduled run in the background, then go into a loop handling the serial channel. I put a back door into the serial channel that allows it to escape if I want out, and then it falls through the end of the definition, and into the language interpreter, where I can talk to it in the language, or even say its name and go back into the command mode.

As a workaround, I am thinking to define very short words, and use the serial port to start the commands.
...
Not ideal (I cannot compress the command, it must be forth friendly) but it should work.


They don't have to be short words either, unless you're concerned about speed.

I'll let you in on a neat trick. If you zero out the link in the Forth language, you can close the dictionary, and only the words you define will be there. That way, you can take away the rest of the language, and only leave the words in the dictionary you want to have as a final command set.

I'll see if I can't work up a short example on this.

Isopod is going to be bluetoothed this evening...

Exciting news!

RMDumse
09-15-04, 03:53 PM
Here's an example to look at. This uses a closed loop to look for specific characters, and do certain functions. Most of the example is simply a "Twinkle" set of state machines, each with two states, which turn on and off the GRN and RED Led's. These are set into the background task.

In the foreground, COMMAND-LOOP captures and holds the system program counter. Any waste cycles left over from the background task are used here looking at the serial channel for characters, and if there are any, comparing them to fixed values, and with a match, taking a specific action.

In this case, the 0 key keeps the GRN led state machine from timing out by reseting its counter. So the 0 key can hold off a transition from off to on, or on to off. When it is sent, the system resets the counter controlling the state transitions.

Similarly, the 1 key keeps the RED led state machine from timing out by reseting its counter. So the 1 key can hold off a transition from off to on, or on to off. When it is sent, the system resets the counter controlling the state transitions.

Repeatedly pressing the 0 or 1 key can hold off the advancement of one or the other LED's flashing, and so, the phase between the two LED's can be adjusted as desired.

The final thing the COMMAND-LOOP does is looks for a carridge return, as a back door out of the loop. When a <CR> is detected, the loop stops running and the outer interpreter of the language is entered, and then any desired Forth command can be run.

Notice the background twinkling continues to go on, even if the COMMAND-LOOP exits. Also notice, to go back into the COMMAND-LOOP after exiting and doing whatever one might, one simply re-enters COMMAND-LOOP, and control via the 0 and 1 is again active. Also note the Yellow LED will be toggled while the COMMAND-LOOP is running, but it is either all on, or all off when out of the loop.

This is an example of the loop that takes over the foreground. The interpreter does not run while this loop holds the foreground. The only "commands" that work in the loop are those specifically programmed to do so by the loop itself. Outside the loop, all of the language is again available. Inside the loop, only the keys programmed to have action can make any changes.



[CODE]
SCRUB


HERE 80 4 + ALLOT CONSTANT RBUFF0 EEWORD ( buffers for interrupt serial
HERE 80 4 + ALLOT CONSTANT TBUFF0 EEWORD ( buffers for interrupt serial

LOOPINDEX G-CNT ( timer for green twinkle timing
100 G-CNT END EEWORD

LOOPINDEX R-CNT ( timer for red twinkle timing
100 R-CNT END EEWORD


MACHINE G-TWINKLE EEWORD
ON-MACHINE G-TWINKLE
APPEND-STATE G-ON EEWORD
APPEND-STATE G-OFF EEWORD

IN-STATE
G-ON
CONDITION
G-CNT COUNT
CAUSES
G-CNT RESET
GRNLED OFF
THEN-STATE
G-OFF
TO-HAPPEN IN-EE


IN-STATE
G-OFF
CONDITION
G-CNT COUNT
CAUSES
G-CNT RESET
GRNLED ON
THEN-STATE
G-ON
TO-HAPPEN IN-EE


MACHINE R-TWINKLE EEWORD
ON-MACHINE R-TWINKLE
APPEND-STATE R-ON EEWORD
APPEND-STATE R-OFF EEWORD

IN-STATE
R-ON
CONDITION
R-CNT COUNT
CAUSES
REDLED OFF
R-CNT RESET
THEN-STATE
R-OFF
TO-HAPPEN IN-EE


IN-STATE
R-OFF
CONDITION
R-CNT COUNT
CAUSES
REDLED ON
R-CNT RESET
THEN-STATE
R-ON
TO-HAPPEN IN-EE


MACHINE-CHAIN TWINKLE
G-TWINKLE
R-TWINKLE
END-MACHINE-CHAIN EEWORD



: COMMAND-LOOP
BEGIN
YELLED TOGGLE
SCI0 RX? IF RX ELSE 0 THEN
DUP 48 = IF G-CNT RESET THEN ( ASCI "0" HOLDS TIME OUT FROM GRN
DUP 49 = IF R-CNT RESET THEN ( ASCI "1" HOLDS TIME OUT FROM RED
13 = ( ASCI <cr> BACK DOOR OUT OF LOOP
UNTIL
; EEWORD

: STARTUP
( 38400 SCI0 BAUD
RBUFF0 80 4 + SCI0 RXBUFFER
TBUFF0 80 4 + SCI0 TXBUFFER
G-CNT RESET
R-CNT RESET
G-ON SET-STATE
R-ON SET-STATE
EVERY 50000 CYCLES SCHEDULE-RUNS TWINKLE
COMMAND-LOOP
; EEWORD

HEX 3C00 DECIMAL AUTOSTART STARTUP ( V.6 VERSION OF AUTOSTART
( AUTOSTART STARTUP ( V.7 VERSION OF AUTOSTART
SAVE-RAM
[\CODE]

RMDumse
09-15-04, 04:17 PM
Here's another example. This is taken from the work Mike Keesling did on the Lynxmotion L6 arm. I won't repeat the whole program, but just the part after the machine chains are defined.




( ******************* THE MACHINE CHAIN
MACHINE-CHAIN ARM-CHAIN
VELMOVE
RCVR
END-MACHINE-CHAIN EEWORD


: ERASEPROG SCRUB ; EEWORD
: WORDS WORDS ; EEWORD
: ? ? ; EEWORD 10 SPACES ( THIS HELPS DOWNLOADER SYNC
: F? F? ; EEWORD
: STORE ! ; EEWORD
: FSTORE F! ; EEWORD

: RIGHT RIGHT ; EEWORD
: LEFT LEFT ; EEWORD
: RBASE RBASE ; EEWORD
: SHLDR SHLDR ; EEWORD
: ELBOW ELBOW ; EEWORD
: WRIST WRIST ; EEWORD
: RGRIP RGRIP ; EEWORD
: GRIP GRIP ; EEWORD
: CMDDEG CMDDEG ; EEWORD
: CMDPOS CMDPOS ; EEWORD
: CMDVEL CMDVEL ; EEWORD
: CMDACC CMDACC ; EEWORD
: CURPOS CURPOS ; EEWORD
: CURVEL CURVEL ; EEWORD
: CURACC CURACC ; EEWORD
: DECCNT DECCNT ; EEWORD

: FIWRIST FIWRIST ; EEWORD
: FIHEIGHT FIHEIGHT ; EEWORD
: FIRADIUS FIRADIUS ; EEWORD
: FOWRIST FOWRIST ; EEWORD

: MAKEALL MAKEALL ; EEWORD
: DO-IK DO-IK ; EEWORD
: FOFINALHEIGHT FOFINALHEIGHT ; EEWORD
: FOFINALRADIUS FOFINALHEIGHT ; EEWORD
: IK-ERROR IK-ERROR ; EEWORD

: MAIN
INIT-IK
INIT-RC
INIT-SER
MBUFF 80 ERASE
0 MBUFFX !
0 RXCHAR !
AWAIT-ADDR SET-STATE
CR ." L6 Arm Command Language" CR
EVERY 50000 CYCLES SCHEDULE-RUNS ARM-CHAIN
; EEWORD



( 0 ' ERASEPROG LFA PF! ( CLOSE THE DICTIONARY LINKAGE BELOW SCRUB
NO-CONTEXT

( HEX 7C00 DECIMAL AUTOSTART MAIN ( V0.1 - V0.5
HEX 3C00 DECIMAL AUTOSTART MAIN ( V0.6 -

SAVE-RAM




What happens here is a select group of words are redefined to have new names. ERASEPROG is a renamed version of SCRUB, so even in this language, if you want to get rid of everything and start over fresh, you can. Anyway, ERASEPROG is the first word of the new language. By popping its LFA to 0, the dictionary is terminated, then the board still translates everything that comes in, but it only knows numbers, and the words between ERASEPROG and MAIN. This is a way of making a closed dictionary, and using the full interpreter that is already in the language, without have to write your own command loop, and making all the parsing words, etc.

Uncommenting the

( 0 ' ERASEPROG LFA PF!

will seal the dictionary to remember only words that come after ERASEPROG.

xar
09-28-04, 07:27 PM
Randy,
sorry for the delay, I wanted to fix the bluetooth stuff first.

Actually the connection works well (transparent!), but I need to test it more.

About your suggestions, I think using simple forth words could be the easiest way to make the thing 'walk', then I will surely try some of your suggesitions (even if they are too high level for me).

The pc gives the desired motion to the isopod, and while the robot is moving each one could decide to come to a stop.

For example, if a bumper triggers, the isopod will perform some sort of emergency stop.

The pc too could decide to change its mind while the robot is moving, so I must be sure that any pc request is processed promptly (or better said I cannot rely on what is left from the other tasks).

I don't have any *special* speed requirement, surely the shortest the complete string, the higher the command rate.

I am planning an external watchdog too, that will guard against the most common problems.

Giuseppe Marullo