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