all but thumb
This commit is contained in:
@@ -4,9 +4,11 @@ XboxSeriesXControllerESP32_asukiaaa::Core xboxController; //"40:8e:2c:41:e4:eb")
|
|||||||
uint32_t lastcontrollernotify = 0;
|
uint32_t lastcontrollernotify = 0;
|
||||||
|
|
||||||
uint16_t joymax = 0;
|
uint16_t joymax = 0;
|
||||||
|
uint16_t trgmax = 0;
|
||||||
#define deadband 10000
|
#define deadband 10000
|
||||||
|
#define trgdeadband 200
|
||||||
|
|
||||||
direction getdirection(int setpoint)
|
direction getdirectionJoy(int setpoint)
|
||||||
{
|
{
|
||||||
if(setpoint > (joymax/2 +deadband))
|
if(setpoint > (joymax/2 +deadband))
|
||||||
{
|
{
|
||||||
@@ -16,11 +18,35 @@ direction getdirection(int setpoint)
|
|||||||
{
|
{
|
||||||
return direction::left;
|
return direction::left;
|
||||||
}
|
}
|
||||||
else
|
//else
|
||||||
{
|
|
||||||
return direction::stop;
|
return direction::stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
direction getdirecion2Button(uint8_t button0, uint8_t button1)
|
||||||
|
{
|
||||||
|
if(button0 & !button1)
|
||||||
|
{
|
||||||
|
return direction::left;
|
||||||
|
}
|
||||||
|
if(!button0 & button1)
|
||||||
|
{
|
||||||
|
return direction::right;
|
||||||
|
}
|
||||||
|
//else
|
||||||
|
return direction::stop;
|
||||||
|
}
|
||||||
|
|
||||||
|
direction getTrackDirection(int trigger, uint8_t shoulder)
|
||||||
|
{
|
||||||
|
if(trigger > (trgmax/2 + trgdeadband) & !shoulder)
|
||||||
|
{
|
||||||
|
return direction::right;
|
||||||
|
}
|
||||||
|
if((trigger == 0) & shoulder)
|
||||||
|
{
|
||||||
|
return direction::left;
|
||||||
|
}
|
||||||
|
return direction::stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_controller()
|
void setup_controller()
|
||||||
@@ -47,23 +73,27 @@ void loop_controller()
|
|||||||
// log_i("message: %s", Serial.print(xboxController.xboxNotif.toString()));
|
// log_i("message: %s", Serial.print(xboxController.xboxNotif.toString()));
|
||||||
unsigned long receivedAt = xboxController.getReceiveNotificationAt();
|
unsigned long receivedAt = xboxController.getReceiveNotificationAt();
|
||||||
joymax = XboxControllerNotificationParser::maxJoy;
|
joymax = XboxControllerNotificationParser::maxJoy;
|
||||||
|
trgmax = XboxControllerNotificationParser::maxTrig;
|
||||||
if (millis() - lastcontrollernotify > CONTROLLERNOTIFY)
|
if (millis() - lastcontrollernotify > CONTROLLERNOTIFY)
|
||||||
{
|
{
|
||||||
log_i("joyLHori rate: %u", xboxController.xboxNotif.joyLHori);
|
// log_i("joyLHori rate: %u", xboxController.xboxNotif.btnLS);
|
||||||
log_i("joyLVert rate: %u", xboxController.xboxNotif.joyLVert);
|
// log_i("joyLVert rate: %u", xboxController.xboxNotif.btnLB);
|
||||||
log_i("joyRHori rate: %u", xboxController.xboxNotif.joyRHori);
|
// log_i("joyRHori rate: %u", xboxController.xboxNotif.trigLT);
|
||||||
log_i("joyRVert rate: %u", xboxController.xboxNotif.joyRVert);
|
// log_i("joyRVert rate: %u", xboxController.xboxNotif.trigRT);
|
||||||
log_i("battery %d %", xboxController.battery);
|
log_i("battery %d %", xboxController.battery);
|
||||||
log_i("joymax:%d",joymax );
|
//log_v("joymax:%d",joymax );
|
||||||
lastcontrollernotify = millis();
|
lastcontrollernotify = millis();
|
||||||
}
|
}
|
||||||
controlMotor("Pivot", getdirection(xboxController.xboxNotif.joyLHori));
|
controlMotor("Pivot", getdirectionJoy(xboxController.xboxNotif.joyLHori));
|
||||||
controlMotor("Dipper", getdirection(xboxController.xboxNotif.joyLVert));
|
controlMotor("Dipper", getdirectionJoy(xboxController.xboxNotif.joyLVert));
|
||||||
|
controlMotor("Bucket", getdirectionJoy(xboxController.xboxNotif.joyRHori));
|
||||||
|
controlMotor("Boom", getdirectionJoy(xboxController.xboxNotif.joyRVert));
|
||||||
|
controlMotor("Push", getdirecion2Button(xboxController.xboxNotif.btnX, xboxController.xboxNotif.btnY));
|
||||||
|
controlMotor("Thumb", getdirecion2Button(xboxController.xboxNotif.btnA, xboxController.xboxNotif.btnB));
|
||||||
|
|
||||||
controlMotor("Bucket", getdirection(xboxController.xboxNotif.joyRHori));
|
controlMotor("TrackLeft", getTrackDirection(xboxController.xboxNotif.trigLT, xboxController.xboxNotif.btnLB));
|
||||||
controlMotor("Boom", getdirection(xboxController.xboxNotif.joyRVert));
|
controlMotor("TrackRight", getTrackDirection(xboxController.xboxNotif.trigRT, xboxController.xboxNotif.btnRB));
|
||||||
|
|
||||||
//controlMotor("TrackLeft", getdirection(xboxController.xboxNotif.trigLT)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "motors.h"
|
#include "motors.h"
|
||||||
#include <XboxSeriesXControllerESP32_asukiaaa.hpp>
|
#include <XboxSeriesXControllerESP32_asukiaaa.hpp>
|
||||||
|
|
||||||
#define CONTROLLERNOTIFY 1000
|
#define CONTROLLERNOTIFY 30000
|
||||||
|
|
||||||
|
|
||||||
void setup_controller();
|
void setup_controller();
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ Servo auxServo;
|
|||||||
|
|
||||||
motorinit initlist[NUMMOTORS]
|
motorinit initlist[NUMMOTORS]
|
||||||
{
|
{
|
||||||
{pivot0, pivot1, 0, "Pivot"},
|
{pivot0, pivot1, 0, "Pivot", true},
|
||||||
{mainBoom0, mainBoom1, 1, "Boom"},
|
{mainBoom0, mainBoom1, 1, "Boom", false},
|
||||||
{secondBoom0, secondBoom1, 2, "Dipper"},
|
{secondBoom0, secondBoom1, 2, "Dipper", true},
|
||||||
{tiltAttach0, tiltAttach1, 3, "Bucket"},
|
{tiltAttach0, tiltAttach1, 3, "Bucket", true},
|
||||||
{thumb0, thumb1, 4, "Thumb"},
|
{thumb0, thumb1, 4, "Thumb", false},
|
||||||
{auxAttach0, auxAttach1, 5, "Aux"},
|
{auxAttach0, auxAttach1, 5, "Push", false},
|
||||||
{leftMotor0, leftMotor1, 6, "TrackLeft"},
|
{leftMotor0, leftMotor1, 6, "TrackLeft", true},
|
||||||
{rightMotor0, rightMotor1, 7, "TrackRight"}
|
{rightMotor0, rightMotor1, 7, "TrackRight", true}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<motor> motors;
|
std::vector<motor> motors;
|
||||||
@@ -67,8 +67,17 @@ void motor::begin()
|
|||||||
|
|
||||||
void motor::setIO(uint8_t in0, uint8_t in1)
|
void motor::setIO(uint8_t in0, uint8_t in1)
|
||||||
{
|
{
|
||||||
|
if(!m_invert)
|
||||||
|
{
|
||||||
mcp.digitalWrite(m_pin0, in0);
|
mcp.digitalWrite(m_pin0, in0);
|
||||||
mcp.digitalWrite(m_pin1, in1);
|
mcp.digitalWrite(m_pin1, in1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mcp.digitalWrite(m_pin0, in1);
|
||||||
|
mcp.digitalWrite(m_pin1, in0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t lastmotorlog = 0;
|
uint32_t lastmotorlog = 0;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ struct motorinit
|
|||||||
uint8_t in1;
|
uint8_t in1;
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
String name;
|
String name;
|
||||||
|
bool invert;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum direction
|
enum direction
|
||||||
@@ -47,13 +48,15 @@ class motor
|
|||||||
String m_name;
|
String m_name;
|
||||||
uint32_t m_lastlog;
|
uint32_t m_lastlog;
|
||||||
direction current;
|
direction current;
|
||||||
|
bool m_invert;
|
||||||
void setIO(uint8_t in0, uint8_t in1);
|
void setIO(uint8_t in0, uint8_t in1);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
motor(motorinit initstruct): m_pin0(initstruct.in0),
|
motor(motorinit initstruct): m_pin0(initstruct.in0),
|
||||||
m_pin1(initstruct.in1),
|
m_pin1(initstruct.in1),
|
||||||
m_id(initstruct.id),
|
m_id(initstruct.id),
|
||||||
m_name(initstruct.name) {};
|
m_name(initstruct.name),
|
||||||
|
m_invert(initstruct.invert) {};
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void run(direction dir);
|
void run(direction dir);
|
||||||
|
|||||||
Reference in New Issue
Block a user