Author SHA1 Message Date
kleiax 00c504fb12 Merge remote-tracking branch 'origin/projektarbeit' into testProjekttoBachelor but only motor things 2024-07-19 15:57:54 +02:00
kleiax f0f75d3fd3 - deactivate a debug print
- activate init screen
- update network config
2024-07-19 15:33:50 +02:00
kleiax a7930e2915 more refactor bug fixes 2023-10-13 14:17:51 +02:00
kleiax f0474027be remove CalcAzimuth 2023-10-12 20:58:30 +02:00
kleiax 12c338def1 fix merge bugs 2023-10-12 20:50:59 +02:00
kleiax e511afb2a5 Merge branch 'main' into projektarbeit 2023-10-12 20:35:31 +02:00
kleiax f78804d836 first build 2023-09-04 14:13:14 +02:00
kleiax 682a99ffea Merge branch 'main' into projektarbeit 2023-09-04 13:35:40 +02:00
kleiax d7a9e9cfd8 delete everthing for bachelore 2023-09-02 18:34:06 +02:00
kleiax fd946f2aa3 Merge branch 'main' into projektarbeit 2023-09-02 18:31:46 +02:00
kleiax 4e2b5bd347 delete old debug python files 2023-09-02 17:51:16 +02:00
4 changed files with 9 additions and 44 deletions
+1
View File
@@ -87,6 +87,7 @@ public:
* @param status
*/
void setDrivingStatus(Status status);
Status getDrivingStatus() const { return this->driving_status; }
/**
* @brief Stops the engine immediately
+5 -27
View File
@@ -33,6 +33,7 @@ void MotorControl::init(uint8_t pwmPin, uint8_t pwmChannel, uint8_t dir_1, uint8
ledcSetup(this->pwmChannel, MotorControl::pwmFreq, MotorControl::pwmRes);
ledcAttachPin(this->pwmPin, this->pwmChannel);
ledcWrite(this->pwmChannel, 0);
std::cout << "Init pwm" << std::endl;
}
void MotorControl::run()
@@ -56,7 +57,7 @@ void MotorControl::run()
return;
}
// Positive or negative tagret speed
// Positive or negative target speed
if (this->targetPower >= 0)
{
// Positive or negative speed
@@ -97,28 +98,6 @@ void MotorControl::run()
}
}
void MotorControl::setMinPwm(uint8_t min)
{
if (min > MotorControl::maxPwmMin)
{
min = MotorControl::maxPwmMin;
}
// transform percentage to real pwm value
min = static_cast<uint8_t>(((static_cast<uint8_t>(1) << pwmRes) - 1) * (min / 100.0));
this->dutycycleMin = min;
}
void MotorControl::setMaxPwm(uint8_t max)
{
if (max > 100)
{
max = 100;
}
// transform percentage to real pwm value
max = static_cast<uint8_t>(((static_cast<uint8_t>(1) << pwmRes) - 1) * (max / 100.0));
this->dutycycleMax = max;
}
void MotorControl::setTargetPower(int8_t power)
{
if (power <= 100 && power >= -100)
@@ -158,7 +137,6 @@ bool MotorControl::isAccelerationNegative() const
void MotorControl::setRealPower(int8_t power)
{
// TODO: Exceptionhandling
if (power <= 100 && power >= -100)
{
this->power = power;
@@ -175,10 +153,11 @@ void MotorControl::setRealPower(int8_t power)
digitalWrite(this->dir_2, LOW);
ledcWrite(this->pwmChannel, 0);
this->dutycycle = 0;
// std::cout << "abort" << std::endl;
return;
}
const uint8_t pwm_val = map(abs(power), 0, 100, this->dutycycleMin, this->dutycycleMax);
const uint8_t pwm_val = map(abs(power), 0, 100, MotorControl::minPwmVal, MotorControl::maxPwmVal);
if ((this->direction == 1 || this->direction == 0) && power < 0)
{ // new direction backward
@@ -193,6 +172,7 @@ void MotorControl::setRealPower(int8_t power)
digitalWrite(this->dir_2, LOW);
}
std::cout << "MotorControl::setRealPower pwm_val: " << (int) pwm_val << " channel:" << (int) this->pwmChannel << std::endl;
ledcWrite(this->pwmChannel, pwm_val);
std::cout << "MotorControl::serRealPower - pwm: " << static_cast<int>(pwm_val) << std::endl;
this->dutycycle = pwm_val;
@@ -200,8 +180,6 @@ void MotorControl::setRealPower(int8_t power)
void MotorControl::increasePower(int8_t power)
{
// TODO: Exceptionhandling
// TODO: make a stop befor a direction change
if (abs(power) > 2 * MotorControl::powerSteps)
{
Serial.println("Invalid Argument in MotorControl::increasePower");
+2 -16
View File
@@ -38,20 +38,6 @@ public:
*/
void init(uint8_t pwmPin, uint8_t pwmChannel, uint8_t dir_1, uint8_t dir_2);
/**
* @brief Set the minimum duty cycle
*
* @param min duty cycle in percent
*/
void setMinPwm(uint8_t min);
/**
* @brief Set the maximum duty cycle
*
* @param max duty cycle in percent
*/
void setMaxPwm(uint8_t max);
/**
* @brief Set the Target Power
*
@@ -103,6 +89,8 @@ private:
static constexpr uint8_t pwmRes = 8;
static constexpr uint8_t powerSteps = 2; // A total of 20 levels ( 100 / SPEED_STEPS ) * RUN_MOTOR_CONTROL_DELAY = 500ms
static constexpr uint8_t maxPwmMin = 80;
static constexpr uint8_t maxPwmVal = 250;
static constexpr uint8_t minPwmVal = 55; // Max 98% of 2^PWM_RES
int8_t targetPower = 0;
int8_t power = 0;
@@ -111,8 +99,6 @@ private:
uint8_t pwmPin = 0;
uint8_t pwmChannel = 0;
uint16_t dutycycle = 0;
uint8_t dutycycleMin = 55;
uint8_t dutycycleMax = 98; // Max 98% of 2^PWM_RES
uint8_t dir_1 = 0;
uint8_t dir_2 = 0;
};
@@ -47,7 +47,7 @@ void ManualControl::analogControl()
void ManualControl::digitalControl()
{
static constexpr uint8_t deadzone = 120;
static constexpr uint8_t deadzone = 110;
const int16_t yAxis = this->input->x - 127;
const int16_t xAxis = this->input->y - 127;