Libary for PM2.

Dependencies:   LSM9DS1 RangeFinder FastPWM

Dependents:   PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board ... more

Committer:
pmic
Date:
Wed Jun 22 14:05:13 2022 +0000
Revision:
32:bb074bb17d39
Parent:
29:335fb9b01ca7
Updated SensorBar so it is not blocking the program if it is not connected

Who changed what in which revision?

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