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

Dependencies:   LS7366LIB MotCon2 PID

Dependents:   LPC1768_6axis_Arm

Files at this revision

API Documentation at this revision

Comitter:
jebradshaw
Date:
Thu May 19 12:41:53 2016 +0000
Parent:
6:2e3a0a382c12
Child:
8:7e399d7c990d
Commit message:
Updated 20160519 - Plan to add motor state and output format variable ('e'-encoder counts, 'r'-radians, 'd'-degrees)

Changed in this revision

Axis.cpp Show annotated file Show diff for this revision Revisions of this file
Axis.h Show annotated file Show diff for this revision Revisions of this file
MotCon.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Axis.cpp	Thu Dec 17 19:10:55 2015 +0000
+++ b/Axis.cpp	Thu May 19 12:41:53 2016 +0000
@@ -36,6 +36,8 @@
     this->update.attach(this, &Axis::paramUpdate, Tdelay);
     this->axisState = 0;
     this->mot_I_lim = .35;    
+    this->motInvert = 0;
+    this->dataFormat = 'r'; //default is radians
     
     this->pid = new PID(0.0,0.0,0.0,Tdelay); //Kc, Ti, Td, interval
     this->ls7366 = new LS7366(spi, cs);  //LS7366 encoder interface IC
@@ -99,8 +101,17 @@
     //Set the new output.
     this->co = this->pid->compute();
 
-    if(this->axisState)
-        this->motcon->mot_control(this->co); //send controller output to PWM motor control command    
+DigitalOut led3(P1_21);
+    if(this->axisState){
+        if(this->motInvert==0){
+            this->motcon->mot_control(this->co); //send controller output to PWM motor control command    
+            led3=1;
+        }
+        else{
+            this->motcon->mot_control(this->co, 1); //send controller output to PWM motor control command    
+            led3=0;
+        }
+    }
     else{
         this->co = 0.0;
         this->motcon->mot_control(0.0);     //turn off motor command
@@ -117,7 +128,7 @@
     
     while((*this->ptr_limit == 1) && (this->readCurrent() < mot_I_lim)){ //limit switch not pressed and mot current not exceeded
        this->set_point += 100;
-       wait(.1);
+       wait(.05);
        if(this->debug)
             printf("T=%.2f SP=%.3f co=%.3f pos=%.3f vel=%.3f acc=%.3f limit=%d motI=%.3f\r\n", t.read(), this->set_point, this->co, this->pos, this->vel, this->acc,*this->ptr_limit, this->_analog.read());
     }
--- a/Axis.h	Thu Dec 17 19:10:55 2015 +0000
+++ b/Axis.h	Thu May 19 12:41:53 2016 +0000
@@ -21,9 +21,9 @@
     void axisOn(void);
     void zero(void);
     
-    long enc;
-    float co;// = 0.0;
-    float Tdelay;// = .01;
+    long enc;       //used to return the data from the LS7366 encoder chip
+    float co;       // = 0.0;
+    float Tdelay;   // = .01;
     float Pk;       // 120.0 for scorbot
     float Ik;       // 55.0 for scorbot
     float Dk;
@@ -41,9 +41,11 @@
     int debug;
     int *ptr_limit;
     float totalCounts;
-    float motCurrent;
-    float mot_I_lim;
+    float motCurrent;   //motor current read from readCurrent() function
+    float mot_I_lim;    //max current limit
     int axisState;
+    int motInvert;
+    char dataFormat;    //'r'=radians (default), 'd'=degrees, 'e'=encoder counts
 
     Ticker update;
     Ticker moveProfile;
--- a/MotCon.lib	Thu Dec 17 19:10:55 2015 +0000
+++ b/MotCon.lib	Thu May 19 12:41:53 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/jebradshaw/code/MotCon/#3ba12980833b
+https://developer.mbed.org/users/jebradshaw/code/MotCon/#69e79f1db999