test

Dependencies:   mbed Watchdog stm32-sensor-base2

Files at this revision

API Documentation at this revision

Comitter:
ruslanbredun
Date:
Fri Nov 05 14:39:08 2021 +0000
Parent:
18:025d9a617769
Commit message:
LastFirmWare05/11/21;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 025d9a617769 -r 7935ca386e13 main.cpp
--- a/main.cpp	Fri Nov 05 13:48:42 2021 +0000
+++ b/main.cpp	Fri Nov 05 14:39:08 2021 +0000
@@ -1,20 +1,37 @@
 #include <global.h>
 
 Serial RS2(UART2_TX, UART2_RX);
+Serial RS1(UART1_TX, UART1_RX);
+
+DigitalOut Select1(DE_TXD_1);
+DigitalOut Select2(DE_TXD_2);
+
+AS5045 Enc_left(SP1_NSS1);
+AS5045 Enc_right(SP1_NSS2);
+
+E18_D80NK IR_sensor_left (PB_13);
+E18_D80NK IR_sensor_right (PB_12);
+
+DigitalIn  Lift1 (PB_0);
+DigitalIn  Lift2 (PB_1); 
+
+JSN_SR04 US_sensor_left (PB_14, PA_9);
+JSN_SR04 US_sensor_middle (PB_15, PA_9);
+JSN_SR04 US_sensor_right (PA_8, PA_9);  
+
+OneWire oneWire(PA_11);        // substitute D8 with the actual pin name connected to the 1-wire bus
 
 Timer timer;
 Watchdog  watchDog;
 
 typedef uint8_t byte;
 
-DigitalOut Select2(DE_TXD_2);
 
-AS5045 Enc_left(SP1_NSS1);
-AS5045 Enc_right(SP1_NSS2);
+char c = '1';
+int Enc_left_data = 0, Enc_right_data = 0, sensorsFound = 0, US1_data = 0,US2_data = 0, US3_data = 0, Lift_IR1 = 0,Lift_IR2 = 0;
+bool IR1_data = 0,IR2_data = 0, sendFlag = false;
+float temp_one_value = -1, temp_two_value = -1;
 
-bool sendFlag = false;
-char c = '1';
-int Enc_left_data = 0, Enc_right_data = 0;
 
 void Encoders()
 {
@@ -28,6 +45,7 @@
     wait_ms(3);
     Select1 = 0;
 }
+
 void UART2_callback()
 {
     c =  RS2.getc();
@@ -39,39 +57,23 @@
         Select2 = 0;
     }
 }
-
 int main()
 {
+    RS1.baud (115200);
     RS2.baud (115200);
+    RS2.attach(&UART2_callback); 
+    
     Select1 = 0;
-    Select2 = 0;
-    RS2.attach(&UART2_callback);
-
-    int US1_data = 0,US2_data = 0, US3_data = 0, Lift_IR1 = 0,Lift_IR2 = 0;
-    bool IR1_data = 0,IR2_data = 0;
-    //float temp_one_value = -1, temp_two_value = -1;//, currentTime = 0, previousTime = 0;
+    Select2 = 0; 
 
     timer.start();
 
-    watchDog.Configure(5.0);
-
-    //OneWire oneWire(PA_11);        // substitute D8 with the actual pin name connected to the 1-wire bus
-    int sensorsFound = 0;
-
-    DigitalIn  Lift1 (PB_0);
-    DigitalIn  Lift2 (PB_1);    
-
-    JSN_SR04 US_sensor_left (PB_14, PA_9);
-    JSN_SR04 US_sensor_middle (PB_15, PA_9);
-    JSN_SR04 US_sensor_right (PA_8, PA_9);
+    watchDog.Configure(5.0); 
 
     US_sensor_left.setRanges (20, 300);
     US_sensor_middle.setRanges (20, 300);
     US_sensor_right.setRanges (20, 300);
 
-    E18_D80NK IR_sensor_left (PB_13);
-    E18_D80NK IR_sensor_right (PB_12);
-
     for (sensorsFound = 0; sensorsFound < MAX_SENSOSRS; sensorsFound++) {
         ds1820[sensorsFound] = new DS1820(&oneWire);
         if (!ds1820[sensorsFound]->begin()) {
@@ -82,26 +84,32 @@
 
     while (true) {
         watchDog.Service();
+        
         Encoders();
+        
         for (int i = 0; i < sensorsFound; i++) {
             ds1820[i]->startConversion();
             wait_ms(1);
         }
+        
         Encoders();
 
         US_sensor_left.startMeasurement ();
         US1_data = US_sensor_left.getDistance_cm ();
         wait_ms(20);
+        
         Encoders();
 
         US_sensor_middle.startMeasurement ();
         US2_data = US_sensor_middle.getDistance_cm ();
         wait_ms(20);
+        
         Encoders();
 
         US_sensor_right.startMeasurement ();
         US3_data = US_sensor_right.getDistance_cm ();
         wait_ms(20);
+        
         Encoders();
 
         IR1_data = IR_sensor_left.checkObstacle ();
@@ -109,37 +117,26 @@
 
         Lift_IR1 = Lift1.read();
         Lift_IR2 = Lift2.read();
+        
         Encoders();
 
-
         if (ds1820[0]->isPresent() ) {
             temp_one_value = ds1820[0]->read();
         }
         if (ds1820[1]->isPresent() ) {
             temp_two_value = ds1820[1]->read();
         }
-        Encoders();
         
-        if(US2_data < 100){
-           Select2 = 1;
-            RS2.printf ("Left Obstacle\r\n");
-            wait_ms(200);
-            Select2 = 0;
-        }
-        if(US3_data < 100){
-            Select2 = 1;
-            RS2.printf ("Right Obstacle\r\n");
-            wait_ms(200);
-            Select2 = 0;
-        }
+        Encoders();   
 
         if(sendFlag) {
             Select2 = 1;
-            RS2.printf ("%d_%d_%d_%d_%d_%d_%d\r\n", US1_data, US2_data, US3_data, IR1_data, IR2_data, Lift_IR1, Lift_IR2);  //,(int)((Vcc -24 ) * 5 + 50));
+            RS2.printf ("%d_%d_%d_%d_%d_%d_%d_%f_%f\r\n", US1_data, US2_data, US3_data, IR1_data, IR2_data, Lift_IR1, Lift_IR2, temp_one_value, temp_two_value);  
             wait_ms(5);
             sendFlag = false;
             Select2 = 0;
         }
+        
         Encoders();
     }
 }
\ No newline at end of file