|
27 | 27 | #include <ignition/common/Profiler.hh>
|
28 | 28 | #include <ignition/math/DiffDriveOdometry.hh>
|
29 | 29 | #include <ignition/math/Quaternion.hh>
|
| 30 | +#include <ignition/math/SpeedLimiter.hh> |
30 | 31 | #include <ignition/plugin/Register.hh>
|
31 | 32 | #include <ignition/transport/Node.hh>
|
32 | 33 |
|
|
36 | 37 | #include "ignition/gazebo/Link.hh"
|
37 | 38 | #include "ignition/gazebo/Model.hh"
|
38 | 39 |
|
39 |
| -#include "SpeedLimiter.hh" |
40 |
| - |
41 | 40 | using namespace ignition;
|
42 | 41 | using namespace gazebo;
|
43 | 42 | using namespace systems;
|
@@ -123,10 +122,10 @@ class ignition::gazebo::systems::DiffDrivePrivate
|
123 | 122 | public: transport::Node::Publisher tfPub;
|
124 | 123 |
|
125 | 124 | /// \brief Linear velocity limiter.
|
126 |
| - public: std::unique_ptr<SpeedLimiter> limiterLin; |
| 125 | + public: std::unique_ptr<ignition::math::SpeedLimiter> limiterLin; |
127 | 126 |
|
128 | 127 | /// \brief Angular velocity limiter.
|
129 |
| - public: std::unique_ptr<SpeedLimiter> limiterAng; |
| 128 | + public: std::unique_ptr<ignition::math::SpeedLimiter> limiterAng; |
130 | 129 |
|
131 | 130 | /// \brief Previous control command.
|
132 | 131 | public: Commands last0Cmd;
|
@@ -197,56 +196,48 @@ void DiffDrive::Configure(const Entity &_entity,
|
197 | 196 | this->dataPtr->wheelRadius = _sdf->Get<double>("wheel_radius",
|
198 | 197 | this->dataPtr->wheelRadius).first;
|
199 | 198 |
|
200 |
| - // Parse speed limiter parameters. |
201 |
| - bool hasVelocityLimits = false; |
202 |
| - bool hasAccelerationLimits = false; |
203 |
| - bool hasJerkLimits = false; |
204 |
| - double minVel = std::numeric_limits<double>::lowest(); |
205 |
| - double maxVel = std::numeric_limits<double>::max(); |
206 |
| - double minAccel = std::numeric_limits<double>::lowest(); |
207 |
| - double maxAccel = std::numeric_limits<double>::max(); |
208 |
| - double minJerk = std::numeric_limits<double>::lowest(); |
209 |
| - double maxJerk = std::numeric_limits<double>::max(); |
| 199 | + // Instantiate the speed limiters. |
| 200 | + this->dataPtr->limiterLin = std::make_unique<ignition::math::SpeedLimiter>(); |
| 201 | + this->dataPtr->limiterAng = std::make_unique<ignition::math::SpeedLimiter>(); |
210 | 202 |
|
| 203 | + // Parse speed limiter parameters. |
211 | 204 | if (_sdf->HasElement("min_velocity"))
|
212 | 205 | {
|
213 |
| - minVel = _sdf->Get<double>("min_velocity"); |
214 |
| - hasVelocityLimits = true; |
| 206 | + const double minVel = _sdf->Get<double>("min_velocity"); |
| 207 | + this->dataPtr->limiterLin->SetMinVelocity(minVel); |
| 208 | + this->dataPtr->limiterAng->SetMinVelocity(minVel); |
215 | 209 | }
|
216 | 210 | if (_sdf->HasElement("max_velocity"))
|
217 | 211 | {
|
218 |
| - maxVel = _sdf->Get<double>("max_velocity"); |
219 |
| - hasVelocityLimits = true; |
| 212 | + const double maxVel = _sdf->Get<double>("max_velocity"); |
| 213 | + this->dataPtr->limiterLin->SetMaxVelocity(maxVel); |
| 214 | + this->dataPtr->limiterAng->SetMaxVelocity(maxVel); |
220 | 215 | }
|
221 | 216 | if (_sdf->HasElement("min_acceleration"))
|
222 | 217 | {
|
223 |
| - minAccel = _sdf->Get<double>("min_acceleration"); |
224 |
| - hasAccelerationLimits = true; |
| 218 | + const double minAccel = _sdf->Get<double>("min_acceleration"); |
| 219 | + this->dataPtr->limiterLin->SetMinAcceleration(minAccel); |
| 220 | + this->dataPtr->limiterAng->SetMinAcceleration(minAccel); |
225 | 221 | }
|
226 | 222 | if (_sdf->HasElement("max_acceleration"))
|
227 | 223 | {
|
228 |
| - maxAccel = _sdf->Get<double>("max_acceleration"); |
229 |
| - hasAccelerationLimits = true; |
| 224 | + const double maxAccel = _sdf->Get<double>("max_acceleration"); |
| 225 | + this->dataPtr->limiterLin->SetMaxAcceleration(maxAccel); |
| 226 | + this->dataPtr->limiterAng->SetMaxAcceleration(maxAccel); |
230 | 227 | }
|
231 | 228 | if (_sdf->HasElement("min_jerk"))
|
232 | 229 | {
|
233 |
| - minJerk = _sdf->Get<double>("min_jerk"); |
234 |
| - hasJerkLimits = true; |
| 230 | + const double minJerk = _sdf->Get<double>("min_jerk"); |
| 231 | + this->dataPtr->limiterLin->SetMinJerk(minJerk); |
| 232 | + this->dataPtr->limiterAng->SetMinJerk(minJerk); |
235 | 233 | }
|
236 | 234 | if (_sdf->HasElement("max_jerk"))
|
237 | 235 | {
|
238 |
| - maxJerk = _sdf->Get<double>("max_jerk"); |
239 |
| - hasJerkLimits = true; |
| 236 | + const double maxJerk = _sdf->Get<double>("max_jerk"); |
| 237 | + this->dataPtr->limiterLin->SetMaxJerk(maxJerk); |
| 238 | + this->dataPtr->limiterAng->SetMaxJerk(maxJerk); |
240 | 239 | }
|
241 | 240 |
|
242 |
| - // Instantiate the speed limiters. |
243 |
| - this->dataPtr->limiterLin = std::make_unique<SpeedLimiter>( |
244 |
| - hasVelocityLimits, hasAccelerationLimits, hasJerkLimits, |
245 |
| - minVel, maxVel, minAccel, maxAccel, minJerk, maxJerk); |
246 |
| - |
247 |
| - this->dataPtr->limiterAng = std::make_unique<SpeedLimiter>( |
248 |
| - hasVelocityLimits, hasAccelerationLimits, hasJerkLimits, |
249 |
| - minVel, maxVel, minAccel, maxAccel, minJerk, maxJerk); |
250 | 241 |
|
251 | 242 | double odomFreq = _sdf->Get<double>("odom_publish_frequency", 50).first;
|
252 | 243 | if (odomFreq > 0)
|
@@ -502,11 +493,11 @@ void DiffDrivePrivate::UpdateVelocity(const ignition::gazebo::UpdateInfo &_info,
|
502 | 493 | angVel = this->targetVel.angular().z();
|
503 | 494 | }
|
504 | 495 |
|
505 |
| - const double dt = std::chrono::duration<double>(_info.dt).count(); |
506 |
| - |
507 | 496 | // Limit the target velocity if needed.
|
508 |
| - this->limiterLin->Limit(linVel, this->last0Cmd.lin, this->last1Cmd.lin, dt); |
509 |
| - this->limiterAng->Limit(angVel, this->last0Cmd.ang, this->last1Cmd.ang, dt); |
| 497 | + this->limiterLin->Limit( |
| 498 | + linVel, this->last0Cmd.lin, this->last1Cmd.lin, _info.dt); |
| 499 | + this->limiterAng->Limit( |
| 500 | + angVel, this->last0Cmd.ang, this->last1Cmd.ang, _info.dt); |
510 | 501 |
|
511 | 502 | // Update history of commands.
|
512 | 503 | this->last1Cmd = last0Cmd;
|
|
0 commit comments