C++ class for controlling DC motor with encoder feedback. Dependencies include LS7366LIB, MotCon, and PID.

Dependencies:   LS7366LIB MotCon2 PID

Dependents:   LPC1768_6axis_Arm

Committer:
jebradshaw
Date:
Mon Aug 31 17:14:20 2015 +0000
Revision:
0:cf7192f9f99a
Child:
1:cd249816dba8
Used to control an axis on a robotic arm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jebradshaw 0:cf7192f9f99a 1
jebradshaw 0:cf7192f9f99a 2
jebradshaw 0:cf7192f9f99a 3 #ifndef MBED_ROBOTARM_H
jebradshaw 0:cf7192f9f99a 4 #define MBED_ROBOTARM_H
jebradshaw 0:cf7192f9f99a 5
jebradshaw 0:cf7192f9f99a 6 #include "mbed.h"
jebradshaw 0:cf7192f9f99a 7 #include "PID.h"
jebradshaw 0:cf7192f9f99a 8 #include "LS7366.h"
jebradshaw 0:cf7192f9f99a 9 #include "MotCon.h"
jebradshaw 0:cf7192f9f99a 10
jebradshaw 0:cf7192f9f99a 11 class Axis{
jebradshaw 0:cf7192f9f99a 12 public:
jebradshaw 0:cf7192f9f99a 13 Axis(SPI& _spi, PinName _cs, PinName _pwm, PinName _dir, PinName _limit);
jebradshaw 0:cf7192f9f99a 14 void paramUpdate(void);
jebradshaw 0:cf7192f9f99a 15 void home(long halfcounts);
jebradshaw 0:cf7192f9f99a 16 void init(float);
jebradshaw 0:cf7192f9f99a 17 void setSetPoint(float);
jebradshaw 0:cf7192f9f99a 18 void moveTrapezoid(float position, float time);
jebradshaw 0:cf7192f9f99a 19 void moveUpdate(void);
jebradshaw 0:cf7192f9f99a 20
jebradshaw 0:cf7192f9f99a 21 long enc;
jebradshaw 0:cf7192f9f99a 22 float co;// = 0.0;
jebradshaw 0:cf7192f9f99a 23 float Tdelay;// = .01;
jebradshaw 0:cf7192f9f99a 24 float Pk; // 120.0 for scorbot
jebradshaw 0:cf7192f9f99a 25 float Ik; // 55.0 for scorbot
jebradshaw 0:cf7192f9f99a 26 float Dk;
jebradshaw 0:cf7192f9f99a 27 float set_point;// = 0.0;
jebradshaw 0:cf7192f9f99a 28 float set_point_last;
jebradshaw 0:cf7192f9f99a 29 float pos, vel, acc; //calculated position, velocity, and acceleration
jebradshaw 0:cf7192f9f99a 30 float pos_last, vel_last, acc_last; //history variables used to calculate motion
jebradshaw 0:cf7192f9f99a 31 float pos_cmd, vel_cmd, vel_avg_cmd, acc_cmd;
jebradshaw 0:cf7192f9f99a 32 float vel_max, acc_max;
jebradshaw 0:cf7192f9f99a 33 float vel_accum;
jebradshaw 0:cf7192f9f99a 34 float moveTime;
jebradshaw 0:cf7192f9f99a 35 float p_higher, p_lower;
jebradshaw 0:cf7192f9f99a 36 int moveStatus;
jebradshaw 0:cf7192f9f99a 37 int moveState;
jebradshaw 0:cf7192f9f99a 38 int debug;
jebradshaw 0:cf7192f9f99a 39
jebradshaw 0:cf7192f9f99a 40 float countsPerDeg; //number of counts/revolution
jebradshaw 0:cf7192f9f99a 41
jebradshaw 0:cf7192f9f99a 42 Ticker update;
jebradshaw 0:cf7192f9f99a 43 Ticker moveProfile;
jebradshaw 0:cf7192f9f99a 44 Timer t;
jebradshaw 0:cf7192f9f99a 45 PID *pid;
jebradshaw 0:cf7192f9f99a 46 LS7366 *ls7366;
jebradshaw 0:cf7192f9f99a 47 MotCon *motcon;
jebradshaw 0:cf7192f9f99a 48
jebradshaw 0:cf7192f9f99a 49 private:
jebradshaw 0:cf7192f9f99a 50 SPI _spi;
jebradshaw 0:cf7192f9f99a 51 DigitalOut _cs;
jebradshaw 0:cf7192f9f99a 52 PwmOut _pwm;
jebradshaw 0:cf7192f9f99a 53 DigitalOut _dir;
jebradshaw 0:cf7192f9f99a 54 DigitalIn _limit;
jebradshaw 0:cf7192f9f99a 55 };
jebradshaw 0:cf7192f9f99a 56
jebradshaw 0:cf7192f9f99a 57 #endif
jebradshaw 0:cf7192f9f99a 58
jebradshaw 0:cf7192f9f99a 59