Skip to content

Commit

Permalink
Update GPIO digital IO ports to 18
Browse files Browse the repository at this point in the history
  • Loading branch information
munseng-flexiv committed Dec 9, 2024
1 parent 898edb3 commit 9e31114
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ The robot driver (`rizon.launch.py`) publishes the following feedback states to
### GPIO
All digital inputs on the robot control box can be accessed via the ROS topic `/gpio_controller/gpio_inputs`, which publishes the current state of all the 16 digital input ports *(True: port high, false: port low)*.
All digital inputs on the robot control box can be accessed via the ROS topic `/gpio_controller/gpio_inputs`, which publishes the current state of all the 18 *(16 on control box + 2 inside the wrist connector)* digital input ports *(True: port high, false: port low)*.
The digital output ports on the control box can be set by publishing to the topic `/gpio_controller/gpio_outputs`. For example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "flexiv_msgs/msg/gpio_states.hpp"

namespace gpio_controller {

/** Number of digital IO ports (16 on control box + 2 inside the wrist connector) */
constexpr size_t kIOPorts = 18;

using CmdType = flexiv_msgs::msg::GPIOStates;

class GPIOController : public controller_interface::ControllerInterface
Expand All @@ -43,7 +47,7 @@ class GPIOController : public controller_interface::ControllerInterface
void initMsgs();

// internal commands
std::array<double, 16> digital_outputs_cmd_;
std::array<double, kIOPorts> digital_outputs_cmd_;

// publisher
std::shared_ptr<rclcpp::Publisher<CmdType>> gpio_inputs_publisher_;
Expand Down
8 changes: 4 additions & 4 deletions flexiv_controllers/gpio_controller/src/gpio_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ controller_interface::InterfaceConfiguration GPIOController::command_interface_c
controller_interface::InterfaceConfiguration config;
config.type = controller_interface::interface_configuration_type::INDIVIDUAL;

for (size_t i = 0; i < 16; ++i) {
for (size_t i = 0; i < kIOPorts; ++i) {
config.names.emplace_back("gpio/digital_output_" + std::to_string(i));
}

Expand All @@ -45,7 +45,7 @@ controller_interface::InterfaceConfiguration GPIOController::state_interface_con
controller_interface::InterfaceConfiguration config;
config.type = controller_interface::interface_configuration_type::INDIVIDUAL;

for (size_t i = 0; i < 16; ++i) {
for (size_t i = 0; i < kIOPorts; ++i) {
config.names.emplace_back("gpio/digital_input_" + std::to_string(i));
}

Expand All @@ -56,7 +56,7 @@ controller_interface::return_type GPIOController::update(
const rclcpp::Time& /*time*/, const rclcpp::Duration& /*period*/)
{
// get inputs
for (size_t i = 0; i < 16; ++i) {
for (size_t i = 0; i < kIOPorts; ++i) {
gpio_inputs_msg_.states[i].pin = i;
gpio_inputs_msg_.states[i].state = static_cast<bool>(state_interfaces_[i].get_value());
}
Expand All @@ -82,7 +82,7 @@ controller_interface::CallbackReturn GPIOController::on_configure(
gpio_outputs_command_ = get_node()->create_subscription<CmdType>(
"~/gpio_outputs", rclcpp::SystemDefaultsQoS(), [this](const CmdType::SharedPtr msg) {
for (size_t i = 0; i < msg->states.size(); ++i) {
if (msg->states[i].pin >= 16) {
if (msg->states[i].pin >= kIOPorts) {
RCLCPP_WARN(get_node()->get_logger(),
"Received command for pin %d, but only pins 0-15 are supported.",
msg->states[i].pin);
Expand Down
5 changes: 5 additions & 0 deletions flexiv_description/urdf/rizon10.ros2_control.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<state_interface name="effort"/>
</joint>

<!-- 18 digital IO ports (16 on control box + 2 inside the wrist connector) -->
<gpio name="${prefix}gpio">
<command_interface name="digital_output_0"/>
<command_interface name="digital_output_1"/>
Expand All @@ -160,6 +161,8 @@
<command_interface name="digital_output_13"/>
<command_interface name="digital_output_14"/>
<command_interface name="digital_output_15"/>
<command_interface name="digital_output_16"/>
<command_interface name="digital_output_17"/>

<state_interface name="digital_input_0"/>
<state_interface name="digital_input_1"/>
Expand All @@ -177,6 +180,8 @@
<state_interface name="digital_input_13"/>
<state_interface name="digital_input_14"/>
<state_interface name="digital_input_15"/>
<state_interface name="digital_input_16"/>
<state_interface name="digital_input_17"/>
</gpio>

</ros2_control>
Expand Down
5 changes: 5 additions & 0 deletions flexiv_description/urdf/rizon4.ros2_control.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<state_interface name="effort"/>
</joint>

<!-- 18 digital IO ports (16 on control box + 2 inside the wrist connector) -->
<gpio name="${prefix}gpio">
<command_interface name="digital_output_0"/>
<command_interface name="digital_output_1"/>
Expand All @@ -160,6 +161,8 @@
<command_interface name="digital_output_13"/>
<command_interface name="digital_output_14"/>
<command_interface name="digital_output_15"/>
<command_interface name="digital_output_16"/>
<command_interface name="digital_output_17"/>

<state_interface name="digital_input_0"/>
<state_interface name="digital_input_1"/>
Expand All @@ -177,6 +180,8 @@
<state_interface name="digital_input_13"/>
<state_interface name="digital_input_14"/>
<state_interface name="digital_input_15"/>
<state_interface name="digital_input_16"/>
<state_interface name="digital_input_17"/>
</gpio>

</ros2_control>
Expand Down

0 comments on commit 9e31114

Please sign in to comment.