Kobuki 1.0.0
C++ API for the Kobuki research robot
Loading...
Searching...
No Matches
diff_drive.hpp
1
9/*****************************************************************************
10** Ifdefs
11*****************************************************************************/
12
13#ifndef KOBUKI_CORE_DIFF_DRIVE_HPP_
14#define KOBUKI_CORE_DIFF_DRIVE_HPP_
15
16/*****************************************************************************
17** Includes
18*****************************************************************************/
19
20#include <vector>
21#include <climits>
22#include <stdint.h>
23// Version 3.4.0 of Eigen in Ubuntu 22.04 has a bug that causes -Wclass-memaccess warnings on
24// aarch64. Upstream Eigen has already fixed this in
25// https://gitlab.com/libeigen/eigen/-/merge_requests/645 . The Debian fix for this is in
26// https://salsa.debian.org/science-team/eigen3/-/merge_requests/1 .
27// However, it is not clear that that fix is going to make it into Ubuntu 22.04 before it
28// freezes, so disable the warning here.
29#if defined(__GNUC__) && !defined(__clang__)
30#pragma GCC diagnostic push
31#pragma GCC diagnostic ignored "-Wclass-memaccess"
32#endif
33#include <ecl/geometry.hpp>
34#if defined(__GNUC__) && !defined(__clang__)
35#pragma GCC diagnostic pop
36#endif
37
38#include <ecl/mobile_robot.hpp>
39#include <ecl/threads/mutex.hpp>
40#include "../macros.hpp"
41
42/*****************************************************************************
43** Namespaces
44*****************************************************************************/
45
46namespace kobuki {
47
48/*****************************************************************************
49** Interfaces
50*****************************************************************************/
51
52class kobuki_PUBLIC DiffDrive {
53public:
54 DiffDrive();
55 const ecl::DifferentialDrive::Kinematics& kinematics() { return diff_drive_kinematics; }
56 void update(const uint16_t &time_stamp,
57 const uint16_t &left_encoder,
58 const uint16_t &right_encoder,
59 ecl::linear_algebra::Vector3d &pose_update,
60 ecl::linear_algebra::Vector3d &pose_update_rates);
61 void reset();
62 void getWheelJointStates(double &wheel_left_angle, double &wheel_left_angle_rate,
63 double &wheel_right_angle, double &wheel_right_angle_rate);
64 void setVelocityCommands(const double &vx, const double &wz);
65 void velocityCommands(const double &vx, const double &wz);
66 void velocityCommands(const short &cmd_speed, const short &cmd_radius);
67 void velocityCommands(const std::vector<double> &cmd) { velocityCommands(cmd[0], cmd[1]); }
68 void velocityCommands(const std::vector<short> &cmd) { velocityCommands(cmd[0], cmd[1]); }
69
70 /*********************
71 ** Command Accessors
72 **********************/
73 std::vector<short> velocityCommands(); // (speed, radius), in [mm/s] and [mm]
74 std::vector<double> pointVelocity() const; // (vx, wz), in [m/s] and [rad/s]
75
76 /*********************
77 ** Property Accessors
78 **********************/
79 double wheel_bias() const { return bias; }
80
81private:
82 unsigned short last_timestamp;
83 double last_velocity_left, last_velocity_right;
84 double last_diff_time;
85
86 unsigned short last_tick_left, last_tick_right;
87 double last_rad_left, last_rad_right;
88
89 //double v, w; // in [m/s] and [rad/s]
90 std::vector<double> point_velocity; // (vx, wz), in [m/s] and [rad/s]
91 double radius; // in [mm]
92 double speed; // in [mm/s]
93 double bias; //wheelbase, wheel_to_wheel, in [m]
94 double wheel_radius; // in [m]
95 const double tick_to_rad;
96
97 ecl::DifferentialDrive::Kinematics diff_drive_kinematics;
98 ecl::Mutex velocity_mutex, state_mutex;
99
100 // Utility
101 short bound(const double &value);
102};
103
104} // namespace kobuki
105
106#endif /* KOBUKI_CORE_DIFF_DRIVE_HPP_ */
Definition diff_drive.hpp:52