diff --git a/examples/sas_robot_driver_example_main.cpp b/examples/sas_robot_driver_example_main.cpp index f349789..a4dcf0f 100644 --- a/examples/sas_robot_driver_example_main.cpp +++ b/examples/sas_robot_driver_example_main.cpp @@ -63,6 +63,15 @@ int main(int,char**) assert((target_joint_positions == robot_driver_example.get_joint_positions())); + // Tool GPIO: default-initialised to false, and the base implementation stores what is set. + if(robot_driver_example.get_tool_gpio() != std::array{false, false}) + throw std::runtime_error("sas_robot_driver_example_main::Tool GPIO should default to {false, false}."); + robot_driver_example.set_tool_gpio({true, false}); + if(robot_driver_example.get_tool_gpio() != std::array{true, false}) + throw std::runtime_error("sas_robot_driver_example_main::Tool GPIO round-trip failed."); + std::cout << "Tool GPIO after change: " << robot_driver_example.get_tool_gpio()[0] << " " + << robot_driver_example.get_tool_gpio()[1] << std::endl; + robot_driver_example.deinitialize(); robot_driver_example.disconnect(); diff --git a/include/marinholab/sas/core/sas_robot_driver.hpp b/include/marinholab/sas/core/sas_robot_driver.hpp index 20eca4a..ff7f3ff 100644 --- a/include/marinholab/sas/core/sas_robot_driver.hpp +++ b/include/marinholab/sas/core/sas_robot_driver.hpp @@ -27,6 +27,8 @@ # 1. Juan Jose Quiroz Omana (juanjose.quirozomana@manchester.ac.uk) # Added the Watchdog functionaly initially proposed in # https://github.com/SmartArmStack/sas_core/pull/1 +# 2. Erwin Lopez (erwin.lopez@manchester.ac.uk) +# Added functionality to control tool gpio */ /** @@ -37,6 +39,7 @@ * implement to interact with hardware. The header also contains watchdog * management used by driver implementations. */ +#include #include #include #include @@ -63,6 +66,7 @@ class RobotDriver std::tuple joint_limits_; Eigen::VectorXd joint_velocities_; Eigen::VectorXd joint_torques_; + std::array tool_gpio_{}; std::unique_ptr clock_; std::unique_ptr watchdog_thread_; @@ -158,6 +162,20 @@ class RobotDriver */ virtual void set_joint_limits(const std::tuple& joint_limits); + /** + * @brief Get the last commanded tool (wrist) digital output values + * @note The default implementation returns the value stored by set_tool_gpio(). Drivers may override it. + * @return Array of boolean values, one per digital pin + */ + virtual std::array get_tool_gpio(); + + /** + * @brief Set the tool (wrist) digital output values + * @note The default implementation only stores the value. Drivers override it to command the hardware. + * @param tool_gpio Array of boolean values, one per digital pin + */ + virtual void set_tool_gpio(const std::array& tool_gpio); + /** * @brief Start the watchdog thread with the given period * @param period Watchdog period as nanoseconds diff --git a/src/sas_robot_driver.cpp b/src/sas_robot_driver.cpp index 49bd471..e1b1905 100644 --- a/src/sas_robot_driver.cpp +++ b/src/sas_robot_driver.cpp @@ -25,6 +25,8 @@ # 1. Juan Jose Quiroz Omana (juanjose.quirozomana@manchester.ac.uk) # Added the Watchdog functionality initially proposed in # https://github.com/SmartArmStack/sas_core/pull/1 +# 2. Erwin Lopez (erwin.lopez@manchester.ac.uk) +# Added functionality to control tool gpio #*/ /** @@ -90,6 +92,16 @@ void RobotDriver::set_joint_limits(const std::tuple RobotDriver::get_tool_gpio() +{ + return tool_gpio_; +} + +void RobotDriver::set_tool_gpio(const std::array& tool_gpio) +{ + tool_gpio_ = tool_gpio; +} + /** * @brief RobotDriver::_watchdog_thread_function throws an exception if the elapsed time since the last trigger