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.
Dependencies: mbed MODSERIAL FATFileSystem
Diff: LinearActuator/LinearActuator.hpp
- Revision:
- 10:085ab7328054
- Parent:
- 9:d5fcdcb3c89d
- Child:
- 11:3b241ecb75ed
--- a/LinearActuator/LinearActuator.hpp Fri Oct 20 11:41:22 2017 +0000
+++ b/LinearActuator/LinearActuator.hpp Mon Oct 23 12:50:53 2017 +0000
@@ -1,9 +1,9 @@
-#ifndef BCE_HPP
-#define BCE_HPP
+#ifndef LINEARACTUATOR_HPP
+#define LINEARACTUATOR_HPP
#include "mbed.h"
#include "PololuHbridge.hpp"
-#include "controller.hpp"
+#include "PidController.hpp"
#include "ltc1298.hpp"
#include "PosVelFilter.hpp"
@@ -13,10 +13,8 @@
//for this reason it makes sense for it to be its own entity that is started in
//the main line code
-class LinearActuator
-{
+class LinearActuator {
public:
- //BuoyancyEngine(PololuHBridge motor, SpiADC adc, PosVelFilter filter, PositionController pid);
LinearActuator(float interval, PinName pwm, PinName dir, PinName reset, PinName limit, int adc_ch);
// functions for setting up
@@ -31,11 +29,9 @@
// setting and getting variables
void setPosition_mm(float dist);
-
float getPosition_mm();
- float getPosition_counts();
-
float getVelocity_mms();
+// float getPosition_counts();
void setControllerP(float P);
float getControllerP();
@@ -56,11 +52,11 @@
float getPotSlope();
void homePiston();
- void setFilterFrequency(float frequency);
+ bool getSwitch();
float getOutput();
- bool getSwitch();
+ void setFilterFrequency(float frequency);
void setDeadband(float deadband);
bool toggleDeadband(bool toggle);
@@ -69,7 +65,6 @@
PololuHBridge _motor;
PosVelFilter _filter;
PIDController _pid;
- //Timer _time;
Ticker _pulse;
InterruptIn _limitSwitch;
@@ -77,7 +72,6 @@
void _switchReleased();
void _calculateSensorSlope();
-
bool _init;
bool _paused;
bool _limit;
@@ -90,12 +84,15 @@
float _SetPoint_mm;
+ // position and velocity in counts (PVF runs on counts)
float _position;
+ float _velocity;
+
+ // position and velocity converted to mm and mm/s
float _position_mm;
-
- float _velocity;
float _velocity_mms;
+ // linear actuator servo PID gains
float _Pgain;
float _Igain;
float _Dgain;
@@ -104,7 +101,6 @@
int _zeroCounts; //gets assigned by homing function. can also be stored in config
float _extendLimit; //config variable, limits the extension of the piston, this is same as datum for normal operation,
- float _pos_vel_wn; //config variable, natural frequecny of the position velocity filter
float _slope;
int dist_to_counts(float dist);
@@ -112,5 +108,18 @@
float counts_to_velocity(int count);
};
-
+
+
+template <typename T>
+T clamp(T value, T min, T max)
+{
+ if(value < min) {
+ return min;
+ } else if(value > max) {
+ return max;
+ } else {
+ return value;
+ }
+};
+
#endif
\ No newline at end of file