mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-06-28 05:09:32 +00:00
Uart working
This commit is contained in:
@ -36,24 +36,17 @@ typedef struct Current {
|
||||
Current current;
|
||||
|
||||
HardwareInit_t hwSettings = {
|
||||
/*DelayTimes*/ {
|
||||
/*preRun*/ 0
|
||||
},
|
||||
/*ServoSetting*/{
|
||||
{0, 0, 90, 180},
|
||||
{0, 0, 90, 180},
|
||||
{0, 0, 90, 180}
|
||||
},
|
||||
/*Motors*/{
|
||||
0, 0
|
||||
}
|
||||
};
|
||||
/*DelayTimes*/{
|
||||
/*preRun*/0 },
|
||||
/*ServoSetting*/{ { 0, 0, 90, 180 }, { 0, 0, 90, 180 }, { 0, 0, 90, 180 } },
|
||||
/*Motors*/{ 0, 0 } };
|
||||
|
||||
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;
|
||||
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) {
|
||||
@ -67,36 +60,43 @@ void doShot(Shot *shot) {
|
||||
|
||||
void startShooting() {
|
||||
switch (current.mode) {
|
||||
case ShotMode:
|
||||
print("StartShooting\n");
|
||||
if(current.shot.isExist){
|
||||
print("Fire!\n");
|
||||
case ShotMode:
|
||||
print("StartShooting\n");
|
||||
if (current.shot.isExist) {
|
||||
print("Fire!\n");
|
||||
|
||||
print("isExist ");printNumber(current.shot.isExist);
|
||||
print("countRepeatShot; ");printNumber(current.shot.countRepeatShot);
|
||||
print("speedRollerTop; ");printNumber(current.shot.speedRollerTop);
|
||||
print("speedRollerBottom; ");printNumber(current.shot.speedRollerBottom);
|
||||
print("speedScrew; ");printNumber(current.shot.speedScrew);
|
||||
print("rotationAxial; ");printNumber(current.shot.rotationAxial);
|
||||
print("rotationHorizontal; ");printNumber(current.shot.rotationHorizontal);
|
||||
print("rotationVertical; ");printNumber(current.shot.rotationVertical);
|
||||
print("isExist ");
|
||||
printNumber(current.shot.isExist);
|
||||
print("countRepeatShot; ");
|
||||
printNumber(current.shot.countRepeatShot);
|
||||
print("speedRollerTop; ");
|
||||
printNumber(current.shot.speedRollerTop);
|
||||
print("speedRollerBottom; ");
|
||||
printNumber(current.shot.speedRollerBottom);
|
||||
print("speedScrew; ");
|
||||
printNumber(current.shot.speedScrew);
|
||||
print("rotationAxial; ");
|
||||
printNumber(current.shot.rotationAxial);
|
||||
print("rotationHorizontal; ");
|
||||
printNumber(current.shot.rotationHorizontal);
|
||||
print("rotationVertical; ");
|
||||
printNumber(current.shot.rotationVertical);
|
||||
|
||||
isShooting = 1;
|
||||
doShot(¤t.shot);
|
||||
} else {
|
||||
print("Current Shot is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
}
|
||||
break;
|
||||
case ProgramMode:
|
||||
|
||||
isShooting = 1;
|
||||
doShot(¤t.shot);
|
||||
} else {
|
||||
print("Current Shot is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
}
|
||||
break;
|
||||
case ProgramMode:
|
||||
break;
|
||||
case MacroMode:
|
||||
|
||||
break;
|
||||
case MacroMode:
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,49 +126,53 @@ uint8_t prepareShot(uint8_t number) {
|
||||
}
|
||||
}
|
||||
|
||||
void setPosSingle(ServoMap servo, uint8_t value) {
|
||||
if (hwSettings.servos[servo].invert)
|
||||
value = 180 - value;
|
||||
SetServo(servo, value);
|
||||
}
|
||||
void setPos(uint8_t axial, uint8_t horizontal, uint8_t vertical) {
|
||||
|
||||
//todo:
|
||||
// hwSettings.servos[SERVO_AXIAL].invert
|
||||
|
||||
SetServo(SERVO_AXIAL, axial); // Axial
|
||||
SetServo(SERVO_HORIZONTAL, horizontal); // Horizontal
|
||||
SetServo(SERVO_VERTICAL, vertical); // Vertical
|
||||
setPosSingle(SERVO_AXIAL, axial);
|
||||
setPosSingle(SERVO_HORIZONTAL, horizontal);
|
||||
setPosSingle(SERVO_VERTICAL, vertical);
|
||||
}
|
||||
void setPosDefault() {
|
||||
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
|
||||
setPos(
|
||||
hwSettings.servos[SERVO_AXIAL].def,
|
||||
hwSettings.servos[SERVO_HORIZONTAL].def,
|
||||
hwSettings.servos[SERVO_VERTICAL].def
|
||||
);
|
||||
}
|
||||
|
||||
// 0 .. 100
|
||||
void setScrewkSpeed(uint8_t speed) {
|
||||
|
||||
// if(speed < 0) speed = 0;
|
||||
if(speed > 100) speed = 100;
|
||||
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);
|
||||
TIM1->CCR2 = (uint16_t) (40 * 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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
map(down, 0, 100, 0, 100 + hwSettings.motors.speed_Screw_min);
|
||||
}
|
||||
|
||||
Vz1 = 200-up; // invert
|
||||
Vz1 = 200 - up; // invert
|
||||
Vz2 = down;
|
||||
}
|
||||
// shot sequence
|
||||
|
Reference in New Issue
Block a user