soar.robot.pioneer¶
A PioneerRobot class, for representing a real or simulated Pioneer 3 robot.
See the MobileRobots documentation for more information.
-
class
soar.robot.pioneer.
PioneerRobot
(**options)¶ Bases:
soar.robot.base.BaseRobot
-
SONAR_MAX
= 1.5¶ An abstract, universal Pioneer 3 robot. Instances of this class can be fully simulated, or used to communicate with an actual Pioneer3 robot over a serial port.
-
type
¶ str – Always
'Pioneer3'
; used to identify this robot type.
-
simulated
¶ bool – If
True
, the robot is being simulated. Otherwise it should be assumed to be real.
-
pose
¶ An instance of
soar.sim.geometry.Pose
representing the robot’s(x, y, theta)
position. In simulation, this is the actual position; on a real robot this is based on information from the encoders.
-
world
¶ An instance of
soar.sim.world.World
or a subclass, orNone
, if the robot is real.
-
FV_CAP
¶ float – The maximum translational velocity at which the robot can move, in meters/second.
-
RV_CAP
¶ float – The maximum rotational velocity at which the robot can move, in radians/second.
-
SONAR_MAX
float – The maximum distance that the sonars can sense, in meters.
-
arcos
¶ An instance of
soar.robot.arcos.ARCOSClient
if the robot is real and has been loaded, otherwiseNone
.
-
serial_device
¶ str – The device name of the serial port the robot is connected to, if it is real and has been been loaded, otherwise
None
.
Parameters: **options – See set_robot_options
.-
-
analogs
¶ Get the robot’s 4 analog inputs, so long as it is real and not simulated, as a 4 tuple.
-
delete
(canvas)¶ Delete the robot from a canvas.
Parameters: canvas – An instance of soar.gui.canvas.SoarCanvas
.
-
draw
(canvas)¶ Draw the robot on a canvas.
Canvas items are preserved. If drawn more than once on the same canvas, the item will be moved and not redrawn.
Parameters: canvas – An instance of soar.gui.canvas.SoarCanvas
.
-
fv
¶ float
The robot’s current translational velocity, in meters/second.Positive values indicate movement towards the front of the robot, and negative values indicate movement towards the back.
Setting the robot’s forward velocity is always subject to
soar.robot.pioneer.PioneerRobot.FV_CAP
. On a real robot, this is further limited by the hardware translational velocity cap.
-
get_distance_left
()¶ Get the perpendicular distance to the left of the robot.
Returns: The perpendicular distance to the left of the robot, assuming there is a linear surface. Return type: float
-
get_distance_left_and_angle
()¶ Get the perpendicular distance and angle to a surface on the left.
Returns: (d, a)
whered
is the perpendicular distance to a surface on the left, assuming it is linear, anda
is the angle to that surface.
-
get_distance_right
()¶ Get the perpendicular distance to the right of the robot.
Returns: The perpendicular distance to the right of the robot, assuming there is a linear surface. Return type: float
-
get_distance_right_and_angle
()¶ Get the perpendicular distance and angle to a surface on the right.
Returns: (d, a)
whered
is the perpendicular distance to a surface on the right, assuming it is linear, anda
is the angle to that surface.
-
on_load
()¶ Called when the controller of the robot is loaded.
The behavior of this method should differ depending on the value of
simulated
; if it isFalse
, this method should be used to connect with the real robot. If a connection error occurs, asoar.errors.SoarIOError
should be raised to notify the client that the error was not due to other causes.
-
on_shutdown
()¶ Called when the controller of the robot is shutdown.
If interacting with a real robot, the connection should be safely closed and reset for any later connections.
-
on_start
()¶ Called when the controller of the robot is started.
This method will always be called by the controller at most once per controller session, before the first step.
-
on_step
(duration)¶ Called when the controller of the robot undergoes a single step of a specified duration.
For BaseRobot, this tries to perform an integrated position update based on the forward and rotational velocities. If the robot cannot move to the new position because there is an object in its way, it will be moved to a safe space just before it would have collided.
Subclasses will typically have more complex
on_step()
methods, usually with behavior for stepping non-simulated robots.Parameters: step_duration (float) – The duration of the step, in seconds.
-
on_stop
()¶ Called when the controller of the robot is stopped.
-
play_notes
(note_string, bpm=120, sync=False, _force_new_thread=True)¶ Play a string of musical notes through the robot’s piezoelectric speaker.
Parameters: - note_string (str) – A space-delimited list of notes. Notes should all be in the form
n/m(name)[#|b][octave]
. Ex:'1/4C'
produces a quarter note middle C.'1/8A#7'
produces an eighth note A# in the 7th MIDI octave.'1/4-'
produces a quarter rest. All of the MIDI notes in the range 1-127 can be played. - bpm (int) – The beats per minute or tempo at which to play the notes.
- sync (bool) – By default
False
, this determines whether notes are sent one by one, with synchronization performed by the function itself, or all at once. - force_new_thread (bool) – By default
True
, this determines whether to force the execution of this function to occur on a new thread.
- note_string (str) – A space-delimited list of notes. Notes should all be in the form
-
play_song
(song_name)¶ Play one of a number of songs through the robot’s piezoelectric speaker.
Parameters: song_name (str) – The song to play. Must be one of 'reveille'
,'daisy'
, or'fanfare'
.
-
rv
¶ float
The robot’s current rotational velocity, in radians/second.Positive values indicate counterclockwise rotation (when viewed from above) and negative values indicate clockwise rotation.
Setting the robot’s rotational velocity is always subject to
soar.robot.pioneer.PioneerRobot.RV_CAP
. On a real robot, this is further limited by the hardware rotational velocity cap.
-
set_analog_voltage
(v)¶ Sets the robot’s analog output voltage.
Parameters: v (float) – The output voltage to set. This is limited to the range of 0-10V.
-
set_robot_options
(**options)¶ Set Pioneer3 specific options. Any unsupported keywords are ignored.
Parameters: - **options – Arbitrary robot options.
- serial_ports (list, optional) – Sets the serial ports to try connecting to with the ARCOS client.
- ignore_brain_lag (bool) – If
True
, a step will always be assumed to be 0.1 seconds long. Otherwise, whatever duration the controller tells the robot to step is how long a step lasts. - raw_sonars (bool) – If
True
, sonar values will not be recast toNone
when no distance was returned.5.0
will be returned instead.
-
sonars
¶ (
list
offloat
) The latest sonar readings as an array.The array contains the latest distance sensed by each sonar, in order, clockwise from the robot’s far left to its far right. Readings are given in meters and are accurate to the millimeter. If no distance was sensed by a sonar, its entry in the array will be
None
, unless the robot optionraw_sonars
has been set toTrue
, in which case its entry will be5.0
.
-
to_dict
()¶ Return a dictionary representation of the robot, usable for serialization.
This contains the robot type, position, sonar data, and forward and rotational velocities.
-
-
soar.robot.pioneer.
gen_tone_pairs
(note_string, bpm=120)¶ Given a string of musical notes separated by spaces and a tempo, generate a corresponding list of (duration, tone) pairs corresponding to each note.
Parameters: - note_string (str) – A space-delimited list of notes. Notes should all be in the form
n/m(name)[#|b][octave]
. Ex:'1/4C'
produces a quarter note middle C.'1/8A#7'
produces an eighth note A# in the 7th MIDI octave.'1/4-'
produces a quarter rest. All of the MIDI notes in the range 1-127 can be played. - bpm (int) – The beats per minute or tempo to use to calculate durations.
Returns: A list of (duration, tone) tuples where duration is in seconds, and tone is the corresponding MIDI number. Musical rest has a tone of 0.
- note_string (str) – A space-delimited list of notes. Notes should all be in the form