User Tools

Site Tools


projects:farmrobot:hinderniserkennung_mit_sonar

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
projects:farmrobot:hinderniserkennung_mit_sonar [2021/02/21 12:14]
tobias
projects:farmrobot:hinderniserkennung_mit_sonar [2021/02/24 20:44] (current)
tobias [Aufbau]
Line 1: Line 1:
 ====== Sonar ====== ====== Sonar ======
  
-Um zu verhindern das der Farm Robot mit voller Kraft in Objekte oder sogar Personen fährt, wurden Sonarsenosren angebracht, welche den Roboter stoppen, falls er sich etwas nährt.+Um zu verhindern das der Farm Robot mit voller Kraft in Objekte oder sogar Personen fährt, wurden Sonarsensoren angebracht, welche den Roboter stoppen, falls er sich etwas nährt.
  
 ==== Aufbau ==== ==== Aufbau ====
Line 7: Line 7:
 Es sind acht [[https://elektro.turanis.de/html/prj121/index.html | HC-SR04]] Sensoren mit einem Arduino Mega verbunden, zwei für jede Seite. Es sind acht [[https://elektro.turanis.de/html/prj121/index.html | HC-SR04]] Sensoren mit einem Arduino Mega verbunden, zwei für jede Seite.
  
-**BILD ANSCHLUSS AN ARUDIONO (MÖGLICHST AKTUELL, ALSO MIT LANGEN KABELN)**+{{:projects:farmrobot:sensoren_angeschlossen.jpg?400|}}
  
-Die Sensoten sind mithilfe von Mounts am Farm Robot angebracht, welche mit Fusion 360 erstellt und anschließend vom 3D-Drucker ausgedruckt wurden.+Die Sensoren sind mithilfe von Mounts am Farm Robot angebracht, welche mit Fusion 360 erstellt und anschließend vom 3D-Drucker ausgedruckt wurden.
  
-**BILD SENSOREN AM FARM ROBOT**+{{:projects:farmrobot:sensor_farm_robot.jpg?400|}}
  
-==== Code ====+Der Arduino ist Seriell mit dem Telem1 Port des Pixhawks verbunden und wird auch vom Pixhawk mit Strom versorgt.
  
-Der Code wertet die Daten der Sensoren aus und sendet ein `LOW` Signal, sobald etwas zu nah kommt.+{{:projects:farmrobot:arduino_pixhawk.png?400|}} 
 + 
 +Zusätzlich müssen in der Full Parameter List zwei Eigenschaften des Telem1 Ports eingestellt werden. 
 + 
 +^ Command           ^ Value  ^ 
 +| SERIAL1_Baud      | 57     | 
 +| SERIAL1_PROTOCOL  | 2      | 
 + 
 + 
 +==== Code ====
  
-> Später hoffentlich: +Der Code wertet die Daten der Sensoren aus und sendet mithilfe von [MAVLink](https://mavlink.io/en/) ein disarm Befehl, sobald etwas zu nah kommt
-Der Code wertet die Daten der Sensoren aus und sendet mithilfe von [MAVLink](https://mavlink.io/en/) ein Stopp Signal, sobald etwas zu nah kommt.+Der Code verwendet eine [[https://github.com/mavlink/mavlink | MAVLink library ]], welche zuvor [[https://discuss.ardupilot.org/uploads/default/original/2X/0/064748b43308485aa9bd0d86fb91d74e17ed8c2a.zip | gedownloadet]] und eingebunden werden muss.
  
  
Line 26: Line 35:
     Ultrasonic sensor Pins:     Ultrasonic sensor Pins:
         VCC: +5VDC         VCC: +5VDC
-        Trig : Trigger (INPUT) - Pin12 +        Trig : Trigger (INPUT) 
-        Echo: Echo (OUTPUT) - Pin 13+        Echo: Echo (OUTPUT)
         GND: GND         GND: GND
  */  */
 +#include <mavlink.h>
  
 int echoPin0 = 22;    // Echo int echoPin0 = 22;    // Echo
Line 50: Line 60:
 int outPin = 1; int outPin = 1;
  
-long distance = 20; // in cm+long distance = 95; // in cm
  
 long duration0, cm0; long duration0, cm0;
Line 60: Line 70:
 long duration6, cm6; long duration6, cm6;
 long duration7, cm7; long duration7, cm7;
 +
 +// MAVLink
 +mavlink_message_t msg;
 +uint8_t buf[MAVLINK_MAX_PACKET_LEN];
 +uint16_t len;
  
 void setup() { void setup() {
   //Serial Port begin   //Serial Port begin
-  Serial.begin (9600);+  Serial.begin (57600); 
 +  Serial1.begin (57600); 
   //Define inputs and outputs   //Define inputs and outputs
   pinMode(echoPin0, INPUT);   pinMode(echoPin0, INPUT);
Line 184: Line 201:
   // Check if something gets to close   // Check if something gets to close
   if(cm0 <= distance || cm1 <= distance || cm2 <= distance || cm3 <= distance || cm4 <= distance || cm5 <= distance || cm6 <= distance || cm7 <= distance){   if(cm0 <= distance || cm1 <= distance || cm2 <= distance || cm3 <= distance || cm4 <= distance || cm5 <= distance || cm6 <= distance || cm7 <= distance){
-    digitalWrite(outPinLOW); +    mavlink_msg_command_long_pack(2550, &msg, 1, 0, MAV_CMD_COMPONENT_ARM_DISARM, 0, 0, 0, 0, 0, 0, 0, 0); 
-    Serial.println("LOW");+    // mavlink_msg_command_long_pack(0xFF, 0xBE, &msg, 1, 1, 400, 1,0.0,0,0,0,0,0,0); 
 +    len = mavlink_msg_to_send_buffer(buf, &msg); 
 + 
 +    // Send the message (.write sends as bytes) 
 +    Serial.write(buf, len); 
 +    Serial.println("Too close!"); 
 +    Serial1.write(buf, len);
   }else{   }else{
-    digitalWrite(outPin, HIGH); +    Serial.println("Nothing close!");
-    Serial.println("HIGH");+
   }   }
 } }
 </code> </code>
projects/farmrobot/hinderniserkennung_mit_sonar.1613909643.txt.gz · Last modified: 2021/02/21 12:14 by tobias