Bioscara
DALSA's DIY SCARA Robot Arm.
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Slots | List of all members
bioscara_rviz_plugin::BioscaraPanel Class Reference

RViz Panel to control the hardware specific functions of the Bioscara robot. More...

#include <bioscara_panel.hpp>

Inheritance diagram for bioscara_rviz_plugin::BioscaraPanel:

Public Member Functions

 BioscaraPanel (QWidget *parent=0)
 Construct a new Bioscara Panel object.
 
 ~BioscaraPanel () override
 Destroy the Bioscara Panel object.
 
void onInitialize () override
 Automatically invoked by the RViz parent class. Initializes the panel.
 

Protected Member Functions

void cm_state_callback (const ControllerManagerActivity &msg)
 callback on reported controller or hardware state changes.
 
void joint_state_callback (const DynamicJointState &msg)
 callback on joint state update.
 
void ensure_jsb_is_active (void)
 Ensure the joint state broadcaster is active.
 
void set_hardware_component_state (const std::string component, const lifecycle_msgs::msg::State target_state)
 Makes a service request to change a hardware component state.
 
void configure_controller (const std::string controller)
 Makes a service request to configure a controller state.
 
void switch_controllers (const std::vector< std::string > &activate_controllers, const std::vector< std::string > &deactivate_controllers, const int32_t=SwitchController::Request::BEST_EFFORT, const bool activate_asap=false, const builtin_interfaces::msg::Duration timeout=builtin_interfaces::msg::Duration())
 Makes a service request to change controller states.
 
void set_controller_state (const std::string controller, const lifecycle_msgs::msg::State target_state)
 calls the correct functions to bring a controller to the correct state.
 
void dynamic_joint_state_msg_to_map (const DynamicJointState &dynamic_joint_state_in, std::unordered_map< std::string, InterfaceValue > &map_out)
 simple conversion message type conversion function
 
void named_lcs_msg_to_map (const std::vector< NamedLifecycleState > &named_lcs_in, std::unordered_map< std::string, NamedLifecycleState > &map_out)
 simple conversion message type conversion function
 
void print_cm_map (const std::string prefix, const std::unordered_map< std::string, NamedLifecycleState > &map_in)
 Print life-cycle state message to console.
 
void prepopulate_joint_state_map (std::unordered_map< std::string, InterfaceValue > &state_map, std::vector< std::string > augment_vec)
 Prepopulates a state map with a default NamedLifecycleState for every specified key.
 
void prepopulate_state_map (std::unordered_map< std::string, NamedLifecycleState > &state_map, std::vector< std::string > augment_vec)
 Prepopulates a state map with a default NamedLifecycleState for every specified key.
 
void update_homing_grp_state (void)
 Enabl/Disables the homing group depending on the homing controller state.
 
void update_homing_state_labels (void)
 updates all homing state labels.
 
void set_homing_state_label (QLabel *label, const InterfaceValue &state)
 Set state label text and color of the homing state label.
 
void update_state_labels_and_btns (void)
 Update all hardware and controller state lables.
 
void update_state_label_and_btn (const std::unordered_map< std::string, NamedLifecycleState > &state_map, QLabel *state_label, QPushButton *en_button, const std::string &state_key)
 updates component state label and control button.
 
void set_state_label (QLabel *label, const NamedLifecycleState &state)
 Set the state label.
 
void set_en_btn (QPushButton *button, const NamedLifecycleState &state)
 Set the control button state.
 
bool check_activation_conditions (const std::string component_key)
 Check under which conditions a component is allowed to be activated.
 
lifecycle_msgs::msg::State target_state_from_current (lifecycle_msgs::msg::State current_state)
 returns the next logical state from the current one.
 
void homing_cmd (const std::string joint, const int cmd)
 callback function called when a homing button is pressed
 
void ctrl_en_btn_cb (const std::string controller)
 callback on controller enable button
 

Protected Attributes

rclcpp::Node::SharedPtr node_
 Pointer to the parent node. Used for access to the executor.
 
rclcpp::Subscription< ControllerManagerActivity >::SharedPtr cm_state_subsription_
 Subscription to the the controller_manager state publisher.
 
rclcpp::Subscription< DynamicJointState >::SharedPtr joint_state_subsription_
 Subscription to the the joint state publisher state publisher.
 
rclcpp::Publisher< DynamicInterfaceGroupValues >::SharedPtr homing_publisher_
 Publisher to send commands to the homing_controller.
 
rclcpp::Client< SwitchController >::SharedPtr switch_controller_client_
 Service client to the "/controller_manager/switch_controller" service.
 
rclcpp::Client< ConfigureController >::SharedPtr configure_controller_client_
 Service client to the "/controller_manager/configure_controller" service.
 
rclcpp::Client< SetHardwareComponentState >::SharedPtr hardware_state_client_
 Service client to the "/controller_manager/set_hardware_component_state" service.
 
rclcpp::TimerBase::SharedPtr prune_timer_
 Timer triggered every 5 s to prune unanswered service requests.
 
std::unordered_map< std::string, InterfaceValue > joint_states_
 Map storing all joint state interface values by each joint.
 
std::unordered_map< std::string, NamedLifecycleState > hardware_states_
 Map correlating hardware component name to its lifecycle_msgs/State.
 
std::unordered_map< std::string, NamedLifecycleState > controller_states_
 Map correlating controller name to its lifecycle_msgs/State.
 
Ui::BioscaraUI * ui_
 The QT object containing all UI elements.
 

Private Slots

void arm_en_btn_cb (void)
 Tries to set the bioscara_arm hardware component to the active state and tries to enable the velocity_joint_trajectory_controller.
 
void gripper_en_btn_cb (void)
 Tries to set the bioscara_gripper_128 hardware component to the active state and tries to enable the gripper_controller.
 

Detailed Description

RViz Panel to control the hardware specific functions of the Bioscara robot.

Through the panel it is possible to modify the robot's hardware's and controller states and to execute the homing procedures.

Constructor & Destructor Documentation

◆ BioscaraPanel()

bioscara_rviz_plugin::BioscaraPanel::BioscaraPanel ( QWidget *  parent = 0)
explicit

Construct a new Bioscara Panel object.

Creates a new ui_ object from the ui object autogenerated from the "bioscara_rviz_plugin_frame.ui". This object contains all UI elements. Each button gets assigned a callback function.

Parameters
parent

◆ ~BioscaraPanel()

bioscara_rviz_plugin::BioscaraPanel::~BioscaraPanel ( )
override

Destroy the Bioscara Panel object.

Member Function Documentation

◆ arm_en_btn_cb

void bioscara_rviz_plugin::BioscaraPanel::arm_en_btn_cb ( void  )
privateslot

Tries to set the bioscara_arm hardware component to the active state and tries to enable the velocity_joint_trajectory_controller.

◆ check_activation_conditions()

bool bioscara_rviz_plugin::BioscaraPanel::check_activation_conditions ( const std::string  component_key)
protected

Check under which conditions a component is allowed to be activated.

Some controllers will only activate under certain conditions. This functions disables the activation button if the coditions are met.

Parameters
component_key
Returns
true
false

◆ cm_state_callback()

void bioscara_rviz_plugin::BioscaraPanel::cm_state_callback ( const ControllerManagerActivity &  msg)
protected

callback on reported controller or hardware state changes.

Updates the controller_states_ and hardware_states_ state maps. Reactivates the Joint State Broadcaster if it has become inactive. Updates controller and hardware state labels and buttons by invoking update_state_labels_and_btns() Updates homing group state by invoking update_homing_grp_state().

Parameters
msgreceived controller states

◆ configure_controller()

void bioscara_rviz_plugin::BioscaraPanel::configure_controller ( const std::string  controller)
protected

Makes a service request to configure a controller state.

Request issued through the configure_controller_client_. Asynchrounous call, method exits after having issued the request.

Parameters
controllername of controller to activate

◆ ctrl_en_btn_cb()

void bioscara_rviz_plugin::BioscaraPanel::ctrl_en_btn_cb ( const std::string  controller)
protected

callback on controller enable button

Parameters
controllerstring name of controller to change state

◆ dynamic_joint_state_msg_to_map()

void bioscara_rviz_plugin::BioscaraPanel::dynamic_joint_state_msg_to_map ( const DynamicJointState &  dynamic_joint_state_in,
std::unordered_map< std::string, InterfaceValue > &  map_out 
)
protected

simple conversion message type conversion function

Parameters
dynamic_joint_state_inmessage in
map_outjoint states map out

◆ ensure_jsb_is_active()

void bioscara_rviz_plugin::BioscaraPanel::ensure_jsb_is_active ( void  )
protected

Ensure the joint state broadcaster is active.

The JSB can become inactive, ensure that it comes active again.

Calls the set_controller_state() method

◆ gripper_en_btn_cb

void bioscara_rviz_plugin::BioscaraPanel::gripper_en_btn_cb ( void  )
privateslot

Tries to set the bioscara_gripper_128 hardware component to the active state and tries to enable the gripper_controller.

◆ homing_cmd()

void bioscara_rviz_plugin::BioscaraPanel::homing_cmd ( const std::string  joint,
const int  cmd 
)
protected

callback function called when a homing button is pressed

publishes on homing_publisher_ to initiate/stop homing

Parameters
jointstring name of joint
cmd-1, 0, +1 to start homing to negative direction, stop homing, start homing to positve direction.

◆ joint_state_callback()

void bioscara_rviz_plugin::BioscaraPanel::joint_state_callback ( const DynamicJointState &  msg)
protected

callback on joint state update.

Updates joint_states_ with the latest values using dynamic_joint_state_msg_to_map(). Updates homing group state by invoking update_homing_grp_state().

Parameters
msgreceived joint states

◆ named_lcs_msg_to_map()

void bioscara_rviz_plugin::BioscaraPanel::named_lcs_msg_to_map ( const std::vector< NamedLifecycleState > &  named_lcs_in,
std::unordered_map< std::string, NamedLifecycleState > &  map_out 
)
protected

simple conversion message type conversion function

Parameters
named_lcs_inNamedLifecycleState message in
map_outstate map out

◆ onInitialize()

void bioscara_rviz_plugin::BioscaraPanel::onInitialize ( )
override

Automatically invoked by the RViz parent class. Initializes the panel.

Retrieves the pointer to the parent node and saves it in node_. This node and its executor is used for all clients and publishers.

Additionally a the prune_timer_ is created which periodically cleans all dangling service requests. All subscribers, publishers and clients are created and saved in their corresponding handler. Also the #controller_states_state and hardware_states_ state maps are prepopulated by invoking prepopulate_state_map()

◆ prepopulate_joint_state_map()

void bioscara_rviz_plugin::BioscaraPanel::prepopulate_joint_state_map ( std::unordered_map< std::string, InterfaceValue > &  state_map,
std::vector< std::string >  augment_vec 
)
protected

Prepopulates a state map with a default NamedLifecycleState for every specified key.

This is done to avoid having to check for the existence of key when accessing the map. Keys could be missing if hardware interfaces are not specified or named differently.

For every joint the state interfaces are initialized as follows:

  • position: 0.0
  • velocity: 0.0
  • home: 0.0

Some joints (the gripper) dont have all state interfaces, but they are initialized regardless.

Parameters
state_mapThe state map to prepopulate
augment_veckeys that are added/overwritten

◆ prepopulate_state_map()

void bioscara_rviz_plugin::BioscaraPanel::prepopulate_state_map ( std::unordered_map< std::string, NamedLifecycleState > &  state_map,
std::vector< std::string >  augment_vec 
)
protected

Prepopulates a state map with a default NamedLifecycleState for every specified key.

This is done to avoid having to check for the existence of key when accessing the map. Keys could be missing if an expected controller or hardware component has not been loaded or has a different name.

Parameters
state_mapThe state map to prepopulate
augment_veckeys that are added/overwritten

◆ print_cm_map()

void bioscara_rviz_plugin::BioscaraPanel::print_cm_map ( const std::string  prefix,
const std::unordered_map< std::string, NamedLifecycleState > &  map_in 
)
protected

Print life-cycle state message to console.

Parameters
prefixstring prefix
map_inmap to be printed

◆ set_controller_state()

void bioscara_rviz_plugin::BioscaraPanel::set_controller_state ( const std::string  controller,
const lifecycle_msgs::msg::State  target_state 
)
protected

calls the correct functions to bring a controller to the correct state.

Checks if configure_controller() needs to be called before switch_controllers() can be called to bring the controller to the desired state.

Parameters
controllercontroller name
target_statetarget state

◆ set_en_btn()

void bioscara_rviz_plugin::BioscaraPanel::set_en_btn ( QPushButton *  button,
const NamedLifecycleState &  state 
)
protected

Set the control button state.

Sets control buttons color, text and active status based on the component state.

Parameters
buttonpointer to button to modify
statestate of the component

◆ set_hardware_component_state()

void bioscara_rviz_plugin::BioscaraPanel::set_hardware_component_state ( const std::string  component,
const lifecycle_msgs::msg::State  target_state 
)
protected

Makes a service request to change a hardware component state.

Request issued through the hardware_state_client_. Asynchrounous call, method exits after having issued the request.

Parameters
componentname of hardware component to modify
target_statetarget state

◆ set_homing_state_label()

void bioscara_rviz_plugin::BioscaraPanel::set_homing_state_label ( QLabel *  label,
const InterfaceValue &  state 
)
protected

Set state label text and color of the homing state label.

Sets color and text of label.

Parameters
labelpointer to label
statejoint state

◆ set_state_label()

void bioscara_rviz_plugin::BioscaraPanel::set_state_label ( QLabel *  label,
const NamedLifecycleState &  state 
)
protected

Set the state label.

sets color and text based on the component state.

Parameters
labelpointer to label to modify
statestate of the component

◆ switch_controllers()

void bioscara_rviz_plugin::BioscaraPanel::switch_controllers ( const std::vector< std::string > &  activate_controllers,
const std::vector< std::string > &  deactivate_controllers,
const int32_t  strictness = SwitchController::Request::BEST_EFFORT,
const bool  activate_asap = false,
const builtin_interfaces::msg::Duration  timeout = builtin_interfaces::msg::Duration() 
)
protected

Makes a service request to change controller states.

Activates and deactivates a combination of controllers.

Parameters
activate_controllerslist of controllers to activate
deactivate_controllerslist of controllers to deactivate
activate_asapif true controller switch happens in the realtime loop
timeoutswitch timeout

◆ target_state_from_current()

lifecycle_msgs::msg::State bioscara_rviz_plugin::BioscaraPanel::target_state_from_current ( lifecycle_msgs::msg::State  current_state)
protected

returns the next logical state from the current one.

Parameters
current_statecurrent state
Returns
lifecycle_msgs::msg::State

◆ update_homing_grp_state()

void bioscara_rviz_plugin::BioscaraPanel::update_homing_grp_state ( void  )
protected

Enabl/Disables the homing group depending on the homing controller state.

◆ update_homing_state_labels()

void bioscara_rviz_plugin::BioscaraPanel::update_homing_state_labels ( void  )
protected

updates all homing state labels.

Calls set_homing_state_label() for each joint state label.

◆ update_state_label_and_btn()

void bioscara_rviz_plugin::BioscaraPanel::update_state_label_and_btn ( const std::unordered_map< std::string, NamedLifecycleState > &  state_map,
QLabel *  state_label,
QPushButton *  en_button,
const std::string &  state_key 
)
protected

updates component state label and control button.

Calls set_state_label() for state_label and set_en_btn() for en_button.

Parameters
state_mapcomponent state map
state_labelpointer to state label
en_buttonpointer to enable button
state_keystring key to access in state_map

◆ update_state_labels_and_btns()

void bioscara_rviz_plugin::BioscaraPanel::update_state_labels_and_btns ( void  )
protected

Update all hardware and controller state lables.

calls update_state_label_and_btn() for each controller and hardware component.

Member Data Documentation

◆ cm_state_subsription_

rclcpp::Subscription<ControllerManagerActivity>::SharedPtr bioscara_rviz_plugin::BioscaraPanel::cm_state_subsription_
protected

Subscription to the the controller_manager state publisher.

Used to retrieve information about hardware and controller state changes.

◆ configure_controller_client_

rclcpp::Client<ConfigureController>::SharedPtr bioscara_rviz_plugin::BioscaraPanel::configure_controller_client_
protected

Service client to the "/controller_manager/configure_controller" service.

Used to request configuration and cleanup of controllers.

◆ controller_states_

std::unordered_map<std::string, NamedLifecycleState> bioscara_rviz_plugin::BioscaraPanel::controller_states_
protected

Map correlating controller name to its lifecycle_msgs/State.

Stored as NamedLifecycleState to also simply access controller name from map value.

◆ hardware_state_client_

rclcpp::Client<SetHardwareComponentState>::SharedPtr bioscara_rviz_plugin::BioscaraPanel::hardware_state_client_
protected

Service client to the "/controller_manager/set_hardware_component_state" service.

Used to request activation and deactivation of harddware components.

◆ hardware_states_

std::unordered_map<std::string, NamedLifecycleState> bioscara_rviz_plugin::BioscaraPanel::hardware_states_
protected

Map correlating hardware component name to its lifecycle_msgs/State.

Stored as NamedLifecycleState to also simply access component name from map value.

◆ homing_publisher_

rclcpp::Publisher<DynamicInterfaceGroupValues>::SharedPtr bioscara_rviz_plugin::BioscaraPanel::homing_publisher_
protected

Publisher to send commands to the homing_controller.

Used to start and stop homing of joints.

◆ joint_state_subsription_

rclcpp::Subscription<DynamicJointState>::SharedPtr bioscara_rviz_plugin::BioscaraPanel::joint_state_subsription_
protected

Subscription to the the joint state publisher state publisher.

Uses the "/dynamic_joint_states" to receive updates of all joints states.

◆ joint_states_

std::unordered_map<std::string, InterfaceValue> bioscara_rviz_plugin::BioscaraPanel::joint_states_
protected

Map storing all joint state interface values by each joint.

◆ node_

rclcpp::Node::SharedPtr bioscara_rviz_plugin::BioscaraPanel::node_
protected

Pointer to the parent node. Used for access to the executor.

◆ prune_timer_

rclcpp::TimerBase::SharedPtr bioscara_rviz_plugin::BioscaraPanel::prune_timer_
protected

Timer triggered every 5 s to prune unanswered service requests.

◆ switch_controller_client_

rclcpp::Client<SwitchController>::SharedPtr bioscara_rviz_plugin::BioscaraPanel::switch_controller_client_
protected

Service client to the "/controller_manager/switch_controller" service.

Used to request activation and deactivation of controllers.

◆ ui_

Ui::BioscaraUI* bioscara_rviz_plugin::BioscaraPanel::ui_
protected

The QT object containing all UI elements.

Autogenerated from the "bioscara_rviz_plugin_frame.ui" file.


The documentation for this class was generated from the following files: