47 DiffDriveBaseController::DiffDriveBaseController() :
53 odom_.pose.pose.orientation.z = 0.0;
54 odom_.pose.pose.orientation.w = 1.0;
77 std::string l_name, r_name;
78 nh.
param<std::string>(
"l_wheel_joint", l_name,
"l_wheel_joint");
79 nh.
param<std::string>(
"r_wheel_joint", r_name,
"r_wheel_joint");
82 if (left_ == NULL ||
right_ == NULL)
101 nh.
param<std::string>(
"odometry_frame",
odom_.header.frame_id,
"odom");
104 nh.
param<std::string>(
"base_frame",
odom_.child_frame_id,
"base_link");
112 nh.
param<
double>(
"timeout", t, 0.25);
127 odom_pub_ = n.advertise<nav_msgs::Odometry>(
"odom", 10);
132 double publish_frequency;
133 nh.
param<
double>(
"publish_frequency", publish_frequency, 100.0);
141 if (safety_scaling_distance_ > 0.0)
143 scan_sub_ = n.subscribe<sensor_msgs::LaserScan>(
"base_scan", 1,
151 nh.
param(
"autostart", autostart,
false);
162 ROS_ERROR_NAMED(
"BaseController",
"Unable to accept command, not initialized.");
166 if (std::isfinite(msg->linear.x) && std::isfinite(msg->angular.z))
186 ROS_ERROR_NAMED(
"BaseController",
"Unable to start, not initialized.");
244 double actual_scaling = 1.0;
279 double left_pos =
left_->getPosition();
280 double right_pos =
right_->getPosition();
299 left_dx = right_dx = 0.0;
300 left_vel = right_vel = 0.0;
304 double d = (left_dx+right_dx)/2.0;
308 dx = (left_vel + right_vel)/2.0;
332 odom_.twist.twist.linear.x = dx;
333 odom_.twist.twist.angular.z = dr;
340 std::vector<std::string> names;
342 names.push_back(
left_->getName());
344 names.push_back(
right_->getName());
357 nav_msgs::Odometry msg;
372 msg.pose.pose.orientation.y,
373 msg.pose.pose.orientation.z,
374 msg.pose.pose.orientation.w) );
384 const sensor_msgs::LaserScanConstPtr& scan)
386 double angle = scan->angle_min;
389 for (
size_t i = 0; i < scan->ranges.size(); ++i, angle += scan->angle_increment)
391 if (std::isfinite(scan->ranges[i]) &&
392 scan->ranges[i] > scan->range_min &&
393 scan->ranges[i] < min_dist)
396 if (angle < -1.5 || angle > 1.5)
400 double py =
sin(angle) * scan->ranges[i];
402 min_dist = scan->ranges[i];
415 right_->setVelocity(right * radians_per_meter_, 0.0);
double rotating_threshold_
Threshold for wheel velocity to be "moving".
boost::mutex command_mutex_
virtual int init(ros::NodeHandle &nh, ControllerManager *manager)
Initialize the controller and any required data structures.
void publishCallback(const ros::TimerEvent &event)
void setCommand(float left, float right)
void publish(const boost::shared_ptr< M > &message) const
void command(const geometry_msgs::TwistConstPtr &msg)
Command callback from either a ROS topic, or a higher controller.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
virtual bool start()
Attempt to start the controller. This should be called only by the ControllerManager instance...
#define ROS_DEBUG_THROTTLE_NAMED(rate, name,...)
virtual int requestStart(const std::string &name)
double max_acceleration_x_
void scanCallback(const sensor_msgs::LaserScanConstPtr &scan)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
double right_last_timestamp_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
float right_last_position_
double safety_scaling_distance_
TFSIMD_FORCE_INLINE const tfScalar & x() const
double moving_threshold_
Threshold for dr to be considered "moving".
double radians_per_meter_
float left_last_position_
double max_velocity_x_
Threshold for dx to be considered "moving".
double wheel_rotating_threshold_
virtual bool stop(bool force)
Attempt to stop the controller. This should be called only by the ControllerManager instance...
virtual bool reset()
Cleanly reset the controller to it's initial state. Some controllers may choose to stop themselves...
double left_last_timestamp_
virtual int init(ros::NodeHandle &nh, ControllerManager *manager)
ros::Subscriber scan_sub_
virtual std::vector< std::string > getClaimedNames()
Get the names of joints/controllers which this controller exclusively claims.
double max_acceleration_r_
boost::shared_ptr< tf::TransformBroadcaster > broadcaster_
ControllerManager * manager_
#define ROS_ERROR_NAMED(name,...)
virtual std::vector< std::string > getCommandedNames()
Get the names of joints/controllers which this controller commands.
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
JointHandlePtr getJointHandle(const std::string &name)
ros::Time last_laser_scan_
ROS-aware controller to manage a differential drive mobile base. This subcribes to cmd_vel topic...
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
def shortest_angular_distance(from_angle, to_angle)
virtual void update(const ros::Time &now, const ros::Duration &dt)
This is the update loop for the controller.