roboglia.base.JointManager¶
-
class
JointManager
(name='JointManager', frequency=100.0, joints=[], group=None, function='mean', p_function=None, v_function=None, ld_function=None, timeout=0.5, **kwargs)[source]¶ Bases:
roboglia.base.thread.BaseLoop
Implements the management of the joints by alowing multiple movement streams to submit position commands to the robot.
The
JointManager
inherits the constructor paramters fromBaseLoop
. Please refer to that class for mote details.In addition the class introduces the following additional paramters:
- Parameters
joints (list of :py:class:roboglia.Base.`Joint` or subclass) – The list of joints that the manager is having under control. Alternatively you can use the parameter
group
(see below)group (set of :py:class:roboglia.Base.`Joint` or subclass) – A group of joints that was defined earlier with a
group
statement in the robot definition file.function (str) – The function used to produce the blended command for the joints. If specific functions for position (
p_function
), velocity (v_function
) or load (ld_function
) are not supplied, then this function is used. Allowed values are ‘mean’, ‘median’, ‘min’, ‘max’.p_function (str) – A specific function to be used for aggregating the position values. Allowed values are ‘mean’, ‘median’, ‘min’, ‘max’.
v_function (str) – A specific function to be used for aggregating the velocity values. Allowed values are ‘mean’, ‘median’, ‘min’, ‘max’.
ld_function (str) – A specific function to be used for aggregating the load values. Allowed values are ‘mean’, ‘median’, ‘min’, ‘max’.
timeout (float) – Is a time in seconds an accessor will wait before issuing a timeout when trying to submit data to the manager or the manager preparing the data for the joints.
-
__init__
(name='JointManager', frequency=100.0, joints=[], group=None, function='mean', p_function=None, v_function=None, ld_function=None, timeout=0.5, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
p_func
¶ Aggregate function for positions.
-
property
v_func
¶ Aggregate function for positions.
-
property
ld_func
¶ Aggregate function for positions.
-
submit
(stream, commands, adjustments=False)[source]¶ Used by a stream of commands to notify the Joint Manager they joint commands they want.
- Parameters
stream (BaseThread or subclass) – The stream providing the data. It is used to keep the request separate and be able to merge later.
commands (dict) –
A dictionary with the commands requests in the format:
{joint_name: (values)}
Where
values
is a tuple with the command for that joint. It is acceptable to send partial commands to a joint, for instance you can send only (100,) meaning position 100 to a JointPVL. Submitting more information to a joint will have no effect, for instance (100, 20, 40) (position, velocity, load) to a Joint will only use the position part of the request.adjustments (bool) – Indicates that the values are to be treated as adjustments to the other requests instead of absolute requests. This is convenient for streams that request postion correction like an accelerometer based balance control. Internally the JointManger keeps the commands separate between the absolute and the adjustments ones and calculates separate averages then adjusts the absolute results with the ones from the adjustments to produce the final numbers.
- Returns
True
if the operation was successful. False if there was an error (most likely the lock was not acquired). Caller needs to review this and decide if they should retry to send data.- Return type
bool
-
stop_submit
(stream, adjustments=False)[source]¶ Notifies the
JointManager
that the stream has finished sending data and as a result the data in theJointManager
cache should be removed.Warning
If the stream does not call this method when it finished with a routine the last submission will remain in the cache and will continue to be averaged with the other requests, creating problems. Don’t forget to call this method when your move finishes!
- Parameters
stream (BaseThread or subclass) – The name of the move sending the data
adjustments (bool) – Indicates the move submitted to the adjustment stream.
- Returns
True
if the operation was successful. False if there was an error (most likely the lock was not acquired). Caller needs to review this and decide if they should retry to send data. In the case of this method it is advisable to try resending the request, otherwise stale data will stay in the cache.- Return type
bool
-
start
()[source]¶ Starts the JointManager. Before calling the
BaseThread.start()
it activates the joints if they indicate they have theauto
flag set.
-
stop
()[source]¶ Stops the JointManager. After calling the
BaseThread.stop()
it deactivates the joints if they indicate they have theauto
flag set.
-
atomic
()[source]¶ This method implements the periodic task that needs to be executed. It does not need to check paused or stopped as the run method does this already and the subclasses should make sure that the implementation completes quickly and does not raise any exceptions.
-
property
actual_frequency
¶ Returns the actual running frequency that is calculated by statistics.
-
property
error_stat
¶ (error in %, total errors, total items).
- Type
Returns the error statistics as a tuple
-
property
errors
¶ Returns the number of errors logged by the statistics.
-
property
frequency
¶ Loop frequency.
-
inc_errors
()¶ Used by subclasses to increment the number of errors.
-
inc_processed
()¶ Used by subclasses to increment the number of processed items.
-
property
name
¶ Returns the name of the thread.
-
pause
()¶ Requests the thread to pause.
-
property
paused
¶ Indicates the thread was paused.
-
property
period
¶ Loop period = 1 / frequency.
-
property
processed
¶ Returns the number of items processed in the current statistics. The items processed depends on the loop and might be different from the number of loops executed. For example the one execution loop might include several communication packets.
-
resume
()¶ Requests the thread to resume.
-
property
review
¶ Indicates the amount of time in seconds before the thread will review the actual frequency against the target and take action.
-
run
()¶ Run method of the thread.
-
property
running
¶ Indicates if the thread is running.
-
setup
()¶ Thread preparation before running. Subclasses should override
-
property
started
¶ Indicates if the thread was started.
-
property
stopped
¶ Indicates if the thread was stopped.
-
teardown
()¶ Thread cleanup. Subclasses should override.
-
property
warning
¶ Control the warning level for the warning message, the setter is smart: if the value is larger than 2 it will assume it is a percentage and divied it by 100 and ignore if the number is higher than 110. The over 100 is available for testing purposes.