浏览代码

changed US timing to avoid serial crash

subDesTagesMitExtraKaese 3 年之前
父节点
当前提交
a2cf5b1d1e
共有 4 个文件被更改,包括 14 次插入10 次删除
  1. 2 3
      arduino/src/main.cpp
  2. 5 2
      arduino/src/ultrasonic.cpp
  3. 5 5
      raspberry-pi/config.ini
  4. 2 0
      raspberry-pi/sensors/connection.py

+ 2 - 3
arduino/src/main.cpp

@@ -42,9 +42,6 @@ void loop() {
   if(micros() >= loopStart + LOOP_INTERVAL_US) {
     loopStart = micros();
 
-    //emit ultrasound pulse
-    us_transmit();
-
     //get mpu values
     mpu.update();
 
@@ -72,6 +69,8 @@ void loop() {
 
     blinkLed();
 
+    //emit ultrasound pulse
+    us_transmit();
   }
 
 }

+ 5 - 2
arduino/src/ultrasonic.cpp

@@ -48,8 +48,11 @@ void us_transmit() {
   //pull pin 2, 3 and 4 to 5V
   //doing this seems to lead to power supply issues and the serial interface stopps working
   //further testing needed!
-  PORTD |= 0b00011100;
-
+  PORTD = (PORTD & 0b11100011) | 0b00000100;
+  delayMicroseconds(5);
+  PORTD = (PORTD & 0b11100011) | 0b00001000;
+  delayMicroseconds(5);
+  PORTD = (PORTD & 0b11100011) | 0b00010000;
   delayMicroseconds(5);
 
   //pull pin 2, 3 and 4 to GND

+ 5 - 5
raspberry-pi/config.ini

@@ -2,9 +2,9 @@
 # size of the trackable area
 [field]
   # width in mm
-  x = 450
+  x = 380
   # height in mm
-  y = 450
+  y = 380
 
 [arduino]
   # leave port empty for auto config
@@ -14,7 +14,7 @@
 # acoustic sensor config
 [ac_sensor]
   # distance of the sensors in front of y=0 in mm
-  y_offset = 10
+  y_offset = 50
 
   # left sensor x offset to the right border at x=0 in mm 
   left_x_offset = 0
@@ -28,8 +28,8 @@
 
   # default arduino timing overhead in us
   # only used before calibration
-  overhead_left  = 150
-  overhead_right = 100
+  overhead_left  = 200
+  overhead_right = 200
 
 [mag_sensor]
 

+ 2 - 0
raspberry-pi/sensors/connection.py

@@ -152,6 +152,8 @@ class ArduinoSlave(SerialConnection):
           self.sensorData = vals[1:]
           for cb in self._recvCbs:
             cb(self.sensorData)
+        elif data.startswith("I2C ERROR"):
+          pass
         else:
           self.log_handler.log_and_print("SERIAL: ", data[:-2])