Wie repariere ich meinen bürstenlosen Motor nicht mit meinem Arduino ESP-32-Nano?C++

Programme in C++. Entwicklerforum
Anonymous
 Wie repariere ich meinen bürstenlosen Motor nicht mit meinem Arduino ESP-32-Nano?

Post by Anonymous »

Ich kodiere ein RC-Auto in der Arduino-IDE. /> < /ul>
Der Empfänger und der Absender sind beide der gleiche Arduino und kommunizieren korrekt. Lenkung und Vorwärts funktionieren gut, es wird umgekehrt, die überhaupt nicht funktioniert. < /P>
Was muss ich tun oder sehe ich nicht?

Code: Select all

#include 
#include 
#include 
#include 

typedef struct struct_message {
int steering_stick;
int accelerating_stick;
} struct_message;

struct_message myReceivedData;
Servo steeringServo;
Servo ESC;

// Keep original pin definitions
const int steeringPin = 4;
const int escPin = 6;

// Maintain original mapping constants for accelerating stick
const int deadzoneLow = 1920;
const int deadzoneHigh = 1940;
const int idlePulse = 850;         // Confirmed neutral pulse is 1000μs
const int forwardMinPulse = 1100;   // Forward begins at this value
const int forwardMaxPulse = 2000;   // Full forward
const int reverseMinPulse = 500;    // Modified: Less aggressive reverse
const int reverseMaxPulse = 950;    // Approach neutral from below

// Keep original steering constants
const int steerMin = 60;
const int steerMax = 130;

// Variables for state tracking
int lastAccel = -1;
int lastSteer = -1;
bool motorBraked = false;          // Track if motor is in braked state
unsigned long brakeStartTime = 0;   // When braking began
const unsigned long brakeHoldTime = 2000; // Hold time in brake/neutral before reverse

// ESC initialization flags
bool escInitialized = false;
bool reverseModeEnabled = false;

void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
memcpy(&myReceivedData, incomingData, sizeof(myReceivedData));

// Keep the original logging logic
if (myReceivedData.accelerating_stick != lastAccel || myReceivedData.steering_stick != lastSteer) {
Serial.println("Received data:");
Serial.print("Accelerating Stick: ");
Serial.println(myReceivedData.accelerating_stick);
Serial.print("Steering Stick: ");
Serial.println(myReceivedData.steering_stick);
lastAccel = myReceivedData.accelerating_stick;
lastSteer = myReceivedData.steering_stick;
}

// Make sure ESC is initialized
if (!escInitialized) {
return;
}

int escPulse;

// Deadzone handling - stick in neutral position
if (myReceivedData.accelerating_stick >= deadzoneLow && myReceivedData.accelerating_stick

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post