38 : DiagnosticTask(
"Roboteq")
40 , private_mNh(private_nh)
54 std::vector<std::string> joint_list;
57 private_nh.
getParam(
"joint", joint_list);
62 joint_list.push_back(
"right_wheel_joint");
63 joint_list.push_back(
"left_wheel_joint");
64 private_nh.
setParam(
"joint", joint_list);
73 for(
unsigned i=0; i < joint_list.size(); ++i)
75 string motor_name = joint_list.at(i);
84 if(private_nh.
hasParam(motor_name +
"/number"))
86 private_nh.
getParam(motor_name +
"/number", number);
91 private_nh.
setParam(motor_name +
"/number", number);
100 for(
int i = 0; i < 6; ++i)
104 for(
int i = 0; i < 6; ++i)
108 for(
int i = 0; i < 2; ++i)
130 bool status = (int)msg.get()->data;
149 std::vector<std::string> fields;
150 boost::split(fields, trn, boost::algorithm::is_any_of(
":"));
176 dynamic_reconfigure::Server<roboteq_control::RoboteqControllerConfig>::CallbackType cb_controller = boost::bind(&
Roboteq::reconfigureCBController,
this, _1, _2);
194 for (vector<Motor*>::iterator it =
mMotor.begin() ; it !=
mMotor.end(); ++it)
217 for (vector<Motor*>::iterator it =
mMotor.begin() ; it !=
mMotor.end(); ++it)
274 unsigned char fault = boost::lexical_cast<
unsigned int>(fault_flag);
275 memcpy(&
_fault, &fault,
sizeof(fault));
278 unsigned char status = boost::lexical_cast<
unsigned int>(status_flag);
279 memcpy(&
_flag, &status,
sizeof(status));
284 _volts_five = boost::lexical_cast<
double>(supply_voltage_3) / 1000;
287 _temp_mcu = boost::lexical_cast<
double>(temperature_1);
289 _temp_bridge = boost::lexical_cast<
double>(temperature_2);
291 catch (std::bad_cast& e)
293 ROS_WARN(
"Failure parsing feedback data. Dropping message.");
304 std::vector<std::string> motors[
mMotor.size()];
305 std::vector<std::string> fields;
311 boost::split(fields, str_status, boost::algorithm::is_any_of(
":"));
312 for(
int i = 0; i < fields.size(); ++i) {
313 motors[i].push_back(fields[i]);
318 boost::split(fields, str_motor, boost::algorithm::is_any_of(
":"));
319 for(
int i = 0; i < fields.size(); ++i) {
320 motors[i].push_back(fields[i]);
325 boost::split(fields, str_feedback, boost::algorithm::is_any_of(
":"));
326 for(
int i = 0; i < fields.size(); ++i) {
327 motors[i].push_back(fields[i]);
332 boost::split(fields, str_loop_error, boost::algorithm::is_any_of(
":"));
333 for(
int i = 0; i < fields.size(); ++i) {
334 motors[i].push_back(fields[i]);
339 boost::split(fields, str_motor_power, boost::algorithm::is_any_of(
":"));
340 for(
int i = 0; i < fields.size(); ++i) {
341 motors[i].push_back(fields[i]);
346 for(
int i = 0; i < fields.size(); ++i) {
347 motors[i].push_back(str_voltage_supply);
352 boost::split(fields, str_motor_amps, boost::algorithm::is_any_of(
":"));
353 for(
int i = 0; i < fields.size(); ++i) {
354 motors[i].push_back(fields[i]);
359 boost::split(fields, str_motor_battery_amps, boost::algorithm::is_any_of(
":"));
360 for(
int i = 0; i < fields.size(); ++i) {
361 motors[i].push_back(fields[i]);
366 boost::split(fields, str_position_encoder_absolute, boost::algorithm::is_any_of(
":"));
367 for(
int i = 0; i < fields.size(); ++i) {
368 motors[i].push_back(fields[i]);
373 boost::split(fields, str_motor_track, boost::algorithm::is_any_of(
":"));
374 for(
int i = 0; i < fields.size(); ++i) {
375 motors[i].push_back(fields[i]);
380 for(
int i = 0; i <
mMotor.size(); ++i) {
382 unsigned int idx =
mMotor[i]->mNumber-1;
384 mMotor[i]->readVector(motors[idx]);
398 std::vector<std::string> fields;
401 boost::split(fields, pulse_in, boost::algorithm::is_any_of(
":"));
404 for(
int i = 0; i < fields.size(); ++i)
408 msg_peripheral.pulse_in.push_back(boost::lexical_cast<unsigned int>(fields[i]));
410 catch (std::bad_cast& e)
417 boost::split(fields, analog, boost::algorithm::is_any_of(
":"));
420 for(
int i = 0; i < fields.size(); ++i)
424 msg_peripheral.analog.push_back(boost::lexical_cast<double>(fields[i]) / 1000.0);
426 catch (std::bad_cast& e)
434 boost::split(fields, digital_in, boost::algorithm::is_any_of(
":"));
437 for(
int i = 0; i < fields.size(); ++i)
441 msg_peripheral.digital_in.push_back(boost::lexical_cast<unsigned int>(fields[i]));
443 catch (std::bad_cast& e)
450 unsigned int num = 0;
453 num = boost::lexical_cast<
unsigned int>(digital_out);
455 catch (std::bad_cast& e)
462 for(
int i = 0; i < 8; ++i)
476 for (vector<Motor*>::iterator it =
mMotor.begin() ; it !=
mMotor.end(); ++it)
485 bool Roboteq::prepareSwitch(
const std::list<hardware_interface::ControllerInfo>& start_list,
const std::list<hardware_interface::ControllerInfo>& stop_list)
491 void Roboteq::doSwitch(
const std::list<hardware_interface::ControllerInfo>& start_list,
const std::list<hardware_interface::ControllerInfo>& stop_list)
494 for(std::list<hardware_interface::ControllerInfo>::const_iterator it = stop_list.begin(); it != stop_list.end(); ++it)
498 for (std::set<std::string>::const_iterator res_it = iface_res.
resources.begin(); res_it != iface_res.
resources.end(); ++res_it)
502 for (vector<Motor*>::iterator m_it =
mMotor.begin() ; m_it !=
mMotor.end(); ++m_it)
505 if(motor->
getName().compare(*res_it) == 0)
517 for(std::list<hardware_interface::ControllerInfo>::const_iterator it = start_list.begin(); it != start_list.end(); ++it)
521 for (std::set<std::string>::const_iterator res_it = iface_res.
resources.begin(); res_it != iface_res.
resources.end(); ++res_it)
525 for (vector<Motor*>::iterator m_it =
mMotor.begin() ; m_it !=
mMotor.end(); ++m_it)
528 if(motor->
getName().compare(*res_it) == 0)
563 stat.
add(
"Mode", mode);
569 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Board ready!");
573 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Power stage OFF");
578 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Stall detect");
583 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"At limit");
588 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Brushless sensor fault");
593 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::WARN,
"Emergency stop");
598 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"MOSFET failure");
608 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Over voltage");
613 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Under voltage");
618 stat.
mergeSummary(diagnostic_msgs::DiagnosticStatus::ERROR,
"Short circuit");
628 unsigned int tmp_pwm = boost::lexical_cast<
unsigned int>(str_pwm);
629 double pwm = ((double) tmp_pwm) / 10.0;
635 unsigned int tmp_ovl = boost::lexical_cast<
unsigned int>(str_ovl);
636 double ovl = ((double) tmp_ovl) / 10.0;
642 unsigned int tmp_ovh = boost::lexical_cast<
unsigned int>(str_ovh);
643 double ovh = ((double) tmp_ovh) / 10.0;
649 unsigned int tmp_uvl = boost::lexical_cast<
unsigned int>(str_uvl);
650 double uvl = ((double) tmp_uvl) / 10.0;
656 int break_delay = boost::lexical_cast<
unsigned int>(str_break);
663 int mixed = boost::lexical_cast<
unsigned int>(str_mxd);
667 }
catch (std::bad_cast& e)
669 ROS_WARN_STREAM(
"Failure parsing feedback data. Dropping message." << e.what());
685 if(config.restore_defaults)
688 config.restore_defaults =
false;
693 if(config.factory_reset)
696 config.factory_reset =
false;
699 config.load_roboteq =
true;
702 if(config.load_from_eeprom)
705 config.load_from_eeprom =
false;
708 config.load_roboteq =
true;
711 if(config.load_roboteq)
714 config.load_roboteq =
false;
721 if(config.store_in_eeprom)
724 config.store_in_eeprom =
false;
733 int pwm = config.pwm_frequency * 10;
740 int ovl = config.over_voltage_limit * 10;
747 int ovh = config.over_voltage_hysteresis * 10;
754 int uvl = config.under_voltage_limit * 10;
777 std::transform(req.service.begin(), req.service.end(), req.service.begin(), ::tolower);
779 if(req.service.compare(
"info") == 0)
781 msg.information =
"\nBoard type: " +
_type +
"\n" 782 "Name board: " +
_model +
"\n" 784 "UID: " +
_uid +
"\n";
786 else if(req.service.compare(
"reset") == 0)
791 msg.information =
"System reset";
793 else if(req.service.compare(
"save") == 0)
798 msg.information =
"Parameters saved";
802 msg.information =
"\nList of commands availabes: \n" 803 "* info - information about this board \n" 804 "* reset - " +
_model +
" board software reset\n" 805 "* save - Save all paramters in EEPROM \n" 806 "* help - this help.";
bool script(bool status)
script Run and stop the script inside the Roboteq
serial_controller * mSerial
void read(const ros::Time &time, const ros::Duration &period)
bool setParam(string msg, string params="")
Roboteq(const ros::NodeHandle &nh, const ros::NodeHandle &private_nh, serial_controller *serial)
Roboteq The Roboteq board controller write and read messages about the motor state.
void publish(const boost::shared_ptr< M > &message) const
void summary(unsigned char lvl, const std::string s)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void doSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list)
std::set< std::string > resources
hardware_interface::JointStateHandle joint_state_handle
std::vector< GPIOAnalogConfigurator * > _param_analog
double first_read_pos_[2]
ros::Publisher pub_peripheral
void reconfigureCBController(roboteq_control::RoboteqControllerConfig &config, uint32_t level)
reconfigureCBEncoder when the dynamic reconfigurator change some values start this method ...
hardware_interface::JointHandle joint_handle
roboteq_control::Peripheral msg_peripheral
uint8_t brushless_sensor_fault
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
urdf::Model model
URDF information about robot.
void write(const ros::Time &time, const ros::Duration &period)
bool echo(bool type)
echo Enable or disable the echo message
bool service_Callback(roboteq_control::Service::Request &req, roboteq_control::Service::Response &msg_system)
service_Callback Internal service to require information from the board connected ...
void initializeDiagnostic()
bool factoryReset()
factoryReset Factory reset of Roboteq board
std::vector< GPIOEncoderConfigurator * > _param_encoder
string getName()
getName the name of the motor
uint8_t microbasic_running
roboteq_control::RoboteqControllerConfig _last_controller_config
void updateDiagnostics()
updateDiagnostics
void writeCommandsToHardware(ros::Duration period)
writeCommandsToHardware Write a command to the hardware interface
void getRoboteqInformation()
getRoboteqInformation Load basic information from roboteq board
std::vector< Motor * > mMotor
ros::NodeHandle private_mNh
bool _first
ROS Control interfaces.
void reset()
reset Reset the Roboteq board
void getControllerFromRoboteq()
getPIDFromRoboteq Load PID parameters from Roboteq board
bool setup_controller
Setup variable.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool initParam(const std::string ¶m)
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
void registerHandle(const JointStateHandle &handle)
void connectionCallback(const ros::SingleSubscriberPublisher &pub)
connectionCallback Check how many subscribers are connected
string getParam(string msg, string params="")
void mergeSummary(unsigned char lvl, const std::string s)
void setupLimits(urdf::Model model)
setupLimits setup the maximum velocity, positio and effort
bool command(string msg, string params="", string type="!")
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
bool prepareSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list)
roboteq_control::RoboteqControllerConfig default_controller_config
bool getParam(const std::string &key, std::string &s) const
std::vector< GPIOPulseConfigurator * > _param_pulse
bool loadFromEEPROM()
loadFromEEPROM
string getQuery(string msg, string params="")
void initialize()
initialize the roboteq controller
bool saveInEEPROM()
saveInEEPROM The EESAV it's a real-time Command must be used to copy the RAM array to Flash...
void initializeInterfaces(hardware_interface::JointStateInterface &joint_state_interface, hardware_interface::VelocityJointInterface &velocity_joint_interface)
initializeInterfaces Initialize all motors. Add all Control Interface availbles and add in diagnostic...
void mergeSummaryf(unsigned char lvl, const char *format,...)
~Roboteq()
The deconstructor.
void add(const std::string &key, const T &val)
bool hasParam(const std::string &key) const
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
run Diagnostic thread called every request
void switchController(string type)
switchController Switch the controller from different type of ros controller
void initializeMotor(bool load_from_board)
initializeMotor Initialization oh motor, this routine load parameter from ros server or load from rob...
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
void stop_Callback(const std_msgs::Bool::ConstPtr &msg)
dynamic_reconfigure::Server< roboteq_control::RoboteqControllerConfig > * ds_controller
Dynamic reconfigure PID.
ros::ServiceServer srv_board