soar.robot.arcos¶
ARCOS (Advanced Robot Control and Operations Software) Client.
Classes and functions for communicating with an ARCOS server running on an Adept MobileRobot platform (typically Pioneer 2 and 3).
-
soar.robot.arcos.
ADSEL
= 35¶ Select the A/D port number for reporting ANPORT value in standard SIP.
-
class
soar.robot.arcos.
ARCOSClient
(timeout=1.0, write_timeout=1.0, allowed_timeouts=2)¶ Bases:
object
An ARCOS Client communicating over a serial port with an ARCOS server.
Parameters: - timeout (float) – The time to wait while receiving data before a timeout occurs, in seconds.
- write_timeout (float) – The time to wait while sending data before a timeout occurs, in seconds.
- allowed_timeouts (int) – The number of timeouts to tolerate before the update coroutine closes the port.
-
standard
¶ dict – The last standard Server Information Packet (SIP) received, or
None
, if one hasn’t been received yet.
-
config
¶ dict – The last CONFIGpac SIP received, or
None
, if one hasn’t been received yet.
-
encoder
¶ dict – The last ENCODERpac SIP received, or
None
, if one hasn’t been received yet.
-
io
¶ dict – The last IOpac SIP received, or
None
, if one hasn’t been received yet.
-
standard_event
¶ threading.Event
– Set whenever a standard SIP is received.
-
config_event
¶ threading.Event
– Set whenever a CONFIGpac SIP is received.
-
encoder_event
¶ threading.Event
– Set whenever an ENCODERpac SIP is received.
-
io_event
¶ threading.Event
– Set whenever an IOpac is received.
-
sonars
¶ list – A list of the latest sonar array values, updated whenever a standard SIP is received.
-
connect
(forced_ports=None)¶ Attempt to connect and sync with an ARCOS server over a serial port.
Returns if successful.
Parameters: forced_ports (list, optional) – If provided, a list of serial ports to try connecting to. Otherwise, the client will try all available ports. Raises: ARCOSError
– If unable to connect to any available ports.
-
disconnect
()¶ Stop the ARCOS server and close the connection if running.
-
pulse
()¶ Continually send the PULSE command so that the robot knows the client is alive.
-
receive_packet
()¶ Read an entire ARCOS Packet from an open port, including header and checksum bytes.
Returns: The entire packet as a list of bytes, including header and checksum bytes.
Return type: list
Raises: Timeout
– If at any point a timeout occurs and fewer bytes than expected are read.InvalidPacket
– If the packet header, checksum, or packet length are invalid.ARCOSError
– If something went wrong reading from the serial port.
-
send_command
(code, data=None, append_null=True)¶ Send a command and data to the ARCOS server.
Parameters: - code – The command code. Must be in
soar.robot.arcos.command_types
. - data (optional) – The associated command argument, assumed to be of the correct type.
For commands that take a string argument, a
bytes
object may also be used. - append_null (optional) – If
True
, append a null byte to anystr
orbytes
object passed as a command argument.
Raises: Timeout
– If the write timeout of the port was exceeded.ARCOSError
– If an error occurred writing to the serial port.
- code – The command code. Must be in
-
send_packet
(*data)¶ Send arbitrary data to the ARCOS server.
Adds the packet header and checksum. Thread-safe.
Parameters: *data – A tuple or iterable of bytes, whose values are assumed to be between 0 and 255, inclusive.
Raises: Timeout
– If the write timeout of the serial port was exceeded.ARCOSError
– If something went wrong writing to the serial port.
-
start
()¶ Open the ARCOS servers, enable the sonars, and start the pulse & update coroutines.
-
sync
(tries=4)¶ Try to sync with an ARCOS server connected over an open serial port.
Returns the raw robot identifying information packet sent after
SYNC2
if successful.Parameters: tries (int, optional) – The number of failures to tolerate before timing out. Raises: Timeout
– If the number of tries is exhausted and syncing was not completed.
-
update
()¶ Continually receive and decode packets, storing them as attributes and triggering events.
-
static
wait_or_timeout
(event, timeout=1.0, timeout_msg='')¶ Wait for an event to occur, with an optional timeout and message.
Parameters: - event (Event) – The event to wait for. Expected to be one of the attribute events of this class.
- timeout (float, optional) – How long to wait for the event before timing out.
- timeout_msg (str) – The message to pass if a timeout occurs.
Raises: Timeout
– If the event has not occurred by the specified time.
-
exception
soar.robot.arcos.
ARCOSError
¶ Bases:
soar.errors.SoarIOError
Umbrella class for ARCOS-related exceptions.
-
soar.robot.arcos.
BUMPSTALL
= 44¶ Stall robot if no (0), only front (1), only rear (2), or either (3) bumpers make contact.
-
soar.robot.arcos.
CLOSE
= 2¶ Close servers and client connection. Also stops the robot.
-
soar.robot.arcos.
CONFIG
= 18¶ Request a configuration SIP.
-
soar.robot.arcos.
DCHEAD
= 22¶ Adjust heading relative to last setpoint; +- degrees (+ is counterclockwise).
-
soar.robot.arcos.
DHEAD
= 13¶ Turn at
SETRV
speed relative to current heading; (+) counterclockwise or (-) clockwise degrees.
-
soar.robot.arcos.
DIGOUT
= 30¶ Set (1) or reset (0) user output ports. High bits 8-15 is a byte mask that selects the ports to change; low bits 0-7 set (1) or reset (0) the selected port(s).
-
soar.robot.arcos.
ENABLE
= 4¶ Enable the motors, if argument is 1, or disable them if it is 0.
-
soar.robot.arcos.
ENCODER
= 19¶ Request a single (1), a continuous stream (>1), or stop (0) encoder SIPS.
-
soar.robot.arcos.
E_STOP
= 55¶ Emergency stop. Overrides acceleration, so is very abrupt.
-
soar.robot.arcos.
HEAD
= 12¶ Turn at
SETRV
speed to absolute heading; +-degrees (+ is counterclockwise).
-
soar.robot.arcos.
IOREQUEST
= 40¶ Request a single (1), a continuous stream (>1), or stop (0) IO SIPS.
-
exception
soar.robot.arcos.
InvalidPacket
¶ Bases:
soar.robot.arcos.ARCOSError
Raised when a packet’s checksum is incorrect.
-
soar.robot.arcos.
MOVE
= 8¶ Translate forward (+) or backward (-) mm absolute distance at
SETV
speed.
-
soar.robot.arcos.
OPEN
= 1¶ Start the ARCOS servers.
-
soar.robot.arcos.
POLLING
= 3¶ Change sonar polling sequence. Argument is a string consisting of sonar numbers 1-32 (as single bytes).
-
soar.robot.arcos.
PULSE
= 0¶ Reset server watchdog (typically sent every second so that the robot knows the client is alive).
-
soar.robot.arcos.
ROTATE
= 9¶ Rotate counter- (+) or clockwise (-) degrees/sec at
SETRV
limited speed.
-
soar.robot.arcos.
RVEL
= 21¶ Rotate (degrees/sec) counterclockwise (+) or clockwise (-). Limited by
SETRV
.
-
soar.robot.arcos.
SAY
= 15¶ Play up to 20 duration, tone sound pairs through User Control panel piezo speaker. The argument is a string whose first byte must be the number of (duration, tone) pairs to play, followed by each (duration, tone) pair. Duration is in 20 millisecond increments. A value of 0 means silence. The values 1-127 are the corresponding MIDI notes, with 60 being middle C. The remaining values are frequencies computed as
(tone - 127)*32
, ranging from 1-4096 in 32Hz increments.
-
soar.robot.arcos.
SETA
= 5¶ Set translation acceleration, if positive, or deceleration, if negative, in mm/sec^2.
-
soar.robot.arcos.
SETO
= 7¶ Reset local odometry position to the origin
(0, 0, 0)
.
-
soar.robot.arcos.
SETRA
= 23¶ Change rotation (+) acceleration or (-) deceleration in degrees/sec^2
-
soar.robot.arcos.
SETRV
= 10¶ Set maximum rotation velocity in degrees/sec. Note that the robot is still limited by the hardware cap.
-
soar.robot.arcos.
SETV
= 6¶ Set maximum translational velocity in mm/sec. Note that the robot is still limited by the hardware cap.
-
soar.robot.arcos.
SONAR
= 28¶ 1=enable, 0=disable all the sonar; otherwise bits 1-3 specify an array from 1-4 to enable/disable.
-
soar.robot.arcos.
SONARCYCLE
= 48¶ Change the sonar cycle time, in milliseconds.
-
soar.robot.arcos.
SOUNDTOG
= 92¶ Mute (0) or enable (1) the user control piezo speaker.
-
soar.robot.arcos.
STOP
= 29¶ Stop the robot without disabling the motors.
-
soar.robot.arcos.
SYNC0
= 0¶ The initial synchronization packet.
-
soar.robot.arcos.
SYNC1
= 1¶ The second synchronization packet.
-
exception
soar.robot.arcos.
Timeout
¶ Bases:
soar.robot.arcos.ARCOSError
Raised when no packet is read after a certain interval.
-
soar.robot.arcos.
VEL2
= 32¶ Set independent wheel velocities; bits 0-7 for right wheel, bits 8-15 for left in 20mm/sec increments.
-
soar.robot.arcos.
command_types
= {0: None, 1: None, 2: None, 3: <class 'str'>, 4: <class 'int'>, 5: <class 'int'>, 6: <class 'int'>, 7: None, 8: <class 'int'>, 9: <class 'int'>, 10: <class 'int'>, 11: <class 'int'>, 12: <class 'int'>, 13: <class 'int'>, 15: <class 'str'>, 18: None, 19: <class 'int'>, 21: <class 'int'>, 22: <class 'int'>, 23: <class 'int'>, 28: <class 'int'>, 29: None, 30: <class 'int'>, 32: <class 'int'>, 35: <class 'int'>, 40: <class 'int'>, 44: <class 'int'>, 48: <class 'int'>, 55: None, 92: <class 'int'>}¶ The argument type of every supported ARCOS command.
-
soar.robot.arcos.
decode_packet
(packet)¶ Decode a SIP (Server Information Packet) into a field-indexable dictionary.
Returns: A dictionary with field names as keys and values as corresponding numbers. The 'TYPE'
key holds a value of'STANDARD'
,'CONFIG'
,'ENCODER'
, or'IO'
, corresponding to the packet type.Return type: dict Raises: InvalidPacket
– If a packet’s fields could not be decoded.
-
soar.robot.arcos.
packet_checksum
(data)¶ Calculate and returns the ARCOS packet checksum of a packet which does not have one.
Parameters: data (list) – A list of data bytes. Returns: The packet checksum. Return type: int