33 #include <nav_msgs/Odometry.h> 34 #include <geometry_msgs/TransformStamped.h> 43 odom_frame_(
"odom"), base_frame_(
"base_link"),
44 use_servo_cmd_(true), publish_tf_(false), x_(0.0), y_(0.0), yaw_(0.0)
91 if (std::fabs(current_speed) < 0.05)
95 double current_steering_angle(0.0), current_angular_velocity(0.0);
98 current_steering_angle =
100 current_angular_velocity = current_speed * tan(current_steering_angle) /
wheelbase_;
113 double x_dot = current_speed * cos(
yaw_);
114 double y_dot = current_speed * sin(
yaw_);
118 yaw_ += current_angular_velocity * dt.
toSec();
124 nav_msgs::Odometry::Ptr odom(
new nav_msgs::Odometry);
126 odom->header.stamp = state->header.stamp;
130 odom->pose.pose.position.x =
x_;
131 odom->pose.pose.position.y =
y_;
132 odom->pose.pose.orientation.x = 0.0;
133 odom->pose.pose.orientation.y = 0.0;
134 odom->pose.pose.orientation.z = sin(
yaw_ / 2.0);
135 odom->pose.pose.orientation.w = cos(
yaw_ / 2.0);
139 odom->pose.covariance[0] = 0.2;
140 odom->pose.covariance[7] = 0.2;
141 odom->pose.covariance[35] = 0.4;
144 odom->twist.twist.linear.x = current_speed;
145 odom->twist.twist.linear.y = 0.0;
146 odom->twist.twist.angular.z = current_angular_velocity;
153 geometry_msgs::TransformStamped
tf;
157 tf.transform.translation.x =
x_;
158 tf.transform.translation.y =
y_;
159 tf.transform.translation.z = 0.0;
160 tf.transform.rotation = odom->pose.pose.orientation;
178 template <
typename T>
184 ROS_FATAL(
"VescToOdom: Parameter %s is required.", name.c_str());
void vescStateCallback(const vesc_msgs::VescStateStamped::ConstPtr &state)
double speed_to_erpm_offset_
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
vesc_msgs::VescStateStamped::ConstPtr last_state_
Last received state message.
std::shared_ptr< tf::TransformBroadcaster > tf_pub_
void servoCmdCallback(const std_msgs::Float64::ConstPtr &servo)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
double steering_to_servo_gain_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std_msgs::Float64::ConstPtr last_servo_cmd_
Last servo position commanded value.
double steering_to_servo_offset_
ros::Subscriber vesc_state_sub_
ros::Subscriber servo_sub_
double speed_to_erpm_gain_
bool getParam(const std::string &key, std::string &s) const
bool getRequiredParam(const ros::NodeHandle &nh, const std::string &name, T *value)
VescToOdom(ros::NodeHandle nh, ros::NodeHandle private_nh)