10 #include <boost/bind.hpp> 15 namespace bacc = boost::accumulators;
25 , velocity_rolling_window_size_(velocity_rolling_window_size)
26 , linear_acc_(
RollingWindow::window_size = velocity_rolling_window_size)
27 , angular_acc_(
RollingWindow::window_size = velocity_rolling_window_size)
28 , integrate_fun_(
boost::bind(&
Odometry::integrateExact, this, _1, _2))
40 const std::vector<ActuatedJoint>& steering_joints,
41 const std::vector<Wheel>& odometry_joints,
44 double linear_sum = 0.0;
45 double angular_sum = 0.0;
46 double steering_angle_sum = 0.0;
51 for (std::vector<Wheel>::const_iterator it = odometry_joints.begin(); it != odometry_joints.end(); ++it)
53 const double wheel_est_vel = it->handle_.getVelocity() * dt;
54 linear_sum += wheel_est_vel * it->radius_;
57 const double linear = linear_sum / odometry_joints.size();
59 for (std::vector<ActuatedJoint>::const_iterator it = steering_joints.begin(); it != steering_joints.end(); ++it)
61 const double steering_angle = it->getPosition();
62 double virtual_steering_angle = std::atan(
wheelbase_ * std::tan(steering_angle)/std::abs(
wheelbase_ + it->lateral_deviation_ * std::tan(steering_angle)));
63 steering_angle_sum += virtual_steering_angle;
64 angular_sum += linear * tan(virtual_steering_angle) /
wheelbase_;
67 const double angular = angular_sum / steering_joints.size();
68 const double steering_angle = steering_angle_sum / steering_joints.size();
71 const double curvature_radius =
wheelbase_ / cos(M_PI/2.0 - steering_angle);
73 if (fabs(curvature_radius) > 0.0001)
75 const double elapsed_distance = linear;
76 const double elapsed_angle = elapsed_distance / curvature_radius;
77 const double x_curvature = curvature_radius * sin(elapsed_angle);
78 const double y_curvature = curvature_radius * (cos(elapsed_angle) - 1.0);
79 const double wheel_heading =
heading_ + steering_angle;
80 y_ += x_curvature * sin(wheel_heading) + y_curvature * cos(wheel_heading);
81 x_ += x_curvature * cos(wheel_heading) - y_curvature * sin(wheel_heading);
105 const double dt = (time -
timestamp_).toSec();
119 const double direction =
heading_ + angular * 0.5;
122 x_ += linear * cos(direction);
123 y_ += linear * sin(direction);
134 if (fabs(angular) < 1e-6)
139 const double heading_old =
heading_;
140 const double r = linear/angular;
143 y_ += -r * (cos(
heading_) - cos(heading_old));
bool update(const std::vector< ActuatedJoint > &steering_joints, const std::vector< Wheel > &odometry_joints, const ros::Time &time)
Updates the odometry class with latest wheels position.
IntegrationFunction integrate_fun_
Integration funcion, used to integrate the odometry:
ros::Time timestamp_
Current timestamp:
void setVelocityRollingWindowSize(size_t velocity_rolling_window_size)
Velocity rolling window size setter.
size_t velocity_rolling_window_size_
Rolling mean accumulators for the linar and angular velocities:
double linear_
Current velocity:
RollingMeanAcc angular_acc_
void integrateExact(double linear, double angular)
Integrates the velocities (linear and angular) using exact method.
void updateOpenLoop(double linear, double angular, const ros::Time &time)
Updates the odometry class with latest velocity command.
Odometry(size_t velocity_rolling_window_size=10)
Constructor Timestamp will get the current time value Value will be set to zero.
bacc::accumulator_set< double, bacc::stats< bacc::tag::rolling_mean > > RollingMeanAcc
Rolling mean accumulator and window:
void integrateRungeKutta2(double linear, double angular)
Integrates the velocities (linear and angular) using 2nd order Runge-Kutta.
void init(const ros::Time &time)
Initialize the odometry.
void resetAccumulators()
Reset linear and angular accumulators.
bacc::tag::rolling_window RollingWindow
The Odometry class handles odometry readings (2D pose and velocity with related timestamp) ...
RollingMeanAcc linear_acc_