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.
Dependents: kisoken_PenPlotter
Revision 0:a7573f3f2207, committed 2017-08-03
- Comitter:
- Akito914
- Date:
- Thu Aug 03 06:50:03 2017 +0000
- Child:
- 1:15adfb7ee64c
- Commit message:
- ???????????????????;
Changed in this revision
| trapezoidalMotionCal.cpp | Show annotated file Show diff for this revision Revisions of this file |
| trapezoidalMotionCal.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/trapezoidalMotionCal.cpp Thu Aug 03 06:50:03 2017 +0000
@@ -0,0 +1,64 @@
+
+#include "mbed.h"
+#include "trapezoidalMotionCal.h"
+
+
+trapezoidalMotionCal::trapezoidalMotionCal(double f_start, double f_stop, double f_max, double a_up, double a_down){
+ _f_start = f_start;
+ _f_stop = f_stop;
+ _f_max = f_max;
+ _a_up = a_up;
+ _a_down = a_down;
+
+ shortMode = 0;
+ revMode = 0;
+
+ step_accel = (f_max * f_max - f_start * f_start) / (2 * a_up);
+ step_decel = (f_stop * f_stop - f_max * f_max) / (2 * a_down);
+
+
+}
+
+void trapezoidalMotionCal::setTarg(int32_t targ){
+
+ targSteps = targ;
+
+ if(targSteps < 0){
+ revMode = 1;
+ targSteps *= -1;
+ }
+
+ step_const = (double)targSteps - step_accel - step_decel;
+
+ if (step_const <= 0) {
+ shortMode = 1;
+ step_accel = (2 * _a_down * targSteps + _f_start * _f_start - _f_stop * _f_stop) / (2 * (_a_down - _a_up));
+ step_decel = targSteps - step_accel;
+ step_const = 0;
+ f_reach = sqrt(2 * _a_up * step_accel + _f_start * _f_start);
+ }
+
+}
+
+uint32_t trapezoidalMotionCal::calStepDelay(int32_t steps){
+ uint32_t period_us;
+
+ if (steps < step_accel) {
+ period_us = 1000000 * pow(_f_start * _f_start + 2 * _a_up * steps, -0.5);
+ }
+ else if (steps < step_accel + step_const) {
+ period_us = 1000000 / _f_max;
+ }
+ else {
+ if (shortMode == 0) {
+ period_us = 1000000 * pow(_f_max * _f_max + 2 * _a_down * (steps - step_accel - step_const), -0.5);
+ }
+ else {
+ period_us = 1000000 * pow(f_reach * f_reach + 2 * _a_down * (steps - step_accel - step_const), -0.5);
+ }
+
+ }
+
+ return period_us;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/trapezoidalMotionCal.h Thu Aug 03 06:50:03 2017 +0000
@@ -0,0 +1,41 @@
+
+#include "mbed.h"
+
+#ifndef __TRAPEZOIDAL_MOTION_CAL_H__
+#define __TRAPEZOIDAL_MOTION_CAL_H__
+
+
+class trapezoidalMotionCal{
+
+public:
+
+ trapezoidalMotionCal(double f_start, double f_stop, double f_max, double a_up, double a_down);
+
+ void setTarg(int32_t targ);
+
+ uint32_t calStepDelay(int32_t steps);
+
+private:
+ double _f_start;
+ double _f_stop;
+ double _f_max;
+ double _a_up;
+ double _a_down;
+
+ double step_accel;
+ double step_decel;
+ double step_const;
+ double f_reach;
+
+ int32_t targSteps;
+
+ int shortMode;
+ int revMode;
+
+};
+
+
+
+
+#endif
+