Benutzer-Werkzeuge

Webseiten-Werkzeuge


privat:projekte:rasenmaeherroboter:fernsterung:arduinocode

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
privat:projekte:rasenmaeherroboter:fernsterung:arduinocode [2025/12/28 09:49] vitalijprivat:projekte:rasenmaeherroboter:fernsterung:arduinocode [2026/01/19 17:41] (aktuell) – old revision restored vitalij
Zeile 1: Zeile 1:
-Notizen +{{.:pasted:20251228-094748.png}}
- +
-// Channel 2 für geschwindigkeit +
-// channel 1 für links und rechts +
- +
-#include <AFMotor.h> +
-AF_DCMotor motor1(1, MOTOR12_64KHZ); // erzeuge objekt motor an +
-AF_DCMotor motor2(2, MOTOR12_64KHZ); // erzeuge objekt motor an +
-AF_DCMotor motor3(3, MOTOR12_64KHZ); // erzeuge objekt motor an +
- +
-int PWM_PIN22 = 17; //Define Digital PIN +
-int PWM_PIN18 = 18; //Define Digital PIN +
-int PWM_PIN19 = 19; //Define Digital PIN +
-int PWM_PIN20 = 20; //Define Digital PIN +
-int PWM_PIN21 = 21; //Define Digital PIN +
- +
- +
-void setup() { +
- +
- +
-  pinMode(PWM_PIN18, OUTPUT); +
-   +
-  pinMode(PWM_PIN19, INPUT); +
-  pinMode(PWM_PIN20, INPUT); +
-  pinMode(PWM_PIN21, INPUT); +
-  pinMode(PWM_PIN22, INPUT); +
-  Serial.begin(115200); +
-+
- +
-void loop() { +
-//Serial.print("tick"); +
- int pwm1 = pulseIn(PWM_PIN19, HIGH); //Read PWM Pulse +
- int pwm2 = pulseIn(PWM_PIN20, HIGH); //Read PWM Pulse +
- int pwm3 = pulseIn(PWM_PIN21, HIGH); //Read PWM Pulse +
- +
- int maehen = pulseIn(PWM_PIN22, HIGH); //Read PWM Pulse +
-// int maehen = digitalRead(PWM_PIN22); //Read PWM Pulse +
- +
- +
- int a = pulseToPWM(pwm1); //-1*(499-(pwm1-996))/2; +
- int b = pulseToPWM(pwm2); +
- int c = pulseToPWM(pwm3); +
- //int c = 499-(pwm3-996); +
-  +
- //int d = 499-(maehen-996); +
- int d = pulseToPWM(maehen); +
-   +
- // Serial.print("PWM CH1: "); +
- // Serial.print(a); +
-//  Serial.print(" PWM CH2: "); +
-//  Serial.print(b); +
-//  Serial.print(" PWM CH3: "); +
-//  Serial.println(c);        +
-  Serial.print(" PWM maehen: "); +
-  Serial.println(maehen);                  +
- +
-if (a>0) { +
-  motor1.run(FORWARD); +
-  motor1.setSpeed(abs(a)); +
-+
-else if (a<0) { +
-  motor1.run(BACKWARD); +
-  motor1.setSpeed(abs(a)); +
-+
-else { +
-  motor1.run(RELEASE); // Motor stopp +
-+
- +
-if (b>0) { +
-  motor2.run(FORWARD); +
-  motor2.setSpeed(abs(b)); +
-+
-else if (b<0) { +
-  motor2.run(BACKWARD); +
-  motor2.setSpeed(abs(b)); +
-+
-else { +
-  motor2.run(RELEASE); // Motor stopp +
-+
- +
- +
-if (d>0){ +
-  motor3.run(BACKWARD); +
-  motor3.setSpeed(d); +
-}else { +
-  motor3.run(RELEASE); // Motor stopp +
-+
- +
-+
- +
-int pulseToPWM(int pulse) { +
- +
-const int deadzone = 10; +
-const int hlevel = 1998; //höchste gelieferte Frequenz +
-const int llevel = 996; //niedrigste gelieferte Frequenz +
-const int glevel = 255; //Grenzlevel für Ergebnis +
- +
-if (pulse > 100) { // nur Werte > 100 verwerten, andere sind Störung oder Sender off +
- +
-pulse = map(pulse, llevel, hlevel, -500, 500); // Ausgabewertebereich verschieben +
- +
-pulse = constrain(pulse, -glevel, glevel); // und jetzt noch begrenzen +
-} else { +
- +
-pulse = 0; // keine sinnvollen Impulse +
-+
- +
-// Ruhezone einrichten +
-if (abs(pulse) <= deadzone) { +
-pulse = 0; +
-+
- +
-return pulse; +
-+
- +
- +
-https://learn.adafruit.com/adafruit-motor-shield/af-dcmotor-class +
-https://www.halloweenfreak.de/arduino/pdfs/motor_shield.pdf +
- +
- +
-PWM Output Sketch +
- +
-Aus < https://dronebotworkshop.com/radio-control-arduino-car/>  +
- +
- +
-Arduino FS-I6X Demo +
-C++ +
-/* +
-  Arduino FS-I6X Demo +
-  fsi6x-arduino-uno.ino +
-  Read output ports from FS-IA6B receiver module +
-  Display values on Serial Monitor +
-   +
-  Channel functions by Ricardo Paiva - https://gist.github.com/werneckpaiva/ +
-   +
-  DroneBot Workshop 2021 +
-   https://dronebotworkshop.com +
-*/ +
- +
-// Define Input Connections +
-#define CH1 3 +
-#define CH2 5 +
-#define CH3 6 +
-#define CH4 9 +
-#define CH5 10 +
-#define CH6 11 +
- +
-// Integers to represent values from sticks and pots +
-int ch1Value; +
-int ch2Value; +
-int ch3Value; +
-int ch4Value;  +
-int ch5Value; +
- +
-// Boolean to represent switch value +
-bool ch6Value; +
- +
-// Read the number of a specified channel and convert to the range provided. +
-// If the channel is off, return the default value +
-int readChannel(int channelInput, int minLimit, int maxLimit, int defaultValue){ +
-  int ch = pulseIn(channelInput, HIGH, 30000); +
-  if (ch < 100) return defaultValue; +
-  return map(ch, 1000, 2000, minLimit, maxLimit); +
-+
- +
-// Read the switch channel and return a boolean value +
-bool readSwitch(byte channelInput, bool defaultValue){ +
-  int intDefaultValue = (defaultValue)? 100: 0; +
-  int ch = readChannel(channelInput, 0, 100, intDefaultValue); +
-  return (ch > 50); +
-+
- +
-void setup(){ +
-  // Set up serial monitor +
-  Serial.begin(115200); +
-   +
-  // Set all pins as inputs +
-  pinMode(CH1, INPUT); +
-  pinMode(CH2, INPUT); +
-  pinMode(CH3, INPUT); +
-  pinMode(CH4, INPUT); +
-  pinMode(CH5, INPUT); +
-  pinMode(CH6, INPUT); +
-+
- +
- +
-void loop() { +
-   +
-  // Get values for each channel +
-  ch1Value = readChannel(CH1, -100, 100, 0); +
-  ch2Value = readChannel(CH2, -100, 100, 0); +
-  ch3Value = readChannel(CH3, -100, 100, -100); +
-  ch4Value = readChannel(CH4, -100, 100, 0); +
-  ch5Value = readChannel(CH5, -100, 100, 0); +
-  ch6Value = readSwitch(CH6, false); +
-   +
-  // Print to Serial Monitor +
-  Serial.print("Ch1: "); +
-  Serial.print(ch1Value); +
-  Serial.print(" | Ch2: "); +
-  Serial.print(ch2Value); +
-  Serial.print(" | Ch3: "); +
-  Serial.print(ch3Value); +
-  Serial.print(" | Ch4: "); +
-  Serial.print(ch4Value); +
-  Serial.print(" | Ch5: "); +
-  Serial.print(ch5Value); +
-  Serial.print(" | Ch6: "); +
-  Serial.println(ch6Value); +
-   +
-  delay(500); +
-+
- +
-Aus < https://dronebotworkshop.com/radio-control-arduino-car/>  +
- +
- +
- +
- +
-Arduino Mega 2560 Hookup +
- +
-Aus < https://dronebotworkshop.com/radio-control-arduino-car/>  +
- +
- +
-Code +
-The Code for the Arduino RC Car +
-arduino +
-Again, try to understand how it works! +
- +
-Aus < https://projecthub.arduino.cc/enriquelopezprojects/arduino-rc-car-with-flysky-fs-i6x-controller-and-receiver-35b7fb>  +
- +
-{{.:pasted:20251228-094911.png}}+
privat/projekte/rasenmaeherroboter/fernsterung/arduinocode.1766915352.txt.gz · Zuletzt geändert: von vitalij