assisipy Package¶
assisipy Package¶
The assisipy Python package implements the API for monitoring and controlling CASU devices. It works both with simulated CASUS and pyhsical devices. It also provides several utility classes for interacting with the simulation engine.
bee Module¶
Python interface to simulated bees.
-
class
assisipy.bee.Bee(rtc_file_name='', name='Bee', **kwargs)¶ The low-level interface to Bee ‘robots’. This clas provides an api for programming bee behaviors. It creates a connection to the data source, i.e., the simulated bee. Waits for the bee of specified by ‘name’ to be spawned into the simulator.
Parameters: - rtc_file_name (string) – Name of the run-time-configuration (RTC) file. This file specifies the simulation connection parameters and the name of the simulated bee object.
- name (string) – The name of the bee (if not specified in the RTC file).
- kwargs (dict) – accepts strings to override values for: pub_addr (defaults to localhost:5556) sub_addr (defautls to localhost:5555)
-
get_airflow_direction(id=0)¶ Returns: the airflow angle sensed by airflow sensor id
-
get_airflow_intensity(id=0)¶ Returns: the airflow intensity sensed by airflow sensor id
-
get_color()¶ Returns: (r,g,b) tuple of bee color setpoints.
-
get_light_rgb(id=5)¶ Returns: (r,g,b) tuple, representing the light intensities at red, green and blue wavelengths (currently, the sensor reports only blue intensity, r and g are always 0).
-
get_object(id)¶ Returns the object type detected by sensor id.
-
get_object_with_range(id)¶ Returns the (object,range) pair detected by sensor id.
-
get_range(id)¶ Returns the range reading corresponding to sensor id.
TODO: Fix the hacky correction of invalid readings
-
get_temp(id=6)¶ Returns the temperature reading of sensor id.
-
get_true_pose()¶ Returns: (x,y,yaw) tuple, representing te true pose of the bee in the world.
-
get_vel_ref()¶ Returns: (vel_left,vel_right) tuple of wheel velocity setpoints.
-
get_vibration_amplitude(id)¶ Returns the vibration amplitude of sensor id.
-
get_vibration_frequency(id)¶ Returns the vibration frequency of sensor id.
-
set_color(r=0.93, g=0.79, b=0)¶ Set the color of the bee. This can be useful for diagnostic and demonstration purposes.
Take note of default values! E.g. in order to change the color to blue, you have to call the function with all parameters explicitly set:
b.set_color(r=0,g=0,b=1)
To revert to “original” bee coloring, call the function without any parameters:
b.set_color()
Parameters: - r (float) – Red component intensity, between 0 and 1.
- g (float) – Green component intensity, between 0 and 1.
- b (float) – Blue component intensity, between 0 and 1.
-
set_vel(vel_left, vel_right)¶ Set wheel velocities.
Bee body velocities depend on wheel velocities in the following way:
\[v = \frac{v_{left}+v_{right}}{2}\]\[\omega = \frac{v_{right}-v_{left}}{d}\]where d is the distance between the wheels (“axle length”).
Parameters: - vel_left (float) – Left wheel velocity.
- vel_right (float) – Right wheel velocity.
casu Module¶
Python interface to CASU functionality.
-
class
assisipy.casu.Casu(rtc_file_name='casu.rtc', name='', log=False, log_folder='.')¶ The low-level interface to Casu devices.
Initializes the object and starts listening for data. The fully constructed object is returned only after the data connection has been established.
Parameters: - rtc_file_name (string) – Name of the run-time configuration (RTC) file. If no file is provided, the default configuration is used; if name is provided, this parameter is ignored (and no RTC file is read).
- name (string) – Casu name (note: this value takes precedence over rtc_file_name if both provided: thus no RTC file is read)
- log (bool) – A variable indicating whether to log all incoming and outgoing data. If set to true, a logfile in the form ‘YYYY-MM-DD-HH-MM-SS-name.csv’ is created.
-
airflow_standby(id=801)¶ Puts the airflow actuator on standby.
-
diagnostic_led_standby(id=501)¶ Turn the diagnostic LED off.
-
get_airflow_intensity(id=801)¶ Get the intensity of the airflow actuator.
-
get_diagnostic_led_rgb(id=501)¶ Get the diagnostic light RGB value.
Returns: An (r,g,b) tuple (values between 0 and 1).
-
get_ir_raw_value(id)¶ Returns the raw value from the IR proximity sensor corresponding to sensor id.
-
get_peltier_setpoint(id=601)¶ Get the temperature actuator setpoint and state.
Returns: (temp,on) tuple, where temp is the temperature setpoint, and on is True if the actuator is switched on.
-
get_range(id)¶ Returns the range reading (in cm) corresponding to sensor id.
Note
This API call might become deprecated in favor of get_raw_value, to better reflect actual sensor capabilities.
-
get_speaker_amplitude(id=701)¶ Returns the vibration amplitude setpoint of actuator id.
-
get_speaker_freq(id=701)¶ Returns the vibration frequency setpoint of actuator id.
Not implemented!
-
get_temp(id)¶ Returns the temperature reading of sensor id.
-
get_vibration_pattern(id=701)¶ - tuple of lists
- (vibe_periods, idle_periods, vibe_freqs, vibe_amps)
-
get_vibration_readings(id=301)¶ Get vibration sensor (FFT processed accelerometer readings).
- tuple of lists: frequencies and amplitudes of 4 dominant FFT spectrum components
- (freqs, amps)
-
ir_standby(command='Standby')¶
-
is_airflow_on(id=801)¶ Get the state of the airflow actuator.
-
is_diagnostic_led_on(id=501)¶ Get the diagnostic LED state.
Returns: True/False
-
is_speaker_on(id=701)¶ Returns the speaker state.
-
name()¶ Returns the name of this Casu instance.
-
read_message()¶ Retrieve the latest message from the buffer.
Returns a dictionary with sender(string), and data (string) fields.
-
send_message(direction, msg)¶ Send a simple string message to one of the neighbors.
-
set_airflow_intensity(intensity, id=801)¶ Set the airflow intensity.
Parameters: intensity (float) – Airflow intensity (in precentage of maximum actuator value).
-
set_diagnostic_led_rgb(r=0, g=0, b=0, id=501)¶ Set the diagnostic LED light color. Automatically turns the actuator on.
Parameters: - r (float) – Red component intensity, between 0 and 1.
- g (float) – Green component intensity, between 0 and 1.
- b (float) – Blue component intensity, between 0 and 1.
-
set_speaker_vibration(freq, intens, id=701)¶ Sets intensity value (0-50) and frequency to the speaker.
- :param
- float freq: Speaker frequency value, between 0 and 1500 float intens: Speaker intensity value , between 0 and 50 %.
-
set_temp(temp, id=601, slope=0.025)¶ Sets the temperature reference of actuator id to temp.
Slope limits the velocity of the temperature reference rise. 0.025 deg/s is an experimentally determined appropriate value.
-
set_vibration_pattern(vibe_periods, vibe_freqs, vibe_amps, id=701)¶ Sets a vibration pattern. The pattern is repeated cyclically, until a new vibration setpoint (or standby command) is received.
To stop a vibration pattern, call the speaker_standby() function.
- vibe_periods : list
- List of vibration period durations, in milliseconds. Lowest supported value is 100.
- vibe_freqs : list
- List of vibration frequencies, in Hertz. All values must be between 1 and 1500.
- vibe_amps : list
- List of vibration amplitudes, in percentage of maximum PWM value. All values must be between 0 and 50.
- id : int
- Actuator id. Default (and only supported) value is VIBE_ACT
All lists must be of same length.
-
speaker_standby(id=701)¶ Turn the vibration actuators (bot motor and speaker) off.
-
stop()¶ Stops the Casu interface and cleans up.
TODO: Need to disable all object access once Casu is stopped!
-
temp_standby(id=601)¶ Turn the temperature actuator off.
physical Module¶
Python API for manipulating simulated physical objects.
-
class
assisipy.physical.Object(rtc_file_name='', name='object')¶ Interface to simulated physical objects.
Connects to the simulated physical object.
Parameters: - rtc_file_name (string) – Name of the RTC file.
- name (string) – Unique name of the spawned physical object.
sim Module¶
Pyton interface to the simulated world.
-
class
assisipy.sim.Control(rtc_file_name='', **kwargs)¶ Simulator control API.
Creates a command publisher and connects it to the simulator.
Parameters: rtc_file_name (string) – Name of the run-time configuraiton file. This file specifies the parameters for connecting to the simulator. -
get_absolute_time()¶ Get the absolute time as reported by the assisi playground.
Returns: the absolute time as reported by the assisi playground.
-
kill(obj_name)¶ Kill an object in the simulated world.
-
reset_temperature(temp)¶ Reset world temperature to given value
-
spawn(obj_type, name, pose, polygon=(), radius=(), color=(), height=1, mass=-1)¶ Spawn an object in the simulated world.
Parameters: - obj_type (str) – Type of object to spawn. Currently supported types are ‘Casu’, ‘Bee’, ‘EPuck’ and ‘Physical’
- name (str) – Name of the object. Must be unique in the world.
- pose (tuple) – An (x,y,yaw) tuple.
- polygon (tuple) – A tuple of vertex coordinates ((x1,y1),(x2,y2),...). If obj_type is ‘Physical’, this defines the shape of the object.
- radius – Radius of a cylindrical ‘Physical’ object.
- color – Color of a ‘Physical’ object.
- height (float) – ‘Physical’ object height.
- mass – ‘Physical’ object mass.
Returns: Nothing
-
spawn_array(obj_type, array)¶ Spawn an array of objects.
-
teleport(obj_name, pose)¶ Teleport object to pose.
-
-
assisipy.sim.main()¶
-
assisipy.sim.spawn_array_from_file(obj_type, array_filename, address, layer_select='all')¶
examples Module¶
Wandering bee example¶
Casu and bee example¶
Heat test¶
Start the simulator (it must be started from the same folder where the simulator executable is located!)
From the examples/heat_test folder run
$ ./spawn_casu_and_be.py
$ ./casu_heat_switch.py
In a new console window, run:
$ ./bee_wander_straight.py
The casu will be toggling its peltier actuator between heating and cooling every two minutes. The bee will be printing its temperature sensor value, while wandering in straight lines from one end of the arena to the other.