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

Dependencies:   LS7366LIB MotCon2 PID

Dependents:   LPC1768_6axis_Arm

Revision:
7:d0458137d6e0
Parent:
5:79dcaa63700c
Child:
8:7e399d7c990d
--- 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());
     }