E-puck with Pi-puck
Table Of Contents
Code
- class PiPuckEpuck(ip_addr)
- set_clock_speed(clock_speed)
Set new clock speed in Hz
- go_on(clock_speed=None)
Important
Mandatory method. This method must be called before execution of next step of the robot.
Tip
Put it as a condition in a while loop. Then, if you would like to finish the infinite while loop, break inside.
- set_speed(speed_left, speed_right=None)
Sets the speed of the robot’s motors
- Parameters:
speed_left – int
speed_right – int, optional (default: is the same speed as speed_left)
Note
The speed of each wheel is already bounded between -7.536 and 7.536
- get_speed()
Gets speed of the motors
- Returns:
[left_wheel, right_wheel]
- Return type:
[int, int]
- bounded_speed(speed)
Limits the motor speed of the robot in case the user puts an excessive value
- Parameters:
speed – speed of a wheel of the e-puck
- enable_led(led_position, red=None, green=None, blue=None)
Note
Extension with the pi-puck adds LEDs 8, 9 and 10 with
There is only one RGB intensity for the pi-puck. It is either 0 (OFF) or 1 (or any other value higher than 0) (ON)
- disable_led(led_position)
Note
Extension with the pi-puck adds LEDs 8, 9 and 10
- enable_body_led()
Warning
Not possible with the pi-puck
- enable_front_led()
Warning
Not possible with the pi-puck
- get_prox()
Gets the robot’s proximity sensor raw values
Note
IR proximity: between 0 (no objects detected) and 4095 (object near the sensor)
Hint
Array position
prox right front
prox right front diagonal
prox right side
prox right back
prox left back
prox left side
prox left front diagonal
prox left front
- Returns:
the proximity sensor values
- Return type:
int array - (length 8)
- get_ground()
Gets the values from the ground sensors
Note
Between 0 (no surface at all or not reflective surface e.g. black) and 1023 (very reflective surface e.g. white)
Hint
Array positions
LEFT
MIDDLE
RIGHT
- Returns:
ground values
- Return type:
[int] - [LEFT, MIDDLE, RIGHT]
- get_gyro_axes()
Gets gyroscope values (axis x, y and z)
- Returns:
[x, y, z]
- Return type:
[int, int, int]
- get_accelerometer_axes()
Gets the accelerometer axis raw values.
- Returns:
[x,y,z]
- Return type:
array of int
- init_tof()
It is required to have the VL53L0X package to be able to use the TOF sensor.
- install it from your terminal:
pip3 install git+https://github.com/gctronic/VL53L0X_rasp_python
- get_tof()
Gets the Time Of Flight value
Warning
The TOF sensor can have different orientations on the robot which will affect measurement.
- Returns:
values in millimetres
- Return type:
int
- disable_tof()
Stops the TOF sensor
- init_camera(folder_save_img=None, size=(None, None), camera_rate=0.2)
Enables the robot’s camera
- Parameters:
save_image_folder – input directory folder to save the images taken by the robot
camera_rate – camera_rate
- disable_camera()
Disables the robot’s camera
- get_camera()
Gets raw images from robot
Note
More information in Examples/camera
- Return arrays:
[[red],[green],[blue]]
- get_camera_read()
get camera.read() of openCV
- take_picture(filename=None)
Take a picture and save it in the image folder define in
init_camera
- get_microphones()
Gets microphones’ intensity
Note
Mic volume: between 0 and 4095
- Returns:
[front, right, back, left]
- Return type:
array of int
- calibrate_prox()
Adjust the sensors to make them as error free as possible
Note
When all LEDs are ON, it indicates that the sensors are calibrating.
- disable_all_led()
Turns OFF all LED lights
- disable_body_led()
Turns OFF green body light
- disable_front_led()
Turns OFF red front light
- disable_sensors()
Disables the robot’s sensors
- enable_all_led()
Turns ON all LED lights
- get_acceleration()
Gets the magnitude of the acceleration vector, whose direction angles are provided by the
get_pitch()andget_roll()functionsNote
acceleration magnitude, between 0.0 and about 2600.0 (~3.46 g)
- Returns:
value of the accelerometer
- Return type:
int
- get_available_epucks()
Get list of connected epucks to the host.
Warning
Monitor must be online!
- Returns:
array of connected epucks
- get_battery_level()
Gets battery level
- get_calibrate_prox()
Gets the calibrated proximity sensor values
Note
IR proximity: between 0 (no objects detected) and 4095 (object near the sensor)
Hint
Array proximites positions
prox right front
prox right front diagonal
prox right side
prox right back
prox left back
prox left side
prox left front diagonal
prox left front
- Returns:
proximity values
- Return type:
[int] - (length 8)
- get_detection(img=None, conf_thresh=0.9)
Analyze the picture passed as img
- Parameters:
img – the 120x160x3 array containing a picture returned by the function get_picture
conf_thresh – an artifical threshold to limit the detections only to a certain confidence level
- Returns:
array of Detected objects
Warning
Only works with real robots
- get_pitch()
Gets pitch angle reading.
Note
Inclination between 0.0 and 90.0 degrees (when tilted in any direction)
- Returns:
pitch axis degree
- Return type:
float
- get_roll()
Gets roll degree reading.
Note
Orientation between 0.0 and 360.0 degrees
- Returns:
roll axis degree
- Return type:
float
- has_receive_msg()
- Returns:
True if the robot has pending messages in his queue otherwise False.
- init_client_communication(host_ip='http://127.0.0.1:8000')
Warning
The host should be created first before calling this method. (ref. Examples/Communication)
- init_ground()
Initiates the ground sensors of the robot
- init_sensors()
Starts the robot’s sensors
- initiate_model(weights=None)
Initiate the network used to recognized blocks Need to be called once at the beginning :param weights: a .pt file containing new possible weights (default: the one trained by Vincent Carrel) .. warning:
Only works with real robots
- live_camera(duration=None)
Lets you stream from the GUI
The live_camera method need to be called at each step.
- Parameters:
duration – int - duration of the stream. (default: until program ends)
- live_detection(duration=None)
Lets you stream the annotated image from the GUI The live_detection method needs to be called at each step. :param duration: int - duration of the stream. (default: until program ends) .. warning:
Only works with real robots
- receive_msg()
Get next message from the robot queue otherwise returns None.
- save_detection(filename=None)
Save the annotated image either with a default name or the one given in filename :param filename: str under which the picture should be saved .. warning:
Only works with real robots
- send_msg(msg)
Puts a message in queue to other robots
- Parameters:
msg – any
- set_id(new_id)
Set new ID for the e-puck
- sleep(duration)
Pause the execution during duration seconds
Warning
This implementation is to be preferred to the standard Python time.sleep() which can lead to problems in the sequence of event handling.
- Parameters:
duration – duration in seconds