Last active
August 24, 2023 19:57
-
-
Save jfrux/d636fb587d79a003c3a89d1e007cc376 to your computer and use it in GitHub Desktop.
Revisions
-
jfrux revised this gist
Jan 16, 2018 . 1 changed file with 86 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ // // Traxxas 27Mhz Receiver Library #include <Servo.h> // RECEIVER DATA // MOTOR DATA Servo throttleMotor; int throttleMotorReceiverSignalPin = 2; // connect motor channel from receiver here. int throttleMotorSignalPin = 9; // connect directly to ESC throttle controller int throttleMotorValue; int throttleMotorNeutralValue = 97; int throttleMotorReceiverValue; // STEERING DATA Servo steeringServo; int steeringServoReceiverSignalPin = 4; // connect servo channel from receiver here. int steeringServoSignalPin = 10; // connect directly to steering servo. int steeringServoValue; int steeringServoNeutralValue = 97; int steeringServoReceiverValue; void setup() { Serial.begin(9600); // pinMode(throttleMotorSignalPin, INPUT); // pinMode(steeringServoSignalPin, INPUT); throttleMotor.attach(throttleMotorSignalPin); // attaches the servo on pin 9 to the servo object setThrottleSpeed(throttleMotorNeutralValue); // go to nuetral // steeringServo.attach(steeringServoSignalPin); // attaches the servo on pin 9 to the servo object // setSteeringValue(steeringServoNeutralValue); // go to nuetral //pinMode(13, OUTPUT); } void loop() { throttleMotorReceiverValue = pulseIn(throttleMotorReceiverSignalPin, HIGH, 20000); throttleMotorValue = map(throttleMotorReceiverValue, 520, 2370, 0, 180); // steeringServoReceiverValue = pulseIn(steeringServoReceiverSignalPin, HIGH, 10000); // steeringServoValue = map(steeringServoReceiverValue, 520, 2370, 0, 180); // Serial.println("Steering Servo Receiver Value: "); // Serial.println(steeringServoReceiverValue); // if (steeringServoReceiverValue == 0) { // //Signal timed out // setSteeringValue(steeringServoNeutralValue); // } else { // // digitalWrite(13, LOW); // everything's fine. // Serial.println("#################"); // // // Serial.print("Steering: "); // Serial.println(steeringServoValue); // } if(throttleMotorReceiverValue== 0) { // Signal timed out! // digitalWrite(13, HIGH); // ALERT! setThrottleSpeed(throttleMotorNeutralValue); // Go to neutral throttle position // setSteeringValue(steeringServoNeutralValue); // Go to neutral throttle position } else { // digitalWrite(13, LOW); // everything's fine. Serial.println("#################"); // setSteeringValue(steeringServoValue); // Repeat the data to the truck's ESC setThrottleSpeed(throttleMotorValue); // Repeat the data to the truck's ESC // Serial.print("Throttle Motor Pulse: "); // This part is used to debug the values for calibration // Serial.println(throttleMotorReceiverValue); Serial.print("Throttle: "); Serial.println(throttleMotorValue); // Serial.print("Steering: "); // Serial.println(steeringServoValue); } delay(1000); } void setThrottleSpeed(int speed) { // Serial.print("Setting Throttle to: "); // Serial.println(speed); throttleMotor.write(speed); } //void setSteeringValue(int steeringValue) { //// Serial.println("Setting Steering to: "); //// Serial.println(steeringValue); // steeringServo.write(steeringValue); //} -
jfrux revised this gist
Jan 16, 2018 . 2 changed files with 60 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ #include "Servo.h" Servo myServo1; Servo myServo2; int angle=90; int thrust=90; int sensorValue=8; char incoming = ""; void setup() { pinMode(sensorValue, INPUT); myServo1.attach(9); myServo1.attach(10); Serial.begin(19200); } void loop() { if (Serial.available()) { incoming=Serial.read(); if(incoming=='8') { thrust += 1; } else if(incoming == '2') { thrust -= 1; } else if (incoming == '5') { thrust = 90; } if (incoming=='4') { angle += 1; } if (incoming=='6') { angle -= 1; } if (incoming == '7') { angle = 179; } if (incoming == '9') { angle = 0; } if (incoming == '/') { angle = 90; } } myServo1.write(thrust); myServo2.write(angle); Serial.print("sensor: "); Serial.print(digitalRead(sensorValue)); Serial.print(", thrust: "); Serial.print(thrust); Serial.print(", angle: "); Serial.println(angle); delay(1500); } File renamed without changes. -
jfrux created this gist
Jan 14, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ #include <Servo.h> int controlMode = 2; // 1 = transmitter, 2 = override Servo steeringServo; byte steeringRxPin = 3; byte steeringControlPin = 9; int steeringNeutral = 90; int steeringPwmValue; int steeringRxValue; int steeringOverrideValue = -1; Servo throttleMotor; byte throttleRxPin = 5; byte throttleControlPin = 10; int throttleNeutral = 90; int throttlePwmValue; int throttleRxValue; int throttleOverrideValue = -1; void setup() { pinMode(steeringRxPin, INPUT); pinMode(throttleRxPin, INPUT); throttleMotor.attach(throttleControlPin); steeringServo.attach(steeringControlPin); setThrottle(90); setSteering(90); Serial.begin(9600); } void loop() { throttlePwmValue = pulseIn(throttleRxPin, HIGH); throttleRxValue = map(throttlePwmValue, 890, 2053, 0, 180); Serial.print("Throttle: "); Serial.println(throttleRxValue); steeringPwmValue = pulseIn(steeringRxPin, HIGH); steeringRxValue = map(steeringPwmValue, 990, 1993, 0, 180); Serial.print("Steering: "); Serial.println(steeringRxValue); if (controlMode == 1) { // Controlling with Transmitter setThrottle(throttleRxValue); setSteering(steeringRxValue); } else if (controlMode = 2) { // setThrottle(throttleOverrideValue); // } } else { } delay(2000); } void setThrottle(int speed) { Serial.print("Setting Throttle to: "); Serial.println(speed); throttleMotor.write(speed); } void setSteering(int speed) { Serial.println("Setting Steering to: "); Serial.println(speed); steeringServo.write(speed); }