66 #include <diagnostic_msgs/DiagnosticStatus.h> 68 #include <geometry_msgs/Twist.h> 69 #include <nav_msgs/Odometry.h> 71 #include <cob_msgs/EmergencyStopState.h> 72 #include <control_msgs/JointTrajectoryControllerState.h> 137 is_initialized_bool_ =
false;
138 is_ucarr_geom_initialized_bool_ =
false;
139 broadcast_tf_ =
true;
142 sample_time_ = 0.020;
144 drive_chain_diagnostic_ = diagnostic_status_lookup_.OK;
152 ROS_INFO(
"Timeout loaded from Parameter-Server is: %fs", timeout_);
156 ROS_WARN(
"No parameter timeout on Parameter-Server. Using default: 1.0s");
159 if ( timeout_ < sample_time_ )
161 ROS_WARN(
"Specified timeout < sample_time. Setting timeout to sample_time = %fs", sample_time_);
165 if (n.
hasParam(
"max_trans_velocity"))
167 n.
getParam(
"max_trans_velocity", max_vel_trans_);
168 ROS_INFO(
"Max translational velocity loaded from Parameter-Server is: %fs", max_vel_trans_);
172 ROS_WARN(
"No parameter max_trans_velocity on Parameter-Server. Using default: 1.1 m/s");
173 max_vel_trans_ = 1.1;
177 n.
getParam(
"max_rot_velocity", max_vel_rot_);
178 ROS_INFO(
"Max rotational velocity loaded from Parameter-Server is: %fs", max_vel_rot_);
182 ROS_WARN(
"No parameter max_rot_velocity on Parameter-Server. Using default: 1.8 rad/s");
187 n.
getParam(
"broadcast_tf", broadcast_tf_);
190 const std::string frame_id = n.
param(
"frame_id", std::string(
"odom"));
191 const std::string child_frame_id = n.
param(
"child_frame_id", std::string(
"base_footprint"));
192 const double cov_pose = n.
param(
"cov_pose", 0.1);
193 const double cov_twist = n.
param(
"cov_twist", 0.1);
195 odom_tracker_ =
new OdometryTracker(frame_id, child_frame_id, cov_pose, cov_twist);
198 std::vector<UndercarriageCtrl::WheelParams> wps;
203 m_iNumWheels = wps.size();
204 m_iNumJoints = m_iNumWheels * 2;
207 is_ucarr_geom_initialized_bool_ =
true;
213 topic_pub_controller_joint_command_ = n.
advertise<control_msgs::JointTrajectoryControllerState> (
"joint_command", 1);
215 topic_pub_odometry_ = n.
advertise<nav_msgs::Odometry>(
"odometry", 1);
234 if (is_ucarr_geom_initialized_bool_)
235 is_initialized_bool_ =
true;
242 topic_sub_CMD_pltf_twist_.
shutdown();
243 topic_sub_EM_stop_state_.
shutdown();
244 topic_sub_drive_diagnostic_.
shutdown();
245 topic_sub_joint_controller_states_.
shutdown();
247 timer_ctrl_step_.
stop();
254 if(is_initialized_bool_)
255 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"");
257 stat.
summary(diagnostic_msgs::DiagnosticStatus::WARN,
"");
258 stat.
add(
"Initialized", is_initialized_bool_);
267 if( (fabs(msg->linear.x) > max_vel_trans_) || (fabs(msg->linear.y) > max_vel_trans_) || (fabs(msg->angular.z) > max_vel_rot_)){
268 if(fabs(msg->linear.x) > max_vel_trans_){
270 ", which is bigger than the maximal allowed translational velocity: " << max_vel_trans_ <<
" so stop the robot");
272 if(fabs(msg->linear.y) > max_vel_trans_){
274 ", which is bigger than the maximal allowed translational velocity: " << max_vel_trans_ <<
" so stop the robot");
276 if(fabs(msg->angular.z) > max_vel_rot_){
278 ", which is bigger than the maximal allowed rotational velocity: " << max_vel_rot_ <<
" so stop the robot");
286 pltState.
setVelX(msg->linear.x);
287 pltState.
setVelY(msg->linear.y);
294 if (is_initialized_bool_ && drive_chain_diagnostic_ == diagnostic_status_lookup_.OK){
295 ROS_DEBUG(
"received new velocity command [cmdVelX=%3.5f,cmdVelY=%3.5f,cmdVelTh=%3.5f]",
296 msg->linear.x, msg->linear.y, msg->angular.z);
300 has_target = msg->linear.x!= 0 || msg->linear.y!=0 || msg->angular.z != 0;
310 ROS_DEBUG(
"Forced platform-velocity cmds to zero");
317 int current_EM_state = msg->emergency_state;
319 if (current_EM_state == msg->EMFREE){
321 if (is_initialized_bool_){
323 ROS_DEBUG(
"Undercarriage Controller EM-Stop released");
327 ROS_DEBUG(
"Undercarriage Controller stopped due to EM-Stop");
334 ROS_DEBUG(
"Forced platform-velocity cmds to zero");
344 control_msgs::JointTrajectoryControllerState joint_state_cmd;
352 joint_state_cmd.desired.positions.resize(m_iNumJoints);
353 joint_state_cmd.desired.velocities.resize(m_iNumJoints);
357 joint_state_cmd.joint_names.push_back(
"fl_caster_r_wheel_joint");
358 joint_state_cmd.joint_names.push_back(
"fl_caster_rotation_joint");
359 joint_state_cmd.joint_names.push_back(
"bl_caster_r_wheel_joint");
360 joint_state_cmd.joint_names.push_back(
"bl_caster_rotation_joint");
361 joint_state_cmd.joint_names.push_back(
"br_caster_r_wheel_joint");
362 joint_state_cmd.joint_names.push_back(
"br_caster_rotation_joint");
363 joint_state_cmd.joint_names.push_back(
"fr_caster_r_wheel_joint");
364 joint_state_cmd.joint_names.push_back(
"fr_caster_rotation_joint");
365 joint_state_cmd.joint_names.resize(m_iNumJoints);
370 joint_state_cmd.desired.positions[i] = 0.0;
371 joint_state_cmd.desired.velocities[i] = 0.0;
376 drive_chain_diagnostic_ = msg->level;
379 if (is_initialized_bool_){
381 if (drive_chain_diagnostic_ != diagnostic_status_lookup_.OK){
384 ROS_DEBUG(
"drive chain not availlable: halt Controller");
394 ROS_DEBUG(
"Forced platform-velocity cmds to zero");
401 if(drive_chain_diagnostic_ != diagnostic_status_lookup_.WARN)
404 topic_pub_controller_joint_command_.
publish(joint_state_cmd);
410 int num_joints = msg->joint_names.size();
413 std::vector<WheelState> wStates;
416 joint_state_odom_stamp_ = msg->header.stamp;
418 for(
int i = 0; i < num_joints; i++)
422 if(msg->joint_names[i] ==
"fl_caster_r_wheel_joint")
424 wStates[0].dVelGearDriveRadS = msg->actual.velocities[i];
426 if(msg->joint_names[i] ==
"bl_caster_r_wheel_joint")
428 wStates[1].dVelGearDriveRadS = msg->actual.velocities[i];
430 if(msg->joint_names[i] ==
"br_caster_r_wheel_joint")
432 wStates[2].dVelGearDriveRadS = msg->actual.velocities[i];
434 if(msg->joint_names[i] ==
"fr_caster_r_wheel_joint")
436 wStates[3].dVelGearDriveRadS = msg->actual.velocities[i];
438 if(msg->joint_names[i] ==
"fl_caster_rotation_joint")
440 wStates[0].dAngGearSteerRad = msg->actual.positions[i];
441 wStates[0].dVelGearSteerRadS = msg->actual.velocities[i];
443 if(msg->joint_names[i] ==
"bl_caster_rotation_joint")
445 wStates[1].dAngGearSteerRad = msg->actual.positions[i];
446 wStates[1].dVelGearSteerRadS = msg->actual.velocities[i];
448 if(msg->joint_names[i] ==
"br_caster_rotation_joint")
450 wStates[2].dAngGearSteerRad = msg->actual.positions[i];
451 wStates[2].dVelGearSteerRadS = msg->actual.velocities[i];
453 if(msg->joint_names[i] ==
"fr_caster_rotation_joint")
455 wStates[3].dAngGearSteerRad = msg->actual.positions[i];
456 wStates[3].dVelGearSteerRadS = msg->actual.velocities[i];
487 int main(
int argc,
char** argv)
490 ros::init(argc, argv,
"undercarriage_ctrl");
499 ROS_INFO(
"New Undercarriage control successfully initialized.");
501 ROS_FATAL(
"Undercarriage control initialization failed!");
502 throw std::runtime_error(
"Undercarriage control initialization failed, check yaml-Files!");
523 std::vector<WheelCommand> wStates;
527 control_msgs::JointTrajectoryControllerState joint_state_cmd;
546 for(
int i = 0; i < wStates.size(); i++){
547 wStates[i].dAngGearSteerRad = 0.0;
548 wStates[i].dVelGearSteerRadS = 0.0;
565 joint_state_cmd.desired.velocities.resize(
m_iNumJoints);
567 joint_state_cmd.joint_names.push_back(
"fl_caster_r_wheel_joint");
568 joint_state_cmd.joint_names.push_back(
"fl_caster_rotation_joint");
569 joint_state_cmd.joint_names.push_back(
"bl_caster_r_wheel_joint");
570 joint_state_cmd.joint_names.push_back(
"bl_caster_rotation_joint");
571 joint_state_cmd.joint_names.push_back(
"br_caster_r_wheel_joint");
572 joint_state_cmd.joint_names.push_back(
"br_caster_rotation_joint");
573 joint_state_cmd.joint_names.push_back(
"fr_caster_r_wheel_joint");
574 joint_state_cmd.joint_names.push_back(
"fr_caster_rotation_joint");
583 if( i == 1 || i == 3 || i == 5 || i == 7)
585 joint_state_cmd.desired.positions[i] = wStates[j].dAngGearSteerRad;
586 joint_state_cmd.desired.velocities[i] = wStates[j].dVelGearSteerRadS;
591 joint_state_cmd.desired.positions[i] = 0.0;
592 joint_state_cmd.desired.velocities[i] = wStates[k].dVelGearDriveRadS;
598 joint_state_cmd.desired.positions[i] = 0.0;
599 joint_state_cmd.desired.velocities[i] = 0.0;
632 geometry_msgs::TransformStamped odom_tf;
634 odom_tf.header.stamp = odom_top.header.stamp;
635 odom_tf.header.frame_id =
"/odom_combined";
636 odom_tf.child_frame_id =
"/base_footprint";
638 odom_tf.transform.translation.x = odom_top.pose.pose.position.x;
639 odom_tf.transform.translation.y = odom_top.pose.pose.position.y;
640 odom_tf.transform.rotation = odom_top.pose.pose.orientation;
655 std::vector<WheelState> wStates;
658 std::vector<WheelCommand> wCommands;
void topicCallbackEMStop(const cob_msgs::EmergencyStopState::ConstPtr &msg)
bool parseWheelParams(std::vector< UndercarriageGeom::WheelParams > ¶ms, const ros::NodeHandle &nh, bool read_urdf=true)
ros::Subscriber topic_sub_joint_controller_states_
virtual void calcDirect(PlatformState &state) const
void setEMStopActive(bool bEMStopActive)
void setTarget(const PlatformState &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 setHardwareID(const std::string &hwid)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
tf::TransformBroadcaster tf_broadcast_odometry_
int main(int argc, char **argv)
UndercarriageCtrl * ucar_ctrl_
void add(const std::string &name, TaskFunction f)
ROSCPP_DECL const std::string & getName()
virtual void updateWheelStates(const std::vector< WheelState > &states)
diagnostic_msgs::DiagnosticStatus diagnostic_status_lookup_
void topicCallbackTwistCmd(const geometry_msgs::Twist::ConstPtr &msg)
const nav_msgs::Odometry & getOdometry()
ros::Time joint_state_odom_stamp_
void calcControlStep(std::vector< WheelCommand > &commands, double dCmdRateS, bool reset)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::Subscriber topic_sub_CMD_pltf_twist_
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
void track(const ros::Time &now, double dt, double vel_x, double vel_y, double vel_theta)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_DEBUG_STREAM(args)
ros::Subscriber topic_sub_drive_diagnostic_
void timerCallbackCtrlStep(const ros::TimerEvent &e)
diagnostic_updater::Updater updater_
ros::Publisher topic_pub_joint_state_cmd_
OdometryTracker * odom_tracker_
void diag_init(diagnostic_updater::DiagnosticStatusWrapper &stat)
ros::Subscriber topic_sub_EM_stop_state_
int drive_chain_diagnostic_
bool getParam(const std::string &key, std::string &s) const
void topicCallbackDiagnostic(const diagnostic_msgs::DiagnosticStatus::ConstPtr &msg)
ros::Publisher topic_pub_controller_joint_command_
bool is_initialized_bool_
void add(const std::string &key, const T &val)
bool hasParam(const std::string &key) const
ros::Timer timer_ctrl_step_
bool is_ucarr_geom_initialized_bool_
ros::Publisher topic_pub_odometry_
void topicCallbackJointControllerStates(const control_msgs::JointTrajectoryControllerState::ConstPtr &msg)