ROME2 Lab3

Committer:
oehlemar
Date:
Wed Mar 25 14:15:52 2020 +0000
Revision:
2:fc9e2aebf9d5
Parent:
0:6a4d3264c067
final

Who changed what in which revision?

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