AlphaBot: Verzweigung: Unterschied zwischen den Versionen

Aus HSHL Mechatronik
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „'''Autor:''' Prof. Dr.-Ing. Schneider == Inhalt des vierten Termins == * Wir haben die Motoransteuerung geändert, so dass Alf…“)
 
Keine Bearbeitungszusammenfassung
Zeile 11: Zeile 11:
* <code>E13_Photo_Interrupter_Sensor</code>
* <code>E13_Photo_Interrupter_Sensor</code>
* <code>E14_Wheel_Encoders</code>
* <code>E14_Wheel_Encoders</code>
<!--
 
<div style="width:1200px; height:300px; overflow:auto; border: 2px solid #088">
<div style="width:1200px; height:300px; overflow:auto; border: 2px solid #088">
<pre>
<pre>
/* Deklaration */
/* Deklaration */
#include "AlphaBot.h"                  // Arduino Bibliothek einbinden     
#include <Servo.h>


AlphaBot Alf = AlphaBot();             // Instanz des AphaBot wird erzeugt
Servo US_SERVO; // create servo object to control a servo


//const byte GESCHWINDIGKEIT_u8 = 80;     // Geschw. wählbar: 0 - 255; Min: 80
int potpin = 0;  // analog pin used to connect the potentiometer
int val;   // variable to read the value from the analog pin


void setup()
void setup() {
{
   US_SERVO.attach(9); // attaches the servo on pin 9 to the servo object
   // Wird einmalig beim Start ausgeführt
   Serial.begin(9600); // init für Serielle ausgabe
  Alf.SetSpeed(80);     // Geschw. setzen: 0 - 255
  Alf.Forward(1000);    // AlphaBot fährt für 1s mit beiden Motoren vorwärts
  Alf.Brake();          // AlphaBot bremst
   Serial.begin(9600);     // Serielle Übertragung mit 9600 Bit/s starten
  Serial.println("SETUP");
}
}


void loop()
void loop() {
{  
   val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
   // Wird zyklisch ausgeführt
  Serial.println(val);
   delay(1000);           // 1s Warten
   val = map(val, 0, 676, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
   Serial.println("Loop"); // Im Loop passiert nichts.
   US_SERVO.write(val);
//  for (int i=0;4;i++)
//  {
//    US_SERVO.write(0);
//    delay(500);
//    US_SERVO.write(90);
//    delay(500);
//   US_SERVO.write(180);
//    delay(500); 
//  }
                  // sets the servo position according to the scaled value
  delay(20);                          // waits for the servo to get there
}
}



Version vom 31. März 2022, 15:12 Uhr

Autor: Prof. Dr.-Ing. Schneider

Inhalt des vierten Termins

  • Wir haben die Motoransteuerung geändert, so dass Alf ein Dreieck gefahren ist.
  • Wir haben uns die Inkrementalgeber angeschaut und die Werte mit dem Demo E13_Photo_Interrupter_Sensor angezeigt.
  • Anschließend haben wir die Umdrehungen gezählt (E14_Wheel_Encoders).
  • Wir haben den Radumfang berechnet: .
  • Fazit: Drehen beider Räder um 360 °, dann fährt der Roboter 20,1 cm vorwärts.

Quelltext

  • E13_Photo_Interrupter_Sensor
  • E14_Wheel_Encoders
/* Deklaration */
#include <Servo.h>

Servo US_SERVO;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  US_SERVO.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);  // init für Serielle ausgabe
}

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Serial.println(val);
  val = map(val, 0, 676, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  US_SERVO.write(val);
//  for (int i=0;4;i++)
//  {
//    US_SERVO.write(0); 
//    delay(500);
//    US_SERVO.write(90);
//    delay(500);
//    US_SERVO.write(180);
//    delay(500);  
//  }
                   // sets the servo position according to the scaled value
  delay(20);                           // waits for the servo to get there
}

-->

Hausaufgaben bis zum 4. Termin

Fahre genau 30 cm geradeaus.

Musterlösung


→ zurück zum Hauptartikel: Projekt Alf