robot

Dependencies:   FastPWM3 mbed

Revision:
187:523cf8c962e4
Parent:
186:c18db1e31da6
Child:
188:43f50a4cc040
--- a/main.cpp	Fri Feb 09 22:25:44 2018 +0000
+++ b/main.cpp	Fri Feb 09 23:24:25 2018 +0000
@@ -29,24 +29,10 @@
 ThrottleMapper *th;
 
 int loop_counter = 0;
-bool control_enabled = false;
-
-void update_velocity() {
-    read.last_p_mech = read.p_mech;
-    read.p_mech = io.pos->GetMechPosition();
-    
-    float dp_mech = read.p_mech - read.last_p_mech;
-    if (dp_mech < -PI) dp_mech += 2 * PI;
-    if (dp_mech >  PI) dp_mech -= 2 * PI;
-    
-    float w_raw = dp_mech * F_SW; //rad/s
-    
-    read.w = control.velocity_filter->update(w_raw);
-}
 
 void commutate() {  
     /*safety checks, do we do anything this cycle?*/
-    if (!control_enabled && io.throttle_in->get_enabled() && io.pos->IsValid() && is_driving()) {
+    if (!control.enabled && io.throttle_in->get_enabled() && io.pos->IsValid() && is_driving()) {
         go_enabled();
     }
     
@@ -93,7 +79,7 @@
     
     constrain_norm(&foc.vd, &foc.vq, 1.0f, 1.0f, 1.0f + OVERMODULATION_FACTOR);
     
-    if (!control_enabled) {
+    if (!control.enabled) {
         foc.vd = 0.0f;
         foc.vq = 0.0f;
     }
@@ -138,22 +124,6 @@
     dq->map(control.torque_percent, read.w, &control.d_ref, &control.q_ref);
 }
 
-void go_enabled() {
-    control_enabled = true;
-    io.en->write(1);
-}
-
-void go_disabled() {
-    control.d_integral = 0.0f;
-    control.q_integral = 0.0f;
-    control_enabled = false;
-    io.en->write(0);
-}
-
-bool is_driving() {
-    return control.torque_percent > 0.01f || fabsf(read.w) > W_SAFE;
-}
-
 void log() {
     float packet[8];
     packet[0] = read.w / 8.0f;
@@ -166,24 +136,6 @@
     packet[7] = 255.0f / (1.0f + OVERMODULATION_FACTOR) * foc.vq / 2.0f + 128.0f;
     io.logger->log(packet);
 }
-        
-extern "C" void TIM1_UP_TIM10_IRQHandler(void) {
-    int start_state = io.throttle_in->state();
-    
-    if (TIM1->SR & TIM_SR_UIF ) {
-        ADC1->CR2  |= 0x40000000; 
-        volatile int delay;
-        for (delay = 0; delay < 35; delay++);
-        
-        read.adval1 = ADC1->DR;
-        read.adval2 = ADC2->DR;
-
-        commutate();
-    }
-    TIM1->SR = 0x00;
-    int end_state = io.throttle_in->state();
-    if (start_state != end_state) io.throttle_in->block();
-}
 
 int main() {    
     dq = new InterpolatingLutMapper();