Same as mallet... but distance

Dependencies:   EthernetInterface NetworkAPI mbed-rtos mbed

Fork of MalletFirmware by Impact-Echo

Files at this revision

API Documentation at this revision

Comitter:
timmey9
Date:
Wed Dec 03 07:18:27 2014 +0000
Parent:
23:9e5141647775
Child:
25:abbc19af13f9
Commit message:
Added angle encoder over ethernet functionality

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Dec 03 06:22:46 2014 +0000
+++ b/main.cpp	Wed Dec 03 07:18:27 2014 +0000
@@ -1,5 +1,6 @@
 // Server code
 #include "mbed.h"
+#include <stdio.h>
 
 // Ethernet
 #include "EthernetInterface.h"
@@ -142,7 +143,7 @@
     led_red = 1;
     
     pc.baud(230400);
-    pc.printf("Starting Server\r\n");
+    pc.printf("Starting %s\r\n",NAME);
     
     analog_initialization(A0);
     analog_initialization(A2);
@@ -188,7 +189,7 @@
     #endif
     
     interface.connect();
-    pc.printf(NAME);
+    //pc.printf(NAME);
     pc.printf("IP Address is: %s\n\r", interface.getIPAddress());
     pc.printf("Network Mask is: %s\n\r", interface.getNetworkMask());
     pc.printf("MAC address is: %s\n\r", interface.getMACAddress());
@@ -330,6 +331,73 @@
                                 led_green = !led_green;
                                 client[index].write((void *)"Data\n",5);
                                 client[index].write((void *)&sample_array,TOTAL_SAMPLES);
+                                break;
+                            case '1':
+                                // run motor and sample
+                                break;
+                            case '2':
+                                // run just the motor
+                                break;
+                            case 'a':
+                                if(angle_encoder.set_zero(&rotary_count)) {
+                                    client[index].write((void *) "Zero set\n",9);
+                                    }
+                                else {
+                                    client[index].write((void *) "Zero NOT set\n",13);
+                                    }
+                                break;
+                            case 's':
+                            {
+                                char buf[16];
+                                sprintf(buf,"NOP: %x\n",angle_encoder.nop());
+                                client[index].write((void *) buf,16);
+                                break;
+                                }
+                            case 'd':
+                            {
+                                char buf[29];
+                                sprintf(buf,"Angle: %i %i\n",angle_encoder.absolute_angle(), rotary_count);
+                                client[index].write((void *) buf,29);
+                                break;
+                                }
+                            /*    
+                                
+                                // for motor testing
+                                if(temp == 'k') // motor backward
+                                {
+                                    motor.backward(duty_cycle, duration[5]);
+                                    }
+                                
+                                if(temp == 'u' && duty_cycle < 1.00f) pc.printf("%f \r\n", duty_cycle += 0.01f);
+                                if(temp == 'i' && duty_cycle > 0.00f) pc.printf("%f \r\n", duty_cycle -= 0.01f);
+                                
+                                if(temp == '=') // you can hit the '+' key to increment "duration" without holding down "shift"
+                                {
+                                    if(pointer < 7) pointer++;
+                                    pc.printf("Duration[%i]: %i\r\n",pointer, duration[pointer]);
+                                }
+                                if(temp == '-')
+                                {
+                                    if(pointer > 0) pointer--;
+                                    pc.printf("Duration[%i]: %i\r\n",pointer, duration[pointer]);
+                                }
+                                if(temp == ']') // you can hit the '+' key to increment "duration" without holding down "shift"
+                                {
+                                    duration[pointer] += 1000;
+                                    pc.printf("             %i\r\n", duration[pointer]);
+                                }
+                                if(temp == '[')
+                                {
+                                    if(duration[pointer] > 0) duration[pointer]-= 1000;
+                                    pc.printf("             %i\r\n", duration[pointer]);
+                                }
+                                
+                            }
+                            
+                            */    
+                                
+                                
+                                
                             }
                         }
                     else {
@@ -378,6 +446,124 @@
         }
              
     } while (server.getStatus() == network::Socket::Listening);
+    
+    /*
+    while(1){
+        uint32_t current_SW3 = SW3_switch;      
+        if(pc.readable() > 0)
+        {
+            char temp = pc.getc();
+            while(pc.readable() > 0) pc.getc();
+            
+            if(temp == '1') current_SW3 = 0;
+            else current_SW3 = 1;
+            if(temp == '2') SW2_switch = 0;
+            else SW2_switch = 1;
+            
+            // for angle encoder testing
+            if(temp == 'a') pc.printf(angle_encoder.set_zero(&rotary_count)?"Zero set\r\n":"False\r\n");
+            if(temp == 's') pc.printf("NOP: %x\r\n",angle_encoder.nop());
+            if(temp == 'd') pc.printf("Angle: %i %i\r\n",angle_encoder.absolute_angle(), rotary_count);
+            
+            if(temp == 't')
+            {
+                
+                }
+            
+            
+            // for motor testing
+            if(temp == 'k') // motor backward
+            {
+                motor.backward(duty_cycle, duration[5]);
+                }
+            
+            if(temp == 'u' && duty_cycle < 1.00f) pc.printf("%f \r\n", duty_cycle += 0.01f);
+            if(temp == 'i' && duty_cycle > 0.00f) pc.printf("%f \r\n", duty_cycle -= 0.01f);
+            
+            if(temp == '=') // you can hit the '+' key to increment "duration" without holding down "shift"
+            {
+                if(pointer < 7) pointer++;
+                pc.printf("Duration[%i]: %i\r\n",pointer, duration[pointer]);
+            }
+            if(temp == '-')
+            {
+                if(pointer > 0) pointer--;
+                pc.printf("Duration[%i]: %i\r\n",pointer, duration[pointer]);
+            }
+            if(temp == ']') // you can hit the '+' key to increment "duration" without holding down "shift"
+            {
+                duration[pointer] += 1000;
+                pc.printf("             %i\r\n", duration[pointer]);
+            }
+            if(temp == '[')
+            {
+                if(duration[pointer] > 0) duration[pointer]-= 1000;
+                pc.printf("             %i\r\n", duration[pointer]);
+            }
+            
+        }
+        else
+        {
+            SW2_switch = 1;
+            current_SW3 = 1;
+        }
+        
+        if (current_SW3 == 0) {
+            
+            if (SW3_past == 1) {
+                pc.printf("All duration settings:\r\n");
+                for(int i = 0; i < 8; i++)
+                {
+                    pc.printf("Duration[%i]: %i\r\n", i, duration[i]);
+                    }
+                // release mallet
+                // add code here
+                
+                __enable_irq();     // Enable Interrupts
+                
+                current_sample_index = BEGIN_SAMPLING;
+                trigger_count++;
+                while (current_sample_index != WAITING_TO_BEGIN){
+                    wait_us(10);
+                    }    
+               
+               __disable_irq();    // Disable Interrupts
+               
+               // reset mallet
+               // add code here
+               
+            
+                output_data(trigger_count);
+                }
+            }
+        SW3_past = current_SW3;
+        
+        
+        if (SW2_switch == 0) { // To advance motor
+            pc.printf("All duration settings 2:\r\n");
+            for(int i = 0; i < 8; i++)
+            {
+                pc.printf("Duration[%i]: %i\r\n", i, duration[i]);
+                }
+            
+            
+            SW2_switch = 1;
+            
+            // release mallet
+            motor.forward(duration[0]); // move motor forward
+            wait_us(duration[1]); // wait
+            motor.backward(0.7, duration[2]); // stop motor using reverse
+            
+            // time for sampling
+            wait_us(SAMPLING_RATE*TOTAL_SAMPLES);
+            
+            // reset mallet
+            motor.backward(duration[3]);    // move motor backward
+            motor.backward(0.75, duration[4]);
+            motor.backward(duty_cycle, duration[5]);
+            
+            }
+            */
 }
 
 void timed_sampling() {