Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Motion.h@0:4beb2ea291ec, 2020-03-16 (annotated)
- Committer:
- boro
- Date:
- Mon Mar 16 13:12:31 2020 +0000
- Revision:
- 0:4beb2ea291ec
a
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| boro | 0:4beb2ea291ec | 1 | /* |
| boro | 0:4beb2ea291ec | 2 | * Motion.h |
| boro | 0:4beb2ea291ec | 3 | * Copyright (c) 2017, ZHAW |
| boro | 0:4beb2ea291ec | 4 | * All rights reserved. |
| boro | 0:4beb2ea291ec | 5 | * |
| boro | 0:4beb2ea291ec | 6 | * Created on: 02.02.2017 |
| boro | 0:4beb2ea291ec | 7 | * Author: Marcel Honegger |
| boro | 0:4beb2ea291ec | 8 | */ |
| boro | 0:4beb2ea291ec | 9 | |
| boro | 0:4beb2ea291ec | 10 | #ifndef MOTION_H_ |
| boro | 0:4beb2ea291ec | 11 | #define MOTION_H_ |
| boro | 0:4beb2ea291ec | 12 | |
| boro | 0:4beb2ea291ec | 13 | #include <cstdlib> |
| boro | 0:4beb2ea291ec | 14 | |
| boro | 0:4beb2ea291ec | 15 | /** |
| boro | 0:4beb2ea291ec | 16 | * This class keeps the motion values <code>position</code> and <code>velocity</code>, and |
| boro | 0:4beb2ea291ec | 17 | * offers methods to increment these values towards a desired target position or velocity. |
| boro | 0:4beb2ea291ec | 18 | * <br/> |
| boro | 0:4beb2ea291ec | 19 | * To increment the current motion values, this class uses a simple 2nd order motion planner. |
| boro | 0:4beb2ea291ec | 20 | * This planner calculates the motion to the target position or velocity with the various motion |
| boro | 0:4beb2ea291ec | 21 | * phases, based on given limits for the profile velocity, acceleration and deceleration. |
| boro | 0:4beb2ea291ec | 22 | * <br/> |
| boro | 0:4beb2ea291ec | 23 | * Note that the trajectory is calculated every time the motion state is incremented. |
| boro | 0:4beb2ea291ec | 24 | * This allows to change the target position or velocity, as well as the limits for profile |
| boro | 0:4beb2ea291ec | 25 | * velocity, acceleration and deceleration at any time. |
| boro | 0:4beb2ea291ec | 26 | */ |
| boro | 0:4beb2ea291ec | 27 | class Motion { |
| boro | 0:4beb2ea291ec | 28 | |
| boro | 0:4beb2ea291ec | 29 | public: |
| boro | 0:4beb2ea291ec | 30 | |
| boro | 0:4beb2ea291ec | 31 | double position; /**< The position value of this motion, given in [m] or [rad]. */ |
| boro | 0:4beb2ea291ec | 32 | float velocity; /**< The velocity value of this motion, given in [m/s] or [rad/s]. */ |
| boro | 0:4beb2ea291ec | 33 | float acceleration; /**< The acceleration value of this motion, given in [m/s²] or [rad/s²]. */ |
| boro | 0:4beb2ea291ec | 34 | |
| boro | 0:4beb2ea291ec | 35 | Motion(); |
| boro | 0:4beb2ea291ec | 36 | Motion(double position, float velocity, float acceleration); |
| boro | 0:4beb2ea291ec | 37 | Motion(const Motion& motion); |
| boro | 0:4beb2ea291ec | 38 | virtual ~Motion(); |
| boro | 0:4beb2ea291ec | 39 | void set(double position, float velocity, float acceleration); |
| boro | 0:4beb2ea291ec | 40 | void set(const Motion& motion); |
| boro | 0:4beb2ea291ec | 41 | void setPosition(double position); |
| boro | 0:4beb2ea291ec | 42 | double getPosition(); |
| boro | 0:4beb2ea291ec | 43 | void setVelocity(float velocity); |
| boro | 0:4beb2ea291ec | 44 | float getVelocity(); |
| boro | 0:4beb2ea291ec | 45 | void setAcceleration(float acceleration); |
| boro | 0:4beb2ea291ec | 46 | float getAcceleration(); |
| boro | 0:4beb2ea291ec | 47 | void setProfileVelocity(float profileVelocity); |
| boro | 0:4beb2ea291ec | 48 | void setProfileAcceleration(float profileAcceleration); |
| boro | 0:4beb2ea291ec | 49 | void setProfileDeceleration(float profileDeceleration); |
| boro | 0:4beb2ea291ec | 50 | void setLimits(float profileVelocity, float profileAcceleration, float profileDeceleration); |
| boro | 0:4beb2ea291ec | 51 | float getTimeToPosition(double targetPosition); |
| boro | 0:4beb2ea291ec | 52 | double getDistanceToStop(); |
| boro | 0:4beb2ea291ec | 53 | void incrementToVelocity(float targetVelocity, float period); |
| boro | 0:4beb2ea291ec | 54 | void incrementToPosition(double targetPosition, float period); |
| boro | 0:4beb2ea291ec | 55 | |
| boro | 0:4beb2ea291ec | 56 | private: |
| boro | 0:4beb2ea291ec | 57 | |
| boro | 0:4beb2ea291ec | 58 | static const float DEFAULT_LIMIT; // default value for limits |
| boro | 0:4beb2ea291ec | 59 | static const float MINIMUM_LIMIT; // smallest value allowed for limits |
| boro | 0:4beb2ea291ec | 60 | |
| boro | 0:4beb2ea291ec | 61 | float profileVelocity; |
| boro | 0:4beb2ea291ec | 62 | float profileAcceleration; |
| boro | 0:4beb2ea291ec | 63 | float profileDeceleration; |
| boro | 0:4beb2ea291ec | 64 | }; |
| boro | 0:4beb2ea291ec | 65 | |
| boro | 0:4beb2ea291ec | 66 | #endif /* MOTION_H_ */ |
| boro | 0:4beb2ea291ec | 67 |