Metainformationen zur Seite
  •  

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
computer:basteln:servo [2011/04/25 11:04]
ristigl angelegt
computer:basteln:servo [2018/03/16 21:11] (aktuell)
Zeile 1: Zeile 1:
 ====== Servos ====== ====== Servos ======
 +{{wp>​servo}}
  
   * http://​www.arduino.cc/​playground/​Learning/​SingleServoExample   * http://​www.arduino.cc/​playground/​Learning/​SingleServoExample
Zeile 10: Zeile 11:
   * http://​www.waggers.de/​kap/​servoumbau.php   * http://​www.waggers.de/​kap/​servoumbau.php
  
 +===== Steuerung von Servos =====
 +Nach den ersten Erfolgen war ich überrascht,​ dass die Servos nicht exakt das taten, was ich erwarte. Die Winkel stimmten nicht. Nachfolgend ein Programm, mit dem ihr die Ansteuerung eurer Servos prüfen könnt. Ihr könnt den Servo über den Serialmonitor von Arduino steuern. Das Programm gibt die Aktuelle Pulsweite zurück, so dass ihr die Grenzen ermitteln könnt.
 +
 +Bedienung: <​key>​.</​key>​ und <​key>,</​key>​ zum Verstellen <​key>​space</​key>​ für die Mittelstellung.
 +Quelle: http://​principialabs.com/​arduino-serial-servo-control/​
 +<code cpp>
 +/* 
 + * NewSerialServo ​
 + * -------------- ​
 + * Servo control from the Serial port 
 + ​* ​
 + * Alteration of the control interface to use < and > keys 
 + * to slew the servo horn left and right. ​ Works best with 
 + * the Linux/Mac terminal "​screen"​ program. ​
 + ​* ​
 + * Created 10 December 2007 
 + * copyleft 2007 Brian D. Wendt 
 + * http://​principialabs.com/ ​
 + ​* ​
 + * Adapted from code by Tom Igoe 
 + * http://​itp.nyu.edu/​physcomp/​Labs/​Servo ​
 + ​*/  ​
 +  ​
 +/** Adjust these values for your servo and setup, if necessary **/  ​
 +int servoPin ​    ​= ​ 10;    // control pin for servo motor  ​
 +int minPulse ​    ​= ​ 300;  // minimum servo position  ​
 +int maxPulse ​    ​= ​ 6000; // maximum servo position  ​
 +int turnRate ​    ​= ​ 100;  // servo turn rate increment (larger value, faster rate)  ​
 +int refreshTime ​ =  20;   // time (ms) between pulses (50Hz)  ​
 +  ​
 +/** The Arduino will calculate these values for you **/  ​
 +int centerServo; ​        // center servo position  ​
 +int pulseWidth; ​         // servo pulse width  ​
 +int moveServo; ​          // raw user input  ​
 +long lastPulse ​  = 0;    // recorded time (ms) of the last pulse  ​
 +  ​
 +  ​
 +void setup() {  ​
 +  pinMode(servoPin,​ OUTPUT); ​ // Set servo pin as an output pin  ​
 +  centerServo = maxPulse - ((maxPulse - minPulse)/​2);  ​
 +  pulseWidth = centerServo; ​  // Give the servo a starting point (or it floats)  ​
 +  Serial.begin(4800);  ​
 +  Serial.println(" ​     Arduino Serial Servo Control"​);  ​
 +  Serial.println("​Press < or > to move, spacebar to center"​);  ​
 +  Serial.println();  ​
 +}  ​
 +  ​
 +void loop() {  ​
 +  // wait for serial input  ​
 +  if (Serial.available() > 0) {  ​
 +    // read the incoming byte:  ​
 +    moveServo = Serial.read();  ​
 +  ​
 +    // ASCII '<'​ is 44, ASCII '>'​ is 46 (comma and period, really)  ​
 +    if (moveServo == 44) { pulseWidth = pulseWidth - turnRate; }  ​
 +    if (moveServo == 46) { pulseWidth = pulseWidth + turnRate; }  ​
 +    if (moveServo == 32) { pulseWidth = centerServo;​ }  ​
 +  ​
 +    // stop servo pulse at min and max  ​
 +    if (pulseWidth > maxPulse) { pulseWidth = maxPulse; }  ​
 +    if (pulseWidth < minPulse) { pulseWidth = minPulse; }  ​
 +    Serial.print("​pulseWidth:​ ");
 +    Serial.println(pulseWidth,​DEC);​
 +    // print pulseWidth back to the Serial Monitor (uncomment to debug)  ​
 +    // Serial.print("​Pulse Width: "​);  ​
 +    // Serial.print(pulseWidth);  ​
 +    // Serial.println("​us"​); ​  // microseconds  ​
 +  }  ​
 +  ​
 +  // pulse the servo every 20 ms (refreshTime) with current pulseWidth  ​
 +  // this will hold the servo'​s position if unchanged, or move it if changed  ​
 +  if (millis() - lastPulse >= refreshTime) {  ​
 +    digitalWrite(servoPin,​ HIGH); ​  // start the pulse  ​
 +    delayMicroseconds(pulseWidth); ​ // pulse width  ​
 +    digitalWrite(servoPin,​ LOW);    // stop the pulse  ​
 +    lastPulse = millis(); ​          // save the time of the last pulse  ​
 +  }  ​
 +}
 +</​code>​