I'm working on a project where I wanted to make an RC car using a Rocket League car body but I can't seem to get the steering and driving to work. I'm using "Remote XY" to control the car and I have gotten it to link up and I can control both the steering and the driving with the app. The problem I have is that if any point in the session I turn the motor on to drive the car forward the servo jerks to the right and then no longer responds to any input. Once I restart the car the servo works properly again, until I turn the motors on for the car to drive. I am using a DRV8833 to for motor control, and 2 18650 cells for power. The code for the car is attached below.
/*
-- New project --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 3.1.13 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.15.01 or later version;
- for iOS 1.12.1 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// you can enable debug logging to Serial at 115200
//#define REMOTEXY__DEBUGLOG
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP32CORE_BLE
#include <BLEDevice.h>
// RemoteXY connection settings
#define REMOTEXY_BLUETOOTH_NAME "Fennec"
#include <RemoteXY.h>
// RemoteXY GUI configuration
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 90 bytes
{ 255,2,0,0,0,83,0,19,0,0,0,70,101,110,110,101,99,0,24,2,
106,200,200,84,1,1,4,0,4,35,155,36,12,142,7,5,68,48,2,26,
4,36,159,36,12,25,44,68,5,176,2,26,129,248,47,71,29,34,20,48,
12,64,17,68,105,114,101,99,116,105,111,110,0,129,249,52,71,29,150,10,
34,12,64,17,83,112,101,101,100,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
int8_t speed; // from -100 to 100
int8_t steer; // from -100 to 100
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#include <ESP32Servo.h>
#define steering 15
#define forward 18
#define backward 19
#define sleep 21
Servo servo;
int steerRange = 20;
int center = 92;
void setup()
{
RemoteXY_Init ();
// TODO you setup code
pinMode(sleep, OUTPUT);
pinMode(forward, OUTPUT);
pinMode(backward, OUTPUT);
servo.attach(steering);
servo.write(center);// move servo to center position -> 90°
Serial.begin(115200);
Serial.println("running");
}
void loop() {
RemoteXY_Handler ();
float speed = RemoteXY.speed;
float steer = RemoteXY.steer;
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay(), use instead RemoteXY_delay()
if(speed != 0){
if(speed > 0){
digitalWrite(sleep, HIGH);
//Serial.println("Motor On");
digitalWrite(backward, LOW);
Serial.print("Forward: ");
Serial.println((speed/100) * 65535);
analogWrite(forward, (speed/100) * 65535);
//Serial.println("Move Forward");
}
if(speed < 0){
digitalWrite(sleep, HIGH);
//Serial.println("Motor On");
digitalWrite(forward, LOW);
Serial.print("Backward: ");
Serial.println((speed/100) * -65535);
analogWrite(backward, (speed/100) * -65535);
//Serial.println("Move Backward");
}
}else{
digitalWrite(sleep, LOW);
digitalWrite(backward, LOW);
digitalWrite(forward, LOW);
//Serial.println("Motor Off");
}
if(steer != 0){
int steerChange = steer * steerRange * .01;
// Serial.println(steer);
// Serial.println(steer * steerRange);
// Serial.println(steerChange);
Serial.println(center + steerChange);
if(steer < 0){
servo.write(center + steerChange);
//Serial.println("Right");
}
if(steer > 0){
servo.write(center + steerChange);
//Serial.println("Left");
}
}else{
servo.write(center);//Recenter
//Serial.println("Center");
}
}

