17 std::string data_binary =
"";
18 for(
int i=0; i<length*8; i++) {
19 data_binary.append(std::to_string((data>>i)&0x01));
32 ROS_INFO(
"set digital output %d to %d", req.io, req.active);
34 if(req.io>=1 && req.io<=4) {
35 if(req.active ==
true) {
37 }
else if (req.active ==
false) {
43 ROS_WARN(
"digital pin should be in 1-4, now is %d", req.io);
79 ROS_INFO(
"can_pub: %s, can_sub: %s, can_id: %d", send_topic_.c_str(), receive_topic_.c_str(),
can_id_);
99 status.summary(diagnostic_msgs::DiagnosticStatus::OK,
"OK");
101 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Amps Limit currently active");
104 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Motor stalled");
107 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Loop Error detected");
111 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Safety Stop active");
114 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Forward Limit triggered");
117 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Reverse Limit triggered");
120 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Amps Trigger activated");
141 status.summary(diagnostic_msgs::DiagnosticStatus::OK,
"OK");
143 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Amps Limit currently active");
146 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Motor stalled");
149 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Loop Error detected");
152 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Safety Stop active");
155 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Forward Limit triggered");
158 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Reverse Limit triggered");
161 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Amps Trigger activated");
177 std::string contorl_mode =
"unknown";
180 contorl_mode =
"Serial mode";
183 contorl_mode =
"Pulse mode";
186 contorl_mode =
"Analog mode";
189 status.add(
"Control mode", contorl_mode);
191 status.summary(diagnostic_msgs::DiagnosticStatus::OK,
"OK");
192 if(contorl_mode ==
"unknown") {
193 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"unknown control mode");
196 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Power stage off");
199 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Stall detected");
202 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"At limit");
205 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Unused");
208 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::OK,
"MicroBasic script running");
224 status.summary(diagnostic_msgs::DiagnosticStatus::OK,
"OK");
226 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Overheat");
229 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Overvoltage");
232 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Undervoltage");
235 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Short circuit");
238 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Emergency stop");
241 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Brushless sensor fault");
244 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"MOSFET failure");
247 status.mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Default configuration loaded at startup");
256 if((msg->data[0]&0xF0) ==
kQuery<<4) {
257 uint16_t index = (msg->data[2]<<8) + msg->data[1];
258 uint8_t sub_index = msg->data[3];
264 int16_t temp_current_x10;
265 memcpy(&temp_current_x10, msg->data.data()+4, 2);
271 memcpy(&
motor_status_[sub_index-1].counter, msg->data.data()+4, 4);
306 uint16_t index = (msg->data[2]<<8) + msg->data[1];
307 uint8_t sub_index = msg->data[3];
322 bool success =
false;
420 can_msgs::Frame frame;
425 frame.is_extended = 0;
430 buf[0] = (type<<4) + ((4-data_length) << 2);
433 memcpy(buf+1, &index, 2);
434 memcpy(buf+3, &sub_index, 1);
437 memcpy(buf+4, &data, data_length);
439 for(
int i=0; i<8; i++) {
440 frame.data[i] = buf[i];
void registerInterface(T *iface)
bool Query(RoboteqCanOpenObjectDictionary query, uint8_t sub_index, uint8_t data_length)
void ControllerCheck(diagnostic_updater::DiagnosticStatusWrapper &status)
ros::NodeHandle private_nh_
std::string ToBinary(size_t data, uint8_t length)
void publish(const boost::shared_ptr< M > &message) const
MotorStatus motor_status_[2]
void Initialize(std::string node_name, ros::NodeHandle &nh, ros::NodeHandle &private_nh)
ros::ServiceServer set_io_service_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
diagnostic_updater::Updater diagnostic_updater_
void CanReceiveCallback(const can_msgs::Frame::ConstPtr &msg)
const uint16_t kCanOpenSendHeader
void UpdateHardwareStatus()
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
std::string receive_topic_
void StatusCheck(diagnostic_updater::DiagnosticStatusWrapper &status)
const uint16_t kCanOpenRecvHeader
void ControllerTimerCallback(const ros::TimerEvent &)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void RegisterControlInterfaces()
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void registerHandle(const JointStateHandle &handle)
void RightMotorCheck(diagnostic_updater::DiagnosticStatusWrapper &status)
bool SetDigitalOutputCB(caster_base::SetDigitalOutput::Request &req, caster_base::SetDigitalOutput::Response &res)
hardware_interface::JointStateInterface joint_state_interface_
bool Command(RoboteqCanOpenObjectDictionary query, uint8_t sub_index, uint32_t data, uint8_t data_length)
std::string right_wheel_joint_
RoboteqCanOpenObjectDictionary
struct iqr::CasterHardware::Joint joints_[2]
void update(const ros::Time &time, const ros::Duration &period, bool reset_controllers=false)
std::string left_wheel_joint_
hardware_interface::VelocityJointInterface velocity_joint_interface_
void LeftMotorCheck(diagnostic_updater::DiagnosticStatusWrapper &status)
void WriteCommandsToHardware()
void SendCanOpenData(uint32_t node_id, RoboteqClientCommandType type, RoboteqCanOpenObjectDictionary index, uint8_t sub_index, uint32_t data, uint8_t data_length)
controller_manager::ControllerManager * controller_manager_