#include "std_srvs/srv/set_bool.hpp"
#include "std_msgs/msg/u_int8.hpp"
#include "a4wd3_open_manipulator/srv/get_error.hpp"
+#include "a4wd3_open_manipulator/srv/ir_temp.hpp"
#define I2C_FILE "/dev/i2c-7"
#define I2C_ADDR (0x60 >> 1)
};
static constexpr double kLimitTolerance = 1e-3;
- void cbTorqueEnable(
- const std::shared_ptr<std_srvs::srv::SetBool::Request> req,
- std::shared_ptr<std_srvs::srv::SetBool::Response> res);
-
- void cbGetError(
- const std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Request> req,
- std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> res);
+ void cbTorqueEnable(const std::shared_ptr<std_srvs::srv::SetBool::Request> req, std::shared_ptr<std_srvs::srv::SetBool::Response> res);
+ void cbGetError(const std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Request> req, std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> res);
+ void cbGetIrTemp(const std::shared_ptr<a4wd3_open_manipulator::srv::IrTemp::Request> req, std::shared_ptr<a4wd3_open_manipulator::srv::IrTemp::Response> res);
void light_callback(const std_msgs::msg::UInt8 msg);
rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr torque_enable_service_;
rclcpp::Service<a4wd3_open_manipulator::srv::GetError>::SharedPtr get_error_service_;
+ rclcpp::Service<a4wd3_open_manipulator::srv::IrTemp>::SharedPtr get_temp_service_;
rclcpp::Subscription<std_msgs::msg::UInt8>::SharedPtr sub_light;
double cmd[NUM_JOINTS] = {NAN, NAN, NAN, NAN, NAN};
return hardware_interface::CallbackReturn::ERROR;
}
- torque_enable_service_ = get_node()->create_service<std_srvs::srv::SetBool>(
- "torque_enable", std::bind(
- &A4wd3OpenManipulatorI2C::cbTorqueEnable, this, std::placeholders::_1,
- std::placeholders::_2));
- get_error_service_ = get_node()->create_service<a4wd3_open_manipulator::srv::GetError>(
- "get_error", std::bind(
- &A4wd3OpenManipulatorI2C::cbGetError, this, std::placeholders::_1,
- std::placeholders::_2));
+ torque_enable_service_ = get_node()->create_service<std_srvs::srv::SetBool>("torque_enable", std::bind(&A4wd3OpenManipulatorI2C::cbTorqueEnable, this, std::placeholders::_1, std::placeholders::_2));
+ get_error_service_ = get_node()->create_service<a4wd3_open_manipulator::srv::GetError>("get_error", std::bind(&A4wd3OpenManipulatorI2C::cbGetError, this, std::placeholders::_1, std::placeholders::_2));
+ get_temp_service_ = get_node()->create_service<a4wd3_open_manipulator::srv::IrTemp>("get_ir_temp", std::bind(&A4wd3OpenManipulatorI2C::cbGetIrTemp, this, std::placeholders::_1, std::placeholders::_2));
sub_light = get_node()->create_subscription<std_msgs::msg::UInt8>("/headlight", rclcpp::SystemDefaultsQoS(), std::bind(&A4wd3OpenManipulatorI2C::light_callback, this, std::placeholders::_1));
RCLCPP_INFO(get_logger(), "Configuration successful");
return 255;
}
-void A4wd3OpenManipulatorI2C::cbTorqueEnable(
- const std::shared_ptr<std_srvs::srv::SetBool::Request> req,
- std::shared_ptr<std_srvs::srv::SetBool::Response> res)
-{
+void A4wd3OpenManipulatorI2C::cbTorqueEnable(const std::shared_ptr<std_srvs::srv::SetBool::Request> req, std::shared_ptr<std_srvs::srv::SetBool::Response> res) {
RCLCPP_INFO(get_logger(), "Setting torque enable=%d", (int)req->data);
res->success = torque_enable(req->data);
}
-void A4wd3OpenManipulatorI2C::cbGetError(
- const std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Request> /*req*/,
- std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> res)
-{
+void A4wd3OpenManipulatorI2C::cbGetError(const std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Request> /*req*/, std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> res) {
RCLCPP_INFO(get_logger(), "Reading Hardware Error Status");
for (int id = 11, i = 0; id <= 15; id++, i++) {
}
}
+// ros2 service call /get_ir_temp a4wd3_open_manipulator/srv/IrTemp
+void A4wd3OpenManipulatorI2C::cbGetIrTemp(const std::shared_ptr<a4wd3_open_manipulator::srv::IrTemp::Request> /*req*/, std::shared_ptr<a4wd3_open_manipulator::srv::IrTemp::Response> res) {
+ int16_t val;
+
+ RCLCPP_INFO(get_logger(), "Reading IR temperature");
+ if (dynamixel_readword(0x21, 0x2, &val) != 1) {
+ RCLCPP_ERROR(get_logger(), "I2C dynamixel reading ir temperature");
+ val = 0xffff;
+ }
+ res->temp = val;
+}
+
+
} // namespace a4wd3_open_manipulator
#include "pluginlib/class_list_macros.hpp"