navel submodule
This module contains the classes implementing communication with the motion, speech, and perception sockets. Each class handles a connection to its respective socket and all its revelent messages.
Motion class
- class navel.navel.Motion(socket_name='/run/bodyd/motion.sock')
Bases:
navel._messages.PayloadMessages
Send and receive messages via motion socket
This class is able to transceive protobuf messages via a unix domain socket (UDS). As soon as object is created will attempt to connect to socket. If socket connection is successful class methods can be used to send messages. Each message is converted into a protobuf format and is then sent to motion socket.
- Parameters
socket_name (str) – Name of motion socket to connect too.
- arms_rotate(angle_l, angle_r)
Sends rotate arms command to robot.
- Parameters
angle_l (int) – Rotation of left arm.
angle_r (int) – Rotation of right arm.
- Raises
SocketError – In cases where message cannot be sent via socket.
- base_move(x, r)
Sends a move command to robot.
Command sets the robot speed to desired value, if after 10ms no new base_move has been sent then robot will start to decrease velocity. To keep robot at same velocity issue this command with the desired speed every 10ms.
- Parameters
x (int) – Forward motion magnitude.
r (int) – Anticlockwise rotation.
- Raises
SocketError – In cases where message cannot be sent via socket.
- base_tilt(x, y)
Sends tilt body command to robot.
- Parameters
x (int) – Tilt in X axis.
y (int) – Tilt in Y axis.
- Raises
SocketError – In cases where message cannot be sent via socket.
- config_set(name, value, valType)
Sends a message to change the value of a config field.
- Parameters
name (str) – Name of config field to set.
value (int or float) – Value to set.
valType (DataType) – DataType Enum describing value datatype.
- Raises
SocketError – In cases where message cannot be sent via socket.
- connect(attempts=1)
Connects object to its Unix domain socket.
Will to attempt to connect to UDS, named at object creation. If the attempts argument is passed and connection fails, this method will loop multiple times to reconnect.
- Parameters
attempts (int, optional) – How many attempts should be made to connect. Defaults to 1.
- Raises
OSError – If unable to connect.
- disconnect()
Disconnects socket.
- head_eyelids(openness_l, openness_r)
Sends a message setting how open the eyes should be.
- Parameters
openness_l (float) – Scalar value of how open left eye should be, where 1 is open and 0 is closed.
openness_r (float) – Scalar value of how open right eye should be, where 1 is open and 0 is closed.
- Raises
SocketError – In cases where message cannot be sent via socket.
- head_facial_expression(neutral, happy, sad, surprise, anger)
Sends a message setting the facial expression of the robot.
This function sets the magnitude of each of the robots five expressions. Each argument contains a scalar value of how extreme the argument emotion is, where emotion max is 1 and emotion minimum is 0.
- Parameters
neutral (float) – Sets magnitude of neutral expression.
happy (float) – Sets magnitude of happy expression.
sad (float) – Sets magnitude of sad expression.
surprise (float) – Sets magnitude of surprise expression.
anger (float) – Sets magnitude of anger expression.
- Raises
SocketError – In cases where message cannot be sent via socket.
- head_mouth(openness)
Sends a message setting how wide the mouth should be open.
- Parameters
openness (float) – Scalar value which controls how wide mouth should be open, 1 = open, 0 = closed.
- Raises
SocketError – In cases where message cannot be sent via socket.
- head_overlay(overlay)
Sends a message rotating the head using tait-bryan angles.
- Parameters
overlay (Bryan) – Tait-Bryan angles describing offset.
- Raises
SocketError – In cases where message cannot be sent via socket.
- head_path_limits(v_max, a_max, j_max)
Sends pathplanner limits for head motion to robot.
- Parameters
v_max (float) – Maximum velocity.
v_max – Maximum acceleration.
v_max – Maximum jerk.
- Raises
SocketError – In cases where message cannot be sent via socket.
- look_at_cart(cart, head)
Sends a message for robot to look at a point in space.
- Parameters
cart (CartSys3d) – 3d target point to look at.
head (float) – Magnitude of head movement towards point, where 0 is no movement and 1 is maximum movement.
- Raises
SocketError – In cases where message cannot be sent via socket.
- look_at_person(uuid, head)
Sends a message setting which person robot should look at.
- Parameters
uuid (int) – Unique identifier of person.
head (float) – Magnitude of head movement towards point, where 0 is no movement and 1 is maximum movement.
- Raises
SocketError – In cases where message cannot be sent via socket.
- look_at_px(px, head)
Sends a message to robot to look at a pixel.
- Parameters
px (Point2dS) – 2d point on the image plane.
head (float) – Magnitude of head movement towards point, where 0 is no movement and 1 is maximum movement.
- Raises
SocketError – In cases where message cannot be sent via socket.
Perception class
- class navel.navel.Perception(socket_name='/run/bodyd/vision.sock', keys=None, callbacks=None)
Bases:
navel._messages.PerceptionMessages
Send and receive messages via perception socket
This class is able to transceive protobuf messages via a unix domain socket (UDS). As soon as object is created will attempt to connect to socket. If socket connection is successful class methods can be used to send messages. Each message is converted into a protobuf format and is then sent to motion socket.
This also contains a listening thread which detects messages send from bodyd. This is run asynchronously as messages could arrive at any point in time. Read messages are accessed using callback functions. If there are no relevent callback functions then messages will be thrown away to keep buffer clear. See valid keys to see what callbacks are supported.
If the object where data is stored by callback functions is to be accessed by any other threads, steps must be taken to make it threadsafe.
- Parameters
socket_name (str, optional) – Name of the socket to connect to. Defaults to NAVEL_VISION_SOCKET
keys (str, optional) – List of names of callbacks. For list of valid values, cf.
assign_callbacks()
. Defaults to None.callbacks (function, optional) – List of callback functions. Defaults to None.
- assign_callbacks(keys, callbacks)
Adds key-value pairs to object callback dictionary.
Used to add callback functions after object has been created.
- Parameters
keys (str) –
Valid keys are
- ”error”
Returns async errors. These errors will be OSerror errnos. It can also return ENOTRECOVERABLE if an unexpected exception occurs and async listener stops.
- ”perception_data”
Returns a PerceptionData object containing all infomation passed by perceptionMessages.
callbacks (functions) – List of callback functions.
- close_socket()
Closes socket connection.
Attempts to shutdown listener thread and then closes socket. If listener thread cannot be shutdown within _SC_SHUTDOWN_CNT_MAX attempts then socket will be shutdown regardless. Between attempts method sleeps for _SC_ASYNC_SLEEP_DUR_SEC.
- Raises
OSError – In case of errors in accessing or closing socket.
- connect(attempts=1)
Connects object to its Unix domain socket.
Will to attempt to connect to UDS, named at object creation. If the attempts argument is passed and connection fails, this method will loop multiple times to reconnect.
- Parameters
attempts (int, optional) – How many attempts should be made to connect. Defaults to 1.
- Raises
OSError – If unable to connect.
- disconnect()
Disconnects socket.
Speech class
- class navel.navel.Speech(socket_name='/run/bodyd/speech.sock', keys=None, callbacks=None)
Bases:
navel._messages.SpeechMessages
Connect to and send messages to speech socket
This class is able to transceive protobuf messages via a unix domain socket (UDS). As soon as object is created will attempt to connect to socket. If socket connection is successful class methods can be used to send messages. Each message is converted into a protobuf format and is then sent to motion socket.
This also contains a listening thread which detects messages send from bodyd. This is run asynchronously as messages could arrive at any point in time. Read messages are accessed using callback functions. If there are no relevent callback functions then messages will be thrown away to keep buffer clear. See valid keys to see what callbacks are supported.
If the object where data is stored by callback functions is to be accessed by any other threads, steps must be taken to make it threadsafe.
- Parameters
socket_name (str, optional) – Name of the socket to connect to. Defaults to NAVEL_SPEECH_SOCKET
keys (str, optional) – List of names of callbacks. For list of valid values, cf.
assign_callbacks()
. Defaults to None.callbacks (function, optional) – List of callback functions mapped to keys. Defaults to None.
- assign_callbacks(keys, callbacks)
Adds key-value pairs to object callback dictionary.
Used to add callback functions after object has been created.
- Parameters
keys (str) –
Valid keys are
- ”error”
returns async errors. These errors will be OSerror errnos. It can also return ENOTRECOVERABLE if an unexpected exception occurs and async listener stops.
- ”mic_state”
returns a duration integer in us for how long current sound will be played.
- ”bookmark”
returns an integer value containing an audio bookmark value.
callbacks (functions) – List of callback functions.
- close_socket()
Closes socket connection.
Attempts to shutdown listener thread and then closes socket. If listener thread cannot be shutdown within _SC_SHUTDOWN_CNT_MAX attempts then socket will be shutdown regardless. Between attempts method sleeps for _SC_ASYNC_SLEEP_DUR_SEC.
- Raises
OSError – In case of errors in accessing or closing socket.
- connect(attempts=1)
Connects object to its Unix domain socket.
Will to attempt to connect to UDS, named at object creation. If the attempts argument is passed and connection fails, this method will loop multiple times to reconnect.
- Parameters
attempts (int, optional) – How many attempts should be made to connect. Defaults to 1.
- Raises
OSError – If unable to connect.
- disconnect()
Disconnects socket.
- speech_text(text)
Sends a speech text message to speech socket.
- Parameters
text (str) – contents of message to be sent to speech socket.
- Raises
TypeError – If text is not string
SocketError – If errors connecting to socket or sending message