first control - no motors
This commit is contained in:
@@ -17,3 +17,7 @@ lib_deps =
|
||||
asukiaaa/XboxSeriesXControllerESP32_asukiaaa @ ^1.0.9
|
||||
adafruit/Adafruit MCP23017 Arduino Library @ ^2.3.2
|
||||
madhephaestus/ESP32Servo @ ^3.0.5
|
||||
build_flags =
|
||||
-DCORE_DEBUG_LEVEL=3
|
||||
-DNDEF_DEBUG=1
|
||||
-fexceptions
|
||||
@@ -3,13 +3,23 @@
|
||||
XboxSeriesXControllerESP32_asukiaaa::Core xboxController; //"40:8e:2c:41:e4:eb"); //("a4:c1:38:38:e3:c0");
|
||||
uint32_t lastcontrollernotify = 0;
|
||||
|
||||
int joymin = 0;
|
||||
int joymax = 0;
|
||||
|
||||
uint16_t joymax = 0;
|
||||
#define deadband 7000
|
||||
|
||||
direction getdirection(int setpoint)
|
||||
{
|
||||
if(setpoint > )
|
||||
if(setpoint > (joymax/2 +deadband))
|
||||
{
|
||||
return direction::right;
|
||||
}
|
||||
else if(setpoint < (joymax/2 -deadband))
|
||||
{
|
||||
return direction::left;
|
||||
}
|
||||
else
|
||||
{
|
||||
return direction::stop;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +27,8 @@ void setup_controller()
|
||||
{
|
||||
xboxController.begin();
|
||||
xboxController.onLoop();
|
||||
xboxController.startScan();
|
||||
|
||||
Serial.printf("Waiting for controller");
|
||||
}
|
||||
|
||||
@@ -34,23 +46,31 @@ void loop_controller()
|
||||
log_v("Address: %s", xboxController.buildDeviceAddressStr());
|
||||
// log_i("message: %s", Serial.print(xboxController.xboxNotif.toString()));
|
||||
unsigned long receivedAt = xboxController.getReceiveNotificationAt();
|
||||
uint16_t joystickMax = XboxControllerNotificationParser::maxJoy;
|
||||
joymax = XboxControllerNotificationParser::maxJoy;
|
||||
if (millis() - lastcontrollernotify > CONTROLLERNOTIFY)
|
||||
{
|
||||
log_i("joyLHori rate: %0.0f", ((float)xboxController.xboxNotif.joyLHori / joystickMax *100));
|
||||
log_i("joyLVert rate: %0.0f",((float)xboxController.xboxNotif.joyLVert / joystickMax *100));
|
||||
log_i("joyRHori rate: %0.0f", ((float)xboxController.xboxNotif.joyRHori / joystickMax *100));
|
||||
log_i("joyRVert rate: %0.0f",((float)xboxController.xboxNotif.joyRVert / joystickMax *100));
|
||||
log_i("joyLHori rate: %u", xboxController.xboxNotif.joyLHori);
|
||||
log_i("joyLVert rate: %u", xboxController.xboxNotif.joyLVert);
|
||||
log_i("joyRHori rate: %0.0f", ((float)xboxController.xboxNotif.joyRHori / joymax *100));
|
||||
log_i("joyRVert rate: %0.0f",((float)xboxController.xboxNotif.joyRVert / joymax *100));
|
||||
log_i("battery %d %", xboxController.battery);
|
||||
log_i("received at %l", receivedAt);
|
||||
log_i("joymax:%d",joymax );
|
||||
lastcontrollernotify = millis();
|
||||
}
|
||||
controlMotor("mainboom", direction::stop)
|
||||
controlMotor("Boom", getdirection(xboxController.xboxNotif.joyLHori));
|
||||
controlMotor("Pivot", getdirection(xboxController.xboxNotif.joyLVert));
|
||||
controlMotor("Bucket", getdirection(xboxController.xboxNotif.joyRHori));
|
||||
controlMotor("Dipper", getdirection(xboxController.xboxNotif.joyRVert));
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log_w("not connected");
|
||||
if (millis() - lastcontrollernotify > CONTROLLERNOTIFY)
|
||||
{
|
||||
log_w("not connected");
|
||||
lastcontrollernotify = millis();
|
||||
}
|
||||
if (xboxController.getCountFailedConnection() > 10)
|
||||
{
|
||||
log_e("restarting");
|
||||
@@ -58,11 +78,3 @@ void loop_controller()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handle_notify(int motR, int motL, int motArm, int bucket)
|
||||
{
|
||||
drivemotor(0, motR);
|
||||
drivemotor(1, motL);
|
||||
drivemotor(2, motArm);
|
||||
bucketTilt(bucket);
|
||||
}
|
||||
@@ -9,22 +9,7 @@ void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
// Ps3.attach(notify);
|
||||
// Ps3.attachOnConnect(onConnect);
|
||||
// Ps3.begin("a0:5a:5a:a0:0f:91");
|
||||
|
||||
// Serial.println("Ready.");
|
||||
|
||||
// pinMode(clawServoPin, OUTPUT);
|
||||
// pinMode(auxServoPin, OUTPUT);
|
||||
|
||||
// pinMode(cabLights, OUTPUT);
|
||||
// pinMode(auxLights, OUTPUT);
|
||||
|
||||
// clawServo.attach(clawServoPin);
|
||||
// auxServo.attach(auxServoPin);
|
||||
// clawServo.write(clawServoValue);
|
||||
// auxServo.write(auxServoValue);
|
||||
setup_motors();
|
||||
setup_controller();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,10 @@ void controlMotor(String name, direction dir)
|
||||
if(thismotor.getName() == name)
|
||||
{
|
||||
thismotor.run(dir);
|
||||
return;
|
||||
}
|
||||
}
|
||||
log_e("motor %s not found",name);
|
||||
}
|
||||
|
||||
void motor::begin()
|
||||
@@ -68,6 +70,17 @@ void motor::setIO(uint8_t in0, uint8_t in1)
|
||||
mcp.digitalWrite(m_pin1, in1);
|
||||
}
|
||||
|
||||
uint32_t lastmotorlog = 0;
|
||||
|
||||
void logactions(String dir, String name)
|
||||
{
|
||||
if (millis() - lastmotorlog > MOTORLOGTIME)
|
||||
{
|
||||
log_i("motor %s: %s", name, dir);
|
||||
lastmotorlog = millis();
|
||||
}
|
||||
}
|
||||
|
||||
void motor::run(direction dir)
|
||||
{
|
||||
if(current == dir) return;
|
||||
@@ -77,17 +90,21 @@ void motor::run(direction dir)
|
||||
case direction::left:
|
||||
{
|
||||
setIO(HIGH, LOW);
|
||||
log_i("motor %s: left", getName());
|
||||
break;
|
||||
}
|
||||
case direction::right:
|
||||
{
|
||||
setIO(LOW, HIGH);
|
||||
log_i("motor %s: Right", getName());
|
||||
|
||||
break;
|
||||
}
|
||||
case direction::stop:
|
||||
default:
|
||||
{
|
||||
setIO(LOW, LOW);
|
||||
log_i("motor %s: stop", getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
#define MOTORLOGTIME 1000
|
||||
|
||||
|
||||
//general functions
|
||||
void setup_motors();
|
||||
void controlMotor(String name, direction dir);
|
||||
|
||||
|
||||
struct motorinit
|
||||
{
|
||||
@@ -36,6 +34,9 @@ enum direction
|
||||
stop
|
||||
};
|
||||
|
||||
//general functions
|
||||
void setup_motors();
|
||||
void controlMotor(String name, direction dir);
|
||||
|
||||
class motor
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user