41 #include <urdf_parser/urdf_parser.h> 43 #include <boost/assign.hpp> 56 , wheel_separation_(0)
57 , drive_motor_gear_ratio_(0)
58 , steer_motor_gear_ratio_(0)
59 , cmd_vel_timeout_(0.5)
60 , base_frame_id_(
"base_link")
61 , enable_odom_tf_(true)
62 , wheel_joints_size_(0)
71 const std::string complete_ns = controller_nh.
getNamespace();
72 std::size_t
id = complete_ns.find_last_of(
"/");
73 name_ = complete_ns.substr(
id + 1);
76 std::string drive_motor_name;
77 controller_nh.
param(
"drive_motor_joint", drive_motor_name, drive_motor_name);
80 std::string steer_motor_name;
81 controller_nh.
param(
"steer_motor_joint", steer_motor_name, steer_motor_name);
86 controller_nh.
param(
"publish_rate", publish_rate, 20.0);
88 << publish_rate <<
"Hz.");
149 if (std::isnan(drive_vel) || std::isnan(steer_vel))
161 const geometry_msgs::Quaternion orientation(
170 odom_pub_->msg_.pose.pose.orientation = orientation;
179 geometry_msgs::TransformStamped& odom_frame =
tf_odom_pub_->msg_.transforms[0];
180 odom_frame.header.stamp = time;
183 odom_frame.transform.rotation = orientation;
191 const double dt = (time - curr_cmd.
stamp).toSec();
201 const double cmd_dt(period.
toSec());
251 "Added values to command. " 265 const std::string& drive_motor_name,
266 const std::string& steer_motor_name)
269 if (!has_wheel_separation)
276 if (!has_wheel_radius)
283 if (!has_drive_motor_gear_ratio)
290 if (!has_steer_motor_gear_ratio)
313 controller_nh.
getParam(
"pose_covariance_diagonal", pose_cov_list);
316 for (
int i = 0; i < pose_cov_list.
size(); ++i)
320 controller_nh.
getParam(
"twist_covariance_diagonal", twist_cov_list);
323 for (
int i = 0; i < twist_cov_list.
size(); ++i)
328 odom_pub_->msg_.header.frame_id =
"odom";
330 odom_pub_->msg_.pose.pose.position.z = 0;
331 odom_pub_->msg_.pose.covariance = boost::assign::list_of
332 (static_cast<double>(pose_cov_list[0])) (0) (0) (0) (0) (0)
333 (0) (
static_cast<double>(pose_cov_list[1])) (0) (0) (0) (0)
334 (0) (0) (
static_cast<double>(pose_cov_list[2])) (0) (0) (0)
335 (0) (0) (0) (
static_cast<double>(pose_cov_list[3])) (0) (0)
336 (0) (0) (0) (0) (
static_cast<double>(pose_cov_list[4])) (0)
337 (0) (0) (0) (0) (0) (
static_cast<double>(pose_cov_list[5]));
338 odom_pub_->msg_.twist.twist.linear.y = 0;
339 odom_pub_->msg_.twist.twist.linear.z = 0;
340 odom_pub_->msg_.twist.twist.angular.x = 0;
341 odom_pub_->msg_.twist.twist.angular.y = 0;
342 odom_pub_->msg_.twist.covariance = boost::assign::list_of
343 (static_cast<double>(twist_cov_list[0])) (0) (0) (0) (0) (0)
344 (0) (
static_cast<double>(twist_cov_list[1])) (0) (0) (0) (0)
345 (0) (0) (
static_cast<double>(twist_cov_list[2])) (0) (0) (0)
346 (0) (0) (0) (
static_cast<double>(twist_cov_list[3])) (0) (0)
347 (0) (0) (0) (0) (
static_cast<double>(twist_cov_list[4])) (0)
348 (0) (0) (0) (0) (0) (
static_cast<double>(twist_cov_list[5]));
353 tf_odom_pub_->msg_.transforms[0].transform.translation.z = 0.0;
355 tf_odom_pub_->msg_.transforms[0].header.frame_id =
"odom";
boost::shared_ptr< realtime_tools::RealtimePublisher< nav_msgs::Odometry > > odom_pub_
Odometry related:
void limit(double &v, double v0, double dt)
Limit the velocity and acceleration.
ros::Duration publish_period_
Odometry related:
#define ROS_DEBUG_STREAM_NAMED(name, args)
#define ROS_ERROR_STREAM_NAMED(name, args)
Velocity command related:
hardware_interface::JointHandle drive_motor_input_
Hardware handles:
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
double getX() const
x position getter
void setGearRatios(double drive_motor_gear_ratio, double steer_motor_gear_ratio)
Sets the gear ratio parameters: gear ratio.
SpeedLimiter limiter_ang_
void cmdVelCallback(const geometry_msgs::Twist &command)
Velocity command callback.
bool has_acceleration_limits
double getVelocity() const
void update(const ros::Time &time, const ros::Duration &period)
Updates controller, i.e. computes the odometry and sets the new velocity commands.
#define ROS_INFO_STREAM_NAMED(name, args)
realtime_tools::RealtimeBuffer< Commands > command_
double getAngular() const
angular velocity getter
bool init(hardware_interface::VelocityJointInterface *hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
Initialize controller.
double drive_motor_gear_ratio_
double getHeading() const
heading getter
void stopping(const ros::Time &time)
Stops controller.
double getY() const
y position getter
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Type const & getType() const
double wheel_radius_
Wheel radius (assuming it's the same for the left and right wheels):
double getLinear() const
linear velocity getter
bool enable_odom_tf_
Whether to publish odometry to tf or not:
bool getParam(const std::string &key, std::string &s) const
SpeedLimiter limiter_lin_
void updateOpenLoop(double linear, double angular, const ros::Time &time)
Updates the odometry class with latest velocity command.
hardware_interface::JointHandle steer_motor_input_
std::string base_frame_id_
Frame to use for the robot base:
double steer_motor_gear_ratio_
JointHandle getHandle(const std::string &name)
DoubleDiffDriveController()
void setCommand(double command)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
boost::shared_ptr< realtime_tools::RealtimePublisher< tf::tfMessage > > tf_odom_pub_
void init(const ros::Time &time)
Initialize the odometry.
#define ROS_INFO_STREAM(args)
const std::string & getNamespace() const
void brake()
Brakes the wheels, i.e. sets the velocity to 0.
void setupRtPublishersMsg(ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
Sets the odometry publishing fields.
ros::Time last_state_publish_time_
ros::Subscriber sub_command_
#define ROS_ERROR_NAMED(name,...)
double wheel_separation_
Wheel separation, wrt the midpoint of the wheel width:
void setWheelsParams(double wheel_radius, double wheel_separation)
Sets the wheels parameters: radius and seperation.
bool update(double drive_motor_vel, double steer_motor_vel, const ros::Time &time)
Updates the odometry class with latest wheels position.
bool setWheelParamsFromUrdf(ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh, const std::string &drive_motor_name, const std::string &steer_motor_name)
Sets odometry parameters from the URDF, i.e. the wheel radius and separation.
double cmd_vel_timeout_
Timeout to consider cmd_vel commands old:
void starting(const ros::Time &time)
Starts controller.