This commit is contained in:
2024-09-10 01:09:10 +03:00
parent 8aed06aa9c
commit c85e6aca95
6 changed files with 268 additions and 333 deletions

View File

@ -52,6 +52,10 @@ HardwareInit_t hwSettings = {
extern int16_t Vz1;
extern int16_t Vz2;
int16_t map(int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void doShot(Shot *shot) {
SetServo(0, shot->rotationHorizontal);
SetServo(1, shot->rotationVertical);
@ -99,13 +103,10 @@ void startShooting() {
void stopShooting() {
isShooting = 0;
isPause = 0;
setScrewkSpeed(0);
setRollersSpeed(100, 100);
setPosDefault();
Vz1 = 100;
Vz2 = 100;
TIM1->CCR1 = 0;
TIM1->CCR2 = 0;
}
void doShotForever(uint8_t number) {
@ -135,16 +136,18 @@ void setPos(uint8_t axial, uint8_t horizontal, uint8_t vertical) {
SetServo(SERVO_VERTICAL, vertical); // Vertical
}
void setPosDefault() {
SetServo(0, 90); // Axial
SetServo(1, 90); // Horizontal
SetServo(2, 90); // Vertical
SetServo(SERVO_AXIAL, hwSettings.servos[SERVO_AXIAL].def); // Axial
SetServo(SERVO_HORIZONTAL, hwSettings.servos[SERVO_HORIZONTAL].def); // Horizontal
SetServo(SERVO_VERTICAL, hwSettings.servos[SERVO_VERTICAL].def); // Vertical
}
// 0 .. 100
void setScrewkSpeed(uint8_t speed) {
if(speed && speed < hwSettings.motors.speed_Screw_min)
speed = hwSettings.motors.speed_Screw_min;
// if(speed < 0) speed = 0;
if(speed > 100) speed = 100;
speed = map(speed, 0, 100, hwSettings.motors.speed_Screw_min, 100);
TIM1->CCR1 = 0;
TIM1->CCR2 = (uint16_t)(40 * speed);
@ -153,6 +156,18 @@ void setScrewkSpeed(uint8_t speed) {
//(-v) 0 .. 100(stop) .. 200(+v)
void setRollersSpeed(uint8_t up, uint8_t down) {
if(up < 100){
up = map(up, 0, 100, 0, 100-hwSettings.motors.speed_Screw_min);
} else {
up = map(up, 0, 100, 0, 100+hwSettings.motors.speed_Screw_min);
}
if(down < 100){
map(down, 0, 100, 0, 100-hwSettings.motors.speed_Screw_min);
} else {
map(down, 0, 100, 0, 100+hwSettings.motors.speed_Screw_min);
}
Vz1 = 200-up; // invert
Vz2 = down;
}