Subject:
|
Re: robolab/rcx/scout/send mail command
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Fri, 19 Jan 2001 14:59:16 GMT
|
Original-From:
|
Steve Baker <sjbaker1@airmail.netSPAMLESS>
|
Reply-To:
|
{sjbaker1@airmail.}avoidspam{net}
|
Viewed:
|
650 times
|
| |
| |
digger wrote:
> i have an rxc, a scout and a copy of robolab 2 for macintosh (i don't have
> any instruction books for robolab). i understand that it is possible to send
> commands from the rcx to the scout and receive replys.
Yes. I've been doing that a lot recently...under NQC that is.
> could any one give me a quick start solution to get me going? also, does
> anyone know what the send mail/ receive mail commands in robolab do?
Dunno about robolab.
On either the RCX or the Scout, I've been using:
x = Message() ;
to read a message (x==0 if no message has arrived)
ClearMessage() ;
...to erase the message once I've read it...and:
SendMessage ( message_number ) ;
...to transmit a message. Messages are a single byte - and
since there is no way to distinguish a return of Zero between
a zero message and no message at all, you should avoid sending
zero as a message.
Here are the two programs I'm playing with right now that allow
one RCX to drive THREE Scouts at once. It's not quite finished
yet - but you can drive the scout's motors and read their sensors
from within the RCX.
In each of the three Scouts, run this:
====================================================================
/*
Compile using:
nqc -S/dev/{port} -TScout -DMY_IDENT={id} scout.nqc
Where: {port} - Whichever serial port you use.
{id} - 1, 2 or 3 depending on which Scout you are setting up.
*/
task main ()
{
ClearMessage () ;
while ( true )
{
int msg, bits ;
msg = Message () ;
if ( msg != 0 )
ClearMessage () ;
/*
No need to check for message zero because bits would
be zero - which won't match MY_IDENT
*/
bits = (msg / 64) & 0x03 ;
msg = msg & 0x3F ;
if ( bits == MY_IDENT )
{
SendMessage ( SENSOR_1 +
SENSOR_2 * 2 +
(SENSOR_3+1) * 4 ) ;
bits = msg / 16 ;
/*
0 0 - Command the Scout's motors.
0 1 - Play a sound.
1 0 - Set Motor Power.
1 1 - Set Light threshold, etc.
*/
switch ( bits )
{
case 0 : /* Motor */
/*
0 0 - Off.
0 1 - OnFwd.
1 0 - OnRev.
1 1 - Float.
*/
bits = msg & 0x03 ;
switch ( bits )
{
case 0 : Off ( OUT_A ) ; break ;
case 1 : OnFwd ( OUT_A ) ; break ;
case 2 : OnRev ( OUT_A ) ; break ;
case 3 : Float ( OUT_A ) ; break ;
}
bits = ( msg / 4 ) & 0x03 ;
switch ( bits )
{
case 0 : Off ( OUT_B ) ; break ;
case 1 : OnFwd ( OUT_B ) ; break ;
case 2 : OnRev ( OUT_B ) ; break ;
case 3 : Float ( OUT_B ) ; break ;
}
break ;
case 1 : /* Sound */
break ;
case 2 : /* Motor Power */
SetPower ( OUT_A, (msg & 0x03) * 2 ) ;
SetPower ( OUT_B, (msg & 0x0C) / 2 ) ;
break ;
case 3 : /* Light Threshold */
break ;
}
}
}
}
====================================================================
Then, in the RCX, use this task to deal with talking to the scouts:
====================================================================
/*
Compile using:
nqc -S/dev/{port} -TRCX2 rcx.nqc
Where: {port} - Whichever serial port you use.
*/
#define TIMEOUT 50 /* 500ms */
int sensor [ 9 ] ;
int motor [ 6 ] ;
int motor_power [ 6 ] ;
task scout_comms ()
{
int i ;
int msg ;
while ( true )
{
for ( i = 0 ; i < 3 ; i++ )
{
while ( true )
{
ClearMessage () ;
SetTimer ( 0, 0 ) ;
SendMessage ( (i+1) * 64 +
0 * 16 +
motor[i*2] +
motor[i*2+1] * 4 ) ;
do
{
msg = Message () ;
} while ( FastTimer ( 0 ) < TIMEOUT && msg == 0 ) ;
if ( msg != 0 )
break ;
PlaySound ( SOUND_DOUBLE_BEEP ) ;
}
sensor[i*3 ] = msg & 0x01 ;
sensor[i*3+1] = (msg/2) & 0x01 ;
sensor[i*3+2] = ((msg/4) & 0x03) - 1 ;
}
}
}
========================================================================
The way this works is that your main program zeroes all the elements of
the 'sensor' and 'motor' arrays and then starts the scout_comms task
running. From then on, you can drive any of the six Scout motors or
read any of the nine sensors (including the high order bits of the
light sensor) simply by looking in the 'sensor' array. You can also
set the motor power using the motor_power array. I have plans to
let you drive the Scout's sound and to set the light sensor's threshold...
but that's not implemented yet.
Here is a sample program that makes each Scout motor be controlled by
the corresponding touch sensor:
========================================================================
/*
Compile me with the 'task scout_comms' code
*/
task main ()
{
int i ;
for ( i = 0 ; i < 3 ; i++ )
{
sensor [ i*3 + 0 ] = 0 ;
sensor [ i*3 + 1 ] = 0 ;
sensor [ i*3 + 2 ] = 0 ;
motor [ i*2 + 0 ] = 0 ;
motor [ i*2 + 1 ] = 0 ;
}
start scout_comms ;
Wait ( 100 ) ;
while(true)
{
for ( i = 0 ; i < 3 ; i++ )
{
motor [ i*2 ] = sensor[i*3] ;
motor [ i*2+1 ] = sensor[i*3+1] ;
}
}
}
========================================================================
The RCX will double-beep if one or more of the Scouts is out of IR range...
or doesn't reply for some other reason.
Beware though - the protocol (with three scouts) is pretty slow - it can
take more than a half second for a Scout sensor input to reach the RCX
and a similar amount of time for the response to go back to the Scout to
drive the motor. Since you only have one Scout, you may want to toss all
this stuff and do something much simpler (and faster)...but I'm a sucker
for hard software problems.
Here is the documentation for the protocol I'm using:
========================================================================
Controlling many scouts with one RCX.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The intention here is to allow a large number of Lego 'Scout'
computers to act a slaves to a single Lego 'RCX' - the scouts
will all run the same program - with one variation - a single
constant that gives each one a unique identifier.
The program that runs in the scouts allows motors, light and
sounds to be controlled remotely - and produces sensor returns
from the two sensor inputs and the built-in light sensor. All
of the 'intelligence' in the robot runs in the RCX.
The code at the RCX end is very simple - and subroutines to
drive the scouts is provided.
Protocols.
~~~~~~~~~~
Since IR commands from the RCX will be 'seen' by all of the
scouts - and there is a good chance that one scout may see
the output from another scout, some care has to be taken to
"Address" each message to a particular computer.
A message consists of only a single byte (8 bits):
7 6 5 4 3 2 1 0
[IDENT] [ DATA ]
The top two bits is the destination identifier, the
bottom 6 bits remains for data.
This permits up to four computers to be addressed. One
RCX and up to three Scouts. The RCX is computer ZERO.
The data part of the message has different meanings
for Scout and RCX.
SCOUT-to-RCX.
~~~~~~~~~~~~~
7 6 5 4 3 2 1 0
0 0 X X S3H S3L S2 S1
Since the scout can only read touch-sensors (switches),
we only need one bit for each of SENSOR_1 and SENSOR_2
S3H and S3L are the SENSOR_3 return - which can be:
S3H S3L
0 1 - Low
1 0 - Medium
1 1 - High
The value will never be zero because that could
result in message 0x00 being sent to the RCX - which
is "discouraged".
Bits 4 and 5 are unused - don't rely on them being Zero.
To avoid two scouts transmitting at the same instant
and corrupting each others' data - thus confusing the
RCX, they obey the "Only speak when you are spoken to"
rule. Hence the RCX must talk to each Scout in turn
in order to get data back from them.
RCX-to-SCOUT.
~~~~~~~~~~~~~
There are many things within the scout that can be
controlled from the RCX - motors, sound and light.
Bits 4/5 of the data therefore contains a command code
that is:
0 0 - Command the Scout's motors.
0 1 - Play a sound.
1 0 - Set Motor Power.
1 1 - Set Light threshold, etc.
Motor Command:
~~~~~~~~~~~~~~
Each motor has a 2 bit command code
0 0 - Off.
0 1 - OnFwd.
1 0 - OnRev.
1 1 - Float.
OUT_A is bits 0 and 1, OUT_B is bits 2 and 3.
Sound Command.
~~~~~~~~~~~~~~
To Be Decided.
Set Motor Power.
~~~~~~~~~~~~~~~~
The power level for OUT_A is packed into bits 0,1,2
the level for OUT_B is packed into bits 3,4,5.
Set Lights and Light Threshold.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To Be Decided.
--
Steve Baker HomeEmail: <sjbaker1@airmail.net>
WorkEmail: <sjbaker@link.com>
HomePage : http://web2.airmail.net/sjbaker1
Projects : http://plib.sourceforge.net
http://tuxaqfh.sourceforge.net
http://tuxkart.sourceforge.net
http://prettypoly.sourceforge.net
http://freeglut.sourceforge.net
|
|
Message is in Reply To:
| | robolab/rcx/scout/send mail command
|
| i have an rxc, a scout and a copy of robolab 2 for macintosh (i don't have any instruction books for robolab). i understand that it is possible to send commands from the rcx to the scout and receive replys. could any one give me a quick start (...) (24 years ago, 19-Jan-01, to lugnet.robotics)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in Robotics
|
|
|
|