Skip to content

Commit cdd8add

Browse files
committed
Fully working on the Gripper example.
1 parent 7bfce93 commit cdd8add

File tree

6 files changed

+390
-208
lines changed

6 files changed

+390
-208
lines changed

gpio_controllers/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ if(BUILD_TESTING)
105105
ros2_control_test_assets::ros2_control_test_assets
106106
)
107107

108+
ament_add_gmock(
109+
test_load_gpio_tool_controller
110+
test/test_load_gpio_tool_controller.cpp
111+
)
112+
target_include_directories(test_load_gpio_tool_controller PRIVATE include)
113+
target_link_libraries(test_load_gpio_tool_controller
114+
gpio_tool_controllers
115+
controller_manager::controller_manager
116+
ros2_control_test_assets::ros2_control_test_assets
117+
)
118+
108119
# ament_add_gmock(test_gpio_tool_controller
109120
# test/gpio_tool_controller/test_gpio_tool_controller.cpp
110121
# test/gpio_tool_controller/test_gpio_tool_controller_open.cpp

gpio_controllers/doc/userdoc.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,26 @@ The controller expects at least one GPIO interface and the corresponding command
5757
- ana.2
5858
5959
With the above-defined controller configuration, the controller will accept commands for all gpios' interfaces and will only publish the state of Gpio2.
60+
61+
62+
63+
### gpio_tool_controller
64+
65+
The controller enables control of tools connected to the robot or components of a robot via general-purpose inputs and outputs (GPIO), digital or analog.
66+
Concretely the controller is made for controlling the custom-made industrial grippers or tools, or components like lifts or breaks.
67+
The IOs might even be virtual, like controlling the state machine of a robot that is implemented on a PLC.
68+
69+
The controller provides high-level interface for engaging or disengaging a tool or a component, as well as for reconfiguring it.
70+
The reconfiguration is possible only in *disengaged* state.
71+
In the example of gripper this would be *open* state.
72+
73+
74+
75+
The controller implements state machine for the transition between states and
76+
77+
78+
1. Tool Actions
79+
80+
1. Tool state machine
81+
82+
2. Transitions

gpio_controllers/include/gpio_controllers/gpio_tool_controller.hpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,33 +132,28 @@ class GpioToolController : public controller_interface::ControllerInterface
132132
{
133133
std::vector<std::string> possible_states;
134134

135-
std::unordered_map<std::string, std::unordered_map<std::string, double>> set_before_commands;
136-
std::unordered_map<std::string, size_t> set_before_commands_start_index;
137-
std::unordered_map<std::string, std::unordered_map<std::string, double>> set_before_states;
138-
std::unordered_map<std::string, size_t> set_before_states_start_index;
135+
std::unordered_map<std::string, std::unordered_map<std::string, std::pair<double, size_t>>> set_before_commands;
136+
std::unordered_map<std::string, std::unordered_map<std::string, std::pair<double, size_t>>> set_before_states;
139137

140-
std::unordered_map<std::string, std::unordered_map<std::string, double>> commands;
141-
std::unordered_map<std::string, size_t> commands_start_index;
138+
std::unordered_map<std::string, std::unordered_map<std::string, std::pair<double, size_t>>> commands;
142139

143-
std::unordered_map<std::string, std::unordered_map<std::string, double>> states;
144-
std::unordered_map<std::string, size_t> states_start_index;
140+
std::unordered_map<std::string, std::unordered_map<std::string, std::pair<double, size_t>>> states;
145141
std::unordered_map<std::string, std::vector<double>> states_joint_states;
146-
std::unordered_map<std::string, std::unordered_map<std::string, double>> set_after_commands;
147-
std::unordered_map<std::string, size_t> set_after_commands_start_index;
148-
std::unordered_map<std::string, std::unordered_map<std::string, double>> set_after_states;
149-
std::unordered_map<std::string, size_t> set_after_states_start_index;
142+
std::unordered_map<std::string, std::unordered_map<std::string, std::pair<double, size_t>>> set_after_commands;
143+
std::unordered_map<std::string, std::unordered_map<std::string, std::pair<double, size_t>>> set_after_states;
150144
};
151145

152146
ToolTransitionIOs disengaged_gpios_;
153147
ToolTransitionIOs engaged_gpios_;
154148
ToolTransitionIOs reconfigure_gpios_;
155149

150+
// Not needed to be atomic or protected as used only in the RT loop
156151
rclcpp::Time state_change_start_;
157152
std::string current_configuration_;
158153
std::string current_state_;
159154

160-
std::unordered_set<std::string> command_if_ios;
161-
std::unordered_set<std::string> state_if_ios;
155+
std::unordered_set<std::string> command_if_ios_;
156+
std::unordered_set<std::string> state_if_ios_;
162157

163158
using EngagingSrvType = example_interfaces::srv::Trigger;
164159
using ResetSrvType = example_interfaces::srv::Trigger;
@@ -218,12 +213,13 @@ class GpioToolController : public controller_interface::ControllerInterface
218213
const rclcpp::Time & current_time, const ToolTransitionIOs & ios,
219214
std::vector<double> & joint_states, const size_t joint_states_start_index,
220215
const std::string & output_prefix, const uint8_t next_transition,
221-
std::string & found_state_name);
216+
std::string & found_state_name, const bool warning_output = false);
222217

223218
/**
224219
* @brief Prepares the command and state IOs.
220+
* \returns true if successful, false otherwise. Check the output if error has happend.
225221
*/
226-
void prepare_command_and_state_ios();
222+
bool prepare_command_and_state_ios();
227223

228224
/**
229225
* @brief Prepares the publishers and services.
@@ -239,15 +235,14 @@ class GpioToolController : public controller_interface::ControllerInterface
239235
/**
240236
* @brief Checks the tools state.
241237
*/
242-
void check_tool_state(const rclcpp::Time & current_time);
238+
void check_tool_state(const rclcpp::Time & current_time, const bool warning_output = false);
243239

244240
bool set_commands(
245-
const std::unordered_map<std::string, double> & commands,
246-
const size_t start_index,
247-
const std::string & transition_name,
241+
const std::unordered_map<std::string, std::pair<double, size_t>> & commands,
242+
const std::string & output_prefix,
248243
const uint8_t next_transition);
249244
bool check_states(
250-
const rclcpp::Time & current_time, const std::unordered_map<std::string, double> & states, const size_t start_index, const std::string & transition_name, const uint8_t next_transition);
245+
const rclcpp::Time & current_time, const std::unordered_map<std::string, std::pair<double, size_t>> & states, const std::string & output_prefix, const uint8_t next_transition, const bool warning_output = false);
251246

252247
std::vector<std::string> configurations_list_;
253248
std::vector<gpio_tool_controller::Params::ConfigurationSetup::MapConfigurations> config_map_;

0 commit comments

Comments
 (0)