Allan Brignoli
/
Rome2_P6
gugus
Motion.h@0:1a0321f1ffbc, 2018-05-18 (annotated)
- Committer:
- Brignall
- Date:
- Fri May 18 12:18:21 2018 +0000
- Revision:
- 0:1a0321f1ffbc
lala;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Brignall | 0:1a0321f1ffbc | 1 | /* |
Brignall | 0:1a0321f1ffbc | 2 | * Motion.h |
Brignall | 0:1a0321f1ffbc | 3 | * Copyright (c) 2018, ZHAW |
Brignall | 0:1a0321f1ffbc | 4 | * All rights reserved. |
Brignall | 0:1a0321f1ffbc | 5 | */ |
Brignall | 0:1a0321f1ffbc | 6 | |
Brignall | 0:1a0321f1ffbc | 7 | #ifndef MOTION_H_ |
Brignall | 0:1a0321f1ffbc | 8 | #define MOTION_H_ |
Brignall | 0:1a0321f1ffbc | 9 | |
Brignall | 0:1a0321f1ffbc | 10 | #include <cstdlib> |
Brignall | 0:1a0321f1ffbc | 11 | |
Brignall | 0:1a0321f1ffbc | 12 | /** |
Brignall | 0:1a0321f1ffbc | 13 | * This class keeps the motion values <code>position</code> and <code>velocity</code>, and |
Brignall | 0:1a0321f1ffbc | 14 | * offers methods to increment these values towards a desired target position or velocity. |
Brignall | 0:1a0321f1ffbc | 15 | * <br/> |
Brignall | 0:1a0321f1ffbc | 16 | * To increment the current motion values, this class uses a simple 2nd order motion planner. |
Brignall | 0:1a0321f1ffbc | 17 | * This planner calculates the motion to the target position or velocity with the various motion |
Brignall | 0:1a0321f1ffbc | 18 | * phases, based on given limits for the profile velocity, acceleration and deceleration. |
Brignall | 0:1a0321f1ffbc | 19 | * <br/> |
Brignall | 0:1a0321f1ffbc | 20 | * Note that the trajectory is calculated every time the motion state is incremented. |
Brignall | 0:1a0321f1ffbc | 21 | * This allows to change the target position or velocity, as well as the limits for profile |
Brignall | 0:1a0321f1ffbc | 22 | * velocity, acceleration and deceleration at any time. |
Brignall | 0:1a0321f1ffbc | 23 | */ |
Brignall | 0:1a0321f1ffbc | 24 | class Motion { |
Brignall | 0:1a0321f1ffbc | 25 | |
Brignall | 0:1a0321f1ffbc | 26 | public: |
Brignall | 0:1a0321f1ffbc | 27 | |
Brignall | 0:1a0321f1ffbc | 28 | double position; /**< The position value of this motion, given in [m] or [rad]. */ |
Brignall | 0:1a0321f1ffbc | 29 | float velocity; /**< The velocity value of this motion, given in [m/s] or [rad/s]. */ |
Brignall | 0:1a0321f1ffbc | 30 | |
Brignall | 0:1a0321f1ffbc | 31 | Motion(); |
Brignall | 0:1a0321f1ffbc | 32 | Motion(double position, float velocity); |
Brignall | 0:1a0321f1ffbc | 33 | Motion(const Motion& motion); |
Brignall | 0:1a0321f1ffbc | 34 | virtual ~Motion(); |
Brignall | 0:1a0321f1ffbc | 35 | void set(double position, float velocity); |
Brignall | 0:1a0321f1ffbc | 36 | void set(const Motion& motion); |
Brignall | 0:1a0321f1ffbc | 37 | void setPosition(double position); |
Brignall | 0:1a0321f1ffbc | 38 | double getPosition(); |
Brignall | 0:1a0321f1ffbc | 39 | void setVelocity(float velocity); |
Brignall | 0:1a0321f1ffbc | 40 | float getVelocity(); |
Brignall | 0:1a0321f1ffbc | 41 | void setProfileVelocity(float profileVelocity); |
Brignall | 0:1a0321f1ffbc | 42 | void setProfileAcceleration(float profileAcceleration); |
Brignall | 0:1a0321f1ffbc | 43 | void setProfileDeceleration(float profileDeceleration); |
Brignall | 0:1a0321f1ffbc | 44 | void setLimits(float profileVelocity, float profileAcceleration, float profileDeceleration); |
Brignall | 0:1a0321f1ffbc | 45 | float getTimeToPosition(double targetPosition); |
Brignall | 0:1a0321f1ffbc | 46 | void incrementToVelocity(float targetVelocity, float period); |
Brignall | 0:1a0321f1ffbc | 47 | void incrementToPosition(double targetPosition, float period); |
Brignall | 0:1a0321f1ffbc | 48 | |
Brignall | 0:1a0321f1ffbc | 49 | private: |
Brignall | 0:1a0321f1ffbc | 50 | |
Brignall | 0:1a0321f1ffbc | 51 | static const float DEFAULT_LIMIT; // default value for limits |
Brignall | 0:1a0321f1ffbc | 52 | static const float MINIMUM_LIMIT; // smallest value allowed for limits |
Brignall | 0:1a0321f1ffbc | 53 | |
Brignall | 0:1a0321f1ffbc | 54 | float profileVelocity; |
Brignall | 0:1a0321f1ffbc | 55 | float profileAcceleration; |
Brignall | 0:1a0321f1ffbc | 56 | float profileDeceleration; |
Brignall | 0:1a0321f1ffbc | 57 | }; |
Brignall | 0:1a0321f1ffbc | 58 | |
Brignall | 0:1a0321f1ffbc | 59 | #endif /* MOTION_H_ */ |
Brignall | 0:1a0321f1ffbc | 60 | |
Brignall | 0:1a0321f1ffbc | 61 |