WebotsEpuck
Table Of Contents
Code
- class WebotsEpuck
- get_id()
- Returns:
The host name of the computer
- set_id(new_id)
Set new ID for the e-puck
- get_ip()
Gets name of the host
- go_on()
Goes to next frame
- 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
- get_battery_level()
Warning
Only works with real robots
- 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)
Turns ON led at led_position
- Parameters:
led_position – int value between 0 and 7
Important
Only LEDs at position 1,3,5 and 7 are RGB
the three colours must be specified to use RGB
- Parameters:
red – int - red intensity value is between 0 (low) and 100 (high)
green – int - green intensity value is between 0 (low) and 100 (high)
blue – int - blue intensity value is between 0 (low) and 100 (high)
- disable_led(led_position)
Turns OFF led at led_position
- Parameters:
led_position – int - (value between 0 and 7)
- enable_all_led()
Turns ON all LED lights
- disable_all_led()
Turns OFF all LED lights
- enable_body_led()
Turns ON green body light
- disable_body_led()
Turns OFF green body light
- enable_front_led()
Turns ON red front light
- disable_front_led()
Turns OFF red front light
- init_sensors()
Starts the robot’s sensors
- disable_sensors()
Disables the robot’s sensors
- 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)
- 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.
- 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)
- init_tof()
Initiates Time Of Flight sensor
- 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_ground()
Initiates the ground sensors of the robot
Note
On Webots, initally the robot does not embed the ground sensors. You must add the NODE ‘E-puckGroundSensors (Transform)’ to the robot to embed it.
- 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
- 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_roll()
Gets roll degree reading.
Note
Orientation between 0.0 and 360.0 degrees
- Returns:
roll axis degree
- Return type:
float
- 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_microphones()
Warning
Only works with real robots
- get_temperature()
Warning
Only works with real robots
- init_camera(save_image_folder=None, camera_rate=1, size=(None, None))
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]]
- take_picture(filename=None)
Takes a picture and saves it in defined image folder from
init_camera
- live_camera(live_time=None)
Note
Only call this method if you prefer to stream from the unifr_api_epuck GUI instead of Webots.
- init_webots_communication()
Call this method to use Webots specific communication
- init_client_communication(host_ip='localhost')
If you called the init_webots_communication(), then the e-puck will connect to the specific Webots communication.
If you do not call the init_webots_communication(), then the robot will try to find a host communication.
- send_msg(msg)
Puts a message in queue to other robots.
Warning
If you use Webots communication then you can only send strings.
- has_receive_msg()
- Returns:
True if the robot has pending messages in his queue otherwise False.
- receive_msg()
Get next message from the robot queue otherwise returns None.
- 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
- 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
- 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
- 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
- get_available_epucks()
Get list of connected epucks to the host.
Warning
Monitor must be online!
- Returns:
array of connected epucks