GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/diff_drive_controller.h Lines: 0 4 0.0 %
Date: 2022-09-12 09:50:59 Branches: 0 2 0.0 %

Line Branch Exec Source
1
/*********************************************************************
2
 * Software License Agreement (BSD License)
3
 *
4
 *  Copyright (c) 2013, PAL Robotics, S.L.
5
 *  All rights reserved.
6
 *
7
 *  Redistribution and use in source and binary forms, with or without
8
 *  modification, are permitted provided that the following conditions
9
 *  are met:
10
 *
11
 *   * Redistributions of source code must retain the above copyright
12
 *     notice, this list of conditions and the following disclaimer.
13
 *   * Redistributions in binary form must reproduce the above
14
 *     copyright notice, this list of conditions and the following
15
 *     disclaimer in the documentation and/or other materials provided
16
 *     with the distribution.
17
 *   * Neither the name of the PAL Robotics nor the names of its
18
 *     contributors may be used to endorse or promote products derived
19
 *     from this software without specific prior written permission.
20
 *
21
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 *  POSSIBILITY OF SUCH DAMAGE.
33
 *********************************************************************/
34
35
/*
36
 * Author: Bence Magyar, Enrique Fernández
37
 */
38
39
#include <dynamic-graph/entity.h>
40
#include <dynamic-graph/linear-algebra.h>
41
#include <dynamic-graph/signal-ptr.h>
42
#include <dynamic-graph/signal-time-dependent.h>
43
44
#include <sot/core/matrix-geometry.hh>
45
46
#include "odometry.h"
47
#include "speed_limiter.h"
48
49
namespace dynamicgraph {
50
/**
51
 * This class makes some assumptions on the model of the robot:
52
 *  - the rotation axes of wheels are collinear
53
 *  - the wheels are identical in radius
54
 * Additional assumptions to not duplicate information readily available in the
55
 * URDF:
56
 *  - the wheels have the same parent frame
57
 *  - a wheel collision geometry is a cylinder or sphere in the urdf
58
 *  - a wheel joint frame center's vertical projection on the floor must lie
59
 * within the contact patch \deprecated TO BE DELETED
60
 */
61
class DiffDriveController : public Entity {
62
 public:
63
  DYNAMIC_GRAPH_ENTITY_DECL();
64
65
  DiffDriveController(const std::string& name);
66
67
  /// Header documentation of the python class
68
  virtual std::string getDocString() const {
69
    return "Compute the wheels velocities of a wheeled platform, from a "
70
           "desired velocity of the platform.";
71
  }
72
73
  /// \param order either 1, 2 or 3 for velocity, acceleration and jerk limits.
74
  void setAngularLimits(const int& order, const bool& enable, const double& min,
75
                        const double& max);
76
77
  /// \param order either 1, 2 or 3 for velocity, acceleration and jerk limits.
78
  void setLinearLimits(const int& order, const bool& enable, const double& min,
79
                       const double& max);
80
81
  /// \param order either 1, 2 or 3 for velocity, acceleration and jerk limits.
82
  /// \return [ min, max ] if a limit for this order is set, otherwise an empty
83
  /// vector.
84
  Vector getAngularLimits(const int& order);
85
86
  /// \param order either 1, 2 or 3 for velocity, acceleration and jerk limits.
87
  /// \return [ min, max ] if a limit for this order is set, otherwise an empty
88
  /// vector.
89
  Vector getLinearLimits(const int& order);
90
91
  void setOpenLoop(const bool& openLoop) { openLoop_ = openLoop; }
92
93
  bool getOpenLoop() const { return openLoop_; }
94
95
  void setWheelSeparation(const double& ws) { wheelSeparation_ = ws; }
96
97
  double getWheelSeparation() const { return wheelSeparation_; }
98
99
  void setWheelRadius(const double& ws) { wheelRadius_ = ws; }
100
101
  double getWheelRadius() const { return wheelRadius_; }
102
103
  void setPeriod(const double& dt);
104
105
  /// Reset accumulators used for velocity estimation from encoders.
106
  void resetOdometryAccumulators();
107
108
 private:
109
  /// Compute the wheels velocities.
110
  /// \returns the vector ( left wheel velocity, right wheel velocity )
111
  Vector& computeControl(Vector& control, const int& time);
112
113
  Vector& computeBasePose(Vector& basePos, const int& time);
114
115
  Vector& computeBaseVel(Vector& baseVel, const int& time);
116
117
  bool computeOdometry(const int& time);
118
119
  /// Velocity command related:
120
  struct Command {
121
    double lin;
122
    double ang;
123
    int time;
124
125
    Command() : lin(0.0), ang(0.0), time(0) {}
126
  };
127
128
  SignalPtr<Vector, int> baseVelSIN;
129
  /// Last base velocity before baseVelSIN.
130
  Command lastBaseVel_;
131
  /// Last base velocity before lastBaseVelSIN.
132
  Command penultimateBaseVel_;
133
134
  SignalTimeDependent<Vector, int> wheelsVelSOUT;
135
  SignalTimeDependent<Vector, int> basePoseSOUT;
136
  SignalTimeDependent<Vector, int> baseVelSOUT;
137
138
  /// For closed loop control
139
  SignalPtr<Vector, int> wheelsPosSIN;
140
141
  double dt_;
142
143
  /// Odometry related:
144
  bool openLoop_;
145
146
  /// Odometry related:
147
  details::Odometry odometry_;
148
149
  /// Wheel separation, wrt the midpoint of the wheel width:
150
  double wheelSeparation_;
151
152
  /// Wheel radius (assuming it's the same for the left and right wheels):
153
  double wheelRadius_;
154
155
  /// Wheel separation and radius calibration multipliers:
156
  double wheelSeparationMultiplier_;
157
  double leftWheelRadiusMultiplier_;
158
  double rightWheelRadiusMultiplier_;
159
160
  /// Speed limiters:
161
  SpeedLimiter limiterLin_;
162
  SpeedLimiter limiterAng_;
163
};
164
165
}  // namespace dynamicgraph