Bioscara
DALSA's DIY SCARA Robot Arm.
Loading...
Searching...
No Matches
bioscara_panel.hpp
Go to the documentation of this file.
1/* Author: sbstorz */
2
3#ifndef BIOSCARA_RVIZ_PANEL_HPP_
4#define BIOSCARA_RVIZ_PANEL_HPP_
5
6#include <QLabel>
7#include <QPushButton>
8#include <unordered_map>
9#include <vector>
10
11#include <rviz_common/panel.hpp>
12#include <rviz_common/ros_integration/ros_node_abstraction_iface.hpp>
13#include "controller_manager_msgs/msg/controller_manager_activity.hpp"
14#include "controller_manager_msgs/msg/named_lifecycle_state.hpp"
15#include "controller_manager_msgs/srv/list_controllers.hpp"
16#include "controller_manager_msgs/srv/set_hardware_component_state.hpp"
17#include "controller_manager_msgs/srv/switch_controller.hpp"
18#include "controller_manager_msgs/srv/configure_controller.hpp"
19#include "control_msgs/msg/dynamic_joint_state.hpp"
20#include "control_msgs/msg/dynamic_interface_group_values.hpp"
21
22namespace Ui
23{
24 class BioscaraUI;
25}
26
28{
29 using namespace controller_manager_msgs::msg;
30 using namespace controller_manager_msgs::srv;
31 using namespace control_msgs::msg;
32
38 class BioscaraPanel : public rviz_common::Panel
39 {
40 Q_OBJECT
41 public:
51 explicit BioscaraPanel(QWidget *parent = 0);
52
57 ~BioscaraPanel() override;
58
69 void onInitialize() override;
70
71 protected:
75 rclcpp::Node::SharedPtr node_;
76
83 rclcpp::Subscription<ControllerManagerActivity>::SharedPtr cm_state_subsription_;
84
91 rclcpp::Subscription<DynamicJointState>::SharedPtr joint_state_subsription_;
92
99 rclcpp::Publisher<DynamicInterfaceGroupValues>::SharedPtr homing_publisher_;
100
107 rclcpp::Client<SwitchController>::SharedPtr switch_controller_client_;
108
115 rclcpp::Client<ConfigureController>::SharedPtr configure_controller_client_;
116
123 rclcpp::Client<SetHardwareComponentState>::SharedPtr hardware_state_client_;
124
129 rclcpp::TimerBase::SharedPtr prune_timer_;
130
135 std::unordered_map<std::string, InterfaceValue> joint_states_;
136
143 std::unordered_map<std::string, NamedLifecycleState> hardware_states_;
144
150 std::unordered_map<std::string, NamedLifecycleState> controller_states_;
151
158 Ui::BioscaraUI *ui_;
159
170 void cm_state_callback(const ControllerManagerActivity &msg);
171
180 void joint_state_callback(const DynamicJointState &msg);
181
190 void ensure_jsb_is_active(void);
191
201 void set_hardware_component_state(const std::string component, const lifecycle_msgs::msg::State target_state);
202
211 void configure_controller(const std::string controller);
212
223 void switch_controllers(const std::vector<std::string> &activate_controllers,
224 const std::vector<std::string> &deactivate_controllers,
225 const int32_t = SwitchController::Request::BEST_EFFORT,
226 const bool activate_asap = false,
227 const builtin_interfaces::msg::Duration timeout = builtin_interfaces::msg::Duration());
228
238 void set_controller_state(const std::string controller,
239 const lifecycle_msgs::msg::State target_state);
240
247 void dynamic_joint_state_msg_to_map(const DynamicJointState &dynamic_joint_state_in,
248 std::unordered_map<std::string, InterfaceValue> &map_out);
249
256 void named_lcs_msg_to_map(const std::vector<NamedLifecycleState> &named_lcs_in,
257 std::unordered_map<std::string, NamedLifecycleState> &map_out);
258
265 void print_cm_map(const std::string prefix,
266 const std::unordered_map<std::string, NamedLifecycleState> &map_in);
267
288 void prepopulate_joint_state_map(std::unordered_map<std::string, InterfaceValue> &state_map,
289 std::vector<std::string> augment_vec);
290
303 void prepopulate_state_map(std::unordered_map<std::string, NamedLifecycleState> &state_map,
304 std::vector<std::string> augment_vec);
305
310 void update_homing_grp_state(void);
311
319
327 void set_homing_state_label(QLabel *label, const InterfaceValue &state);
328
335
347 const std::unordered_map<std::string, NamedLifecycleState> &state_map,
348 QLabel *state_label,
349 QPushButton *en_button,
350 const std::string &state_key);
351
360 void set_state_label(QLabel *label, const NamedLifecycleState &state);
361
370 void set_en_btn(QPushButton *button, const NamedLifecycleState &state);
371
382 bool check_activation_conditions(const std::string component_key);
383
391 lifecycle_msgs::msg::State target_state_from_current(lifecycle_msgs::msg::State current_state);
392
401 void homing_cmd(const std::string joint, const int cmd);
402
408 void ctrl_en_btn_cb(const std::string controller);
409
410 private Q_SLOTS:
411
417 void arm_en_btn_cb(void);
418
424 void gripper_en_btn_cb(void);
425 };
426
427} // namespace bioscara_rviz_plugin
428
429#endif // BIOSCARA_RVIZ_PANEL_HPP_
RViz Panel to control the hardware specific functions of the Bioscara robot.
Definition bioscara_panel.hpp:39
void cm_state_callback(const ControllerManagerActivity &msg)
callback on reported controller or hardware state changes.
Definition bioscara_panel.cpp:116
void set_en_btn(QPushButton *button, const NamedLifecycleState &state)
Set the control button state.
Definition bioscara_panel.cpp:483
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.
Definition bioscara_panel.cpp:201
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
Definition bioscara_panel.cpp:323
void homing_cmd(const std::string joint, const int cmd)
callback function called when a homing button is pressed
Definition bioscara_panel.cpp:278
rclcpp::Client< ConfigureController >::SharedPtr configure_controller_client_
Service client to the "/controller_manager/configure_controller" service.
Definition bioscara_panel.hpp:115
bool check_activation_conditions(const std::string component_key)
Check under which conditions a component is allowed to be activated.
Definition bioscara_panel.cpp:517
rclcpp::Publisher< DynamicInterfaceGroupValues >::SharedPtr homing_publisher_
Publisher to send commands to the homing_controller.
Definition bioscara_panel.hpp:99
Ui::BioscaraUI * ui_
The QT object containing all UI elements.
Definition bioscara_panel.hpp:158
std::unordered_map< std::string, InterfaceValue > joint_states_
Map storing all joint state interface values by each joint.
Definition bioscara_panel.hpp:135
void joint_state_callback(const DynamicJointState &msg)
callback on joint state update.
Definition bioscara_panel.cpp:130
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.
Definition bioscara_panel.cpp:365
rclcpp::Client< SetHardwareComponentState >::SharedPtr hardware_state_client_
Service client to the "/controller_manager/set_hardware_component_state" service.
Definition bioscara_panel.hpp:123
void update_homing_state_labels(void)
updates all homing state labels.
Definition bioscara_panel.cpp:394
rclcpp::TimerBase::SharedPtr prune_timer_
Timer triggered every 5 s to prune unanswered service requests.
Definition bioscara_panel.hpp:129
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.
Definition bioscara_panel.cpp:353
void configure_controller(const std::string controller)
Makes a service request to configure a controller state.
Definition bioscara_panel.cpp:163
void ensure_jsb_is_active(void)
Ensure the joint state broadcaster is active.
Definition bioscara_panel.cpp:137
void set_homing_state_label(QLabel *label, const InterfaceValue &state)
Set state label text and color of the homing state label.
Definition bioscara_panel.cpp:402
~BioscaraPanel() override
Destroy the Bioscara Panel object.
Definition bioscara_panel.cpp:53
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.
Definition bioscara_panel.cpp:445
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.
Definition bioscara_panel.cpp:178
rclcpp::Node::SharedPtr node_
Pointer to the parent node. Used for access to the executor.
Definition bioscara_panel.hpp:75
lifecycle_msgs::msg::State target_state_from_current(lifecycle_msgs::msg::State current_state)
returns the next logical state from the current one.
Definition bioscara_panel.cpp:254
void gripper_en_btn_cb(void)
Tries to set the bioscara_gripper_128 hardware component to the active state and tries to enable the ...
Definition bioscara_panel.cpp:304
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
Definition bioscara_panel.cpp:332
std::unordered_map< std::string, NamedLifecycleState > controller_states_
Map correlating controller name to its lifecycle_msgs/State.
Definition bioscara_panel.hpp:150
void update_homing_grp_state(void)
Enabl/Disables the homing group depending on the homing controller state.
Definition bioscara_panel.cpp:376
rclcpp::Subscription< DynamicJointState >::SharedPtr joint_state_subsription_
Subscription to the the joint state publisher state publisher.
Definition bioscara_panel.hpp:91
void onInitialize() override
Automatically invoked by the RViz parent class. Initializes the panel.
Definition bioscara_panel.cpp:58
rclcpp::Client< SwitchController >::SharedPtr switch_controller_client_
Service client to the "/controller_manager/switch_controller" service.
Definition bioscara_panel.hpp:107
rclcpp::Subscription< ControllerManagerActivity >::SharedPtr cm_state_subsription_
Subscription to the the controller_manager state publisher.
Definition bioscara_panel.hpp:83
void arm_en_btn_cb(void)
Tries to set the bioscara_arm hardware component to the active state and tries to enable the velocity...
Definition bioscara_panel.cpp:292
void ctrl_en_btn_cb(const std::string controller)
callback on controller enable button
Definition bioscara_panel.cpp:315
void print_cm_map(const std::string prefix, const std::unordered_map< std::string, NamedLifecycleState > &map_in)
Print life-cycle state message to console.
Definition bioscara_panel.cpp:341
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.
Definition bioscara_panel.cpp:147
std::unordered_map< std::string, NamedLifecycleState > hardware_states_
Map correlating hardware component name to its lifecycle_msgs/State.
Definition bioscara_panel.hpp:143
void update_state_labels_and_btns(void)
Update all hardware and controller state lables.
Definition bioscara_panel.cpp:427
void set_state_label(QLabel *label, const NamedLifecycleState &state)
Set the state label.
Definition bioscara_panel.cpp:456
Definition bioscara_panel.hpp:28