esp23 motor class
This commit is contained in:
@@ -22,5 +22,5 @@ lib_deps =
|
|||||||
build_flags =
|
build_flags =
|
||||||
-DCORE_DEBUG_LEVEL=3
|
-DCORE_DEBUG_LEVEL=3
|
||||||
-DNDEF_DEBUG=1
|
-DNDEF_DEBUG=1
|
||||||
upload_protocol = espota
|
upload_protocol = espota ;esptool
|
||||||
upload_port = MiniSkidi.local
|
upload_port = MiniSkidi.local
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ bool removeArmMomentum = false;
|
|||||||
Servo bucketServo;
|
Servo bucketServo;
|
||||||
Servo auxServo;
|
Servo auxServo;
|
||||||
|
|
||||||
|
|
||||||
void motor::drive(int dirspeed)
|
void motor::drive(int dirspeed)
|
||||||
{
|
{
|
||||||
if (dirspeed == 0)
|
if (dirspeed == 0)
|
||||||
@@ -16,19 +15,17 @@ void motor::drive(int dirspeed)
|
|||||||
{
|
{
|
||||||
// map(value, fromLow, fromHigh, toLow, toHigh)
|
// map(value, fromLow, fromHigh, toLow, toHigh)
|
||||||
uint8_t speed = map(dirspeed, -255, 0, 0, 100);
|
uint8_t speed = map(dirspeed, -255, 0, 0, 100);
|
||||||
log_i("motor forward");
|
log_i("motor(%u) forward", m_index);
|
||||||
motorForward(motorindex, speed);
|
motorForward(motorindex, speed);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t speed = map(dirspeed, 0, 255, 0, 100);
|
uint8_t speed = map(dirspeed, 0, 255, 0, 100);
|
||||||
log_i("motor reverse");
|
log_i("motor(%u) reverse", m_index);
|
||||||
motorReverse(motorindex, speed);
|
motorReverse(motorindex, speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<MOTOR_PINS> motorPins =
|
std::vector<MOTOR_PINS> motorPins =
|
||||||
{
|
{
|
||||||
{RMOTOR_IN1, RMOTOR_IN2}, // RIGHT_MOTOR Pins (IN1, IN2)
|
{RMOTOR_IN1, RMOTOR_IN2}, // RIGHT_MOTOR Pins (IN1, IN2)
|
||||||
@@ -36,15 +33,18 @@ std::vector<MOTOR_PINS> motorPins =
|
|||||||
// {ARM_IN1, ARM_IN2}, //ARM_MOTOR pins
|
// {ARM_IN1, ARM_IN2}, //ARM_MOTOR pins
|
||||||
};
|
};
|
||||||
|
|
||||||
motor motors[2];
|
#define NUMMOTORS 2
|
||||||
|
motor motors[NUMMOTORS];
|
||||||
|
|
||||||
void setupmotors()
|
void setupmotors()
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i = 0; i < motorPins.size(); i++)
|
for (int i = 0; i < NUMMOTORS; i++)
|
||||||
{
|
{
|
||||||
|
log_i("motor(%u) initialized", motors[i].m_index);
|
||||||
motors[i].attachMotor(motorPins[i].pinIN1, motorPins[i].pinIN2); // pinMode(motorPins[i].pinIN1, OUTPUT);
|
motors[i].attachMotor(motorPins[i].pinIN1, motorPins[i].pinIN2); // pinMode(motorPins[i].pinIN1, OUTPUT);
|
||||||
motors[i].motorStop(0);
|
motors[i].motorStop(0);
|
||||||
|
motors[i].setindex(i);
|
||||||
}
|
}
|
||||||
bucketServo.attach(bucketServoPin);
|
bucketServo.attach(bucketServoPin);
|
||||||
auxServo.attach(auxServoPin);
|
auxServo.attach(auxServoPin);
|
||||||
@@ -56,12 +56,11 @@ void drivemotor(uint8_t num, int dirspeed)
|
|||||||
{
|
{
|
||||||
if (num < motorPins.size())
|
if (num < motorPins.size())
|
||||||
{
|
{
|
||||||
|
log_i("drive motor %u, speed %d", num, dirspeed);
|
||||||
motors[num].drive(dirspeed);
|
motors[num].drive(dirspeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void bucketTilt(int bucketServoValue)
|
void bucketTilt(int bucketServoValue)
|
||||||
{
|
{
|
||||||
bucketServo.write(bucketServoValue);
|
bucketServo.write(bucketServoValue);
|
||||||
@@ -70,4 +69,3 @@ void auxControl(int auxServoValue)
|
|||||||
{
|
{
|
||||||
auxServo.write(auxServoValue);
|
auxServo.write(auxServoValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
//defaults
|
//defaults
|
||||||
|
|
||||||
#define default_auxControl 150
|
#define default_auxControl 150
|
||||||
#define default_bucketTilt 100
|
#define default_bucketTilt 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,12 @@ void auxControl(int auxServoValue);
|
|||||||
class motor: public ESP32MotorControl
|
class motor: public ESP32MotorControl
|
||||||
{
|
{
|
||||||
const uint8_t motorindex = 0;
|
const uint8_t motorindex = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
uint8_t m_index;
|
||||||
|
|
||||||
void drive(int dirspeed);
|
void drive(int dirspeed);
|
||||||
|
void setindex(uint8_t index)
|
||||||
|
{
|
||||||
|
m_index = index;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -18,8 +18,6 @@ void handle_message(WebsocketsMessage msg) {
|
|||||||
|
|
||||||
void setup_webserver()
|
void setup_webserver()
|
||||||
{
|
{
|
||||||
Serial.begin(9600);
|
|
||||||
|
|
||||||
// HTTP handler assignment
|
// HTTP handler assignment
|
||||||
webserver.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
|
webserver.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", web_smars_html_gz, web_smars_html_gz_len);
|
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", web_smars_html_gz, web_smars_html_gz_len);
|
||||||
|
|||||||
Reference in New Issue
Block a user