14 #include "../../include/kobuki_driver/modules/diff_drive.hpp" 26 last_velocity_left(0.0),
27 last_velocity_right(0.0),
34 point_velocity(2,0.0),
37 tick_to_rad(0.002436916871363930187454f),
38 diff_drive_kinematics(
bias, wheel_radius)
53 const uint16_t &left_encoder,
54 const uint16_t &right_encoder,
55 ecl::LegacyPose2D<double> &pose_update,
56 ecl::linear_algebra::Vector3d &pose_update_rates) {
58 static bool init_l =
false;
59 static bool init_r =
false;
60 double left_diff_ticks = 0.0f;
61 double right_diff_ticks = 0.0f;
62 unsigned short curr_tick_left = 0;
63 unsigned short curr_tick_right = 0;
64 unsigned short curr_timestamp = 0;
65 curr_timestamp = time_stamp;
66 curr_tick_left = left_encoder;
72 left_diff_ticks = (double)(
short)((curr_tick_left -
last_tick_left) & 0xffff);
76 curr_tick_right = right_encoder;
82 right_diff_ticks = (double)(
short)((curr_tick_right -
last_tick_right) & 0xffff);
115 double &wheel_right_angle,
double &wheel_right_angle_rate) {
127 std::vector<double> cmd_vel;
128 cmd_vel.push_back(vx);
129 cmd_vel.push_back(wz);
137 const double epsilon = 0.0001;
140 if( std::abs(wz) < epsilon ) {
142 speed = 1000.0f * vx;
147 radius = vx * 1000.0f / wz;
149 if( std::abs(vx) < epsilon || std::abs(
radius) <= 1.0f ) {
168 speed =
static_cast<double>(cmd_speed);
169 radius =
static_cast<double>(cmd_radius);
176 std::vector<short> cmd(2);
188 if (value > static_cast<double>(SHRT_MAX))
return SHRT_MAX;
189 if (value < static_cast<double>(SHRT_MIN))
return SHRT_MIN;
190 return static_cast<short>(value);
short bound(const double &value)
ecl::Mutex velocity_mutex
std::vector< double > point_velocity
unsigned short last_tick_left
void getWheelJointStates(double &wheel_left_angle, double &wheel_left_angle_rate, double &wheel_right_angle, double &wheel_right_angle_rate)
ecl::DifferentialDrive::Kinematics diff_drive_kinematics
std::vector< double > pointVelocity() const
std::vector< short > velocityCommands()
unsigned short last_timestamp
double last_velocity_left
void update(const uint16_t &time_stamp, const uint16_t &left_encoder, const uint16_t &right_encoder, ecl::LegacyPose2D< double > &pose_update, ecl::linear_algebra::Vector3d &pose_update_rates)
Updates the odometry from firmware stamps and encoders.
unsigned short last_tick_right
double last_velocity_right
void setVelocityCommands(const double &vx, const double &wz)