min speed fix

This commit is contained in:
DashyFox 2024-10-03 20:20:52 +03:00
parent c7876a00c5
commit 251da124f7
3 changed files with 46 additions and 38 deletions

View File

@ -643,27 +643,35 @@ void setScrewkSpeed(uint8_t speed) {
//(-v) 0 .. 100(stop) .. 200(+v)
void setRollersSpeed(uint8_t up, uint8_t down) {
uint16_t min_speed_rpm = map(infoBlock.hwInfo.motors.speed_Rollers_min, 0, 200, 400, 800);
uint16_t min_speed_pwm_positive = map(min_speed_rpm, 0, 8000, 100, 200);
uint16_t min_speed_pwm_negative = 100 - map(min_speed_rpm, 0, 8000, 0, 100);
if (up < 100) {
// up = map(up, 0, 100, 0, 100 - infoBlock.hwInfo.motors.speed_Screw_min);
// if (100 - up < min_speed) {
// up = 100 - min_speed;
// }
if (up == 100) {
up = 100;
} else if (up > 100) {
if (up < min_speed_pwm_positive) {
up = min_speed_pwm_positive;
}
} else {
// up = map(up, 0, 100, 0, 100 + infoBlock.hwInfo.motors.speed_Screw_min);
// if (up - 100 < min_speed) { // Ограничиваем положительную скорость минимальной
// up = 100 + min_speed;
// }
if (up > min_speed_pwm_negative) {
up = min_speed_pwm_negative;
}
}
if (down < 100) {
// map(down, 0, 100, 0, 100 - infoBlock.hwInfo.motors.speed_Screw_min);
if (down == 100) {
down = 100;
} else if (down > 100) {
if (down < min_speed_pwm_positive) {
down = min_speed_pwm_positive;
}
} else {
// map(down, 0, 100, 0, 100 + infoBlock.hwInfo.motors.speed_Screw_min);
if (down > min_speed_pwm_negative) {
down = min_speed_pwm_negative;
}
}
Vz1 = 200 - up; // invert
Vz1 = 200 - up; // Инвертируем значение скорости для одного из моторов
Vz2 = down;
}

View File

@ -422,10 +422,13 @@ void UART3_GetStartupDelay(uint8_t *dataPtr, uint8_t len) {
// 210 !!!!!!!!
void UART3_SetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
return;
infoBlock.hwInfo.motors.speed_Rollers_min = dataPtr[1];
saveInfoBlock();
SendResponse(dataPtr[0], 0, NULL, 0);
}
@ -435,8 +438,7 @@ void UART3_GetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
return;
uint8_t res[1];
// res[0] = ;
uint8_t res[1] = {infoBlock.hwInfo.motors.speed_Rollers_min};
SendResponse(dataPtr[0], 0, res, sizeof(res));
}

View File

@ -222,24 +222,22 @@ int main(void)
// printNumber(SysTick->LOAD);
// CDC_Transmit_FS(text, sizeof(text));
// char buffer[100]; // Буфер для формата строки
// extern uint32_t vsk1;
// extern uint32_t vsk2;
// extern uint16_t timing1;
// extern uint16_t timing2;
// sprintf(buffer,
// "timing1: %u ms, timing2: %u ms, vsk1: %u RPM, vsk2: %u RPM\n",
// timing1, timing2, vsk1, vsk2);
//
// CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
char buffer[64];
sprintf(buffer, "Current mode: %s, Current state: %s\n",
getModeString(currentInfo.mode),
getStateString(currentInfo.state));
char buffer[100];
extern uint32_t vsk1;
extern uint32_t vsk2;
extern uint16_t timing1;
extern uint16_t timing2;
sprintf(buffer,
"timing1: %u ms, timing2: %u ms, vsk1: %u RPM, vsk2: %u RPM\n",
timing1, timing2, vsk1, vsk2);
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
// char buffer[64];
// sprintf(buffer, "Current mode: %s, Current state: %s\n",
// getModeString(currentInfo.mode),
// getStateString(currentInfo.state));
// CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
}