Add functions for different servo states

This commit is contained in:
Rihards Skuja 2018-01-22 21:24:15 +02:00
parent dc5b0e9995
commit 6dac67f5a9
No known key found for this signature in database
GPG Key ID: 53FA13A3F7F8571B
2 changed files with 39 additions and 2 deletions

View File

@ -26,6 +26,13 @@
#define US2TIMER0(us) (uint16_t)((51U * us) / (200U * PWM_PERIOD_MS)) #define US2TIMER0(us) (uint16_t)((51U * us) / (200U * PWM_PERIOD_MS))
void init_servos(void); void init_servos(void);
void run_servos(void);
void servo_full_forw(void);
void servo_turn_forw_r(void);
void servo_turn_forw_l(void);
void servo_full_backw(void);
void servo_turn_backw_r(void);
void servo_turn_backw_l(void);
#endif /* SERVOS_H */ #endif /* SERVOS_H */

View File

@ -23,8 +23,38 @@ void init_servos(void)
SET(SERVO_DDR, SERVO_R_BIT); SET(SERVO_DDR, SERVO_R_BIT);
} }
void run_servos(void) void servo_full_forw(void)
{ {
SERVO_L_REG = US2TIMER0(SERVO_L_FORW); SERVO_L_REG = US2TIMER0(SERVO_L_FORW);
SERVO_R_REG = US2TIMER0(SERVO_R_FORW); SERVO_R_REG = US2TIMER0(SERVO_R_FORW);
} }
void servo_turn_forw_r(void)
{
SERVO_L_REG = US2TIMER0(SERVO_L_FORW);
SERVO_R_REG = US2TIMER0(SERVO_R_STOP);
}
void servo_turn_forw_l(void)
{
SERVO_L_REG = US2TIMER0(SERVO_L_STOP);
SERVO_R_REG = US2TIMER0(SERVO_R_FORW);
}
void servo_full_backw(void)
{
SERVO_L_REG = US2TIMER0(SERVO_L_BACKW);
SERVO_R_REG = US2TIMER0(SERVO_R_BACKW);
}
void servo_turn_backw_r(void)
{
SERVO_L_REG = US2TIMER0(SERVO_L_STOP);
SERVO_R_REG = US2TIMER0(SERVO_R_BACKW);
}
void servo_turn_backw_l(void)
{
SERVO_L_REG = US2TIMER0(SERVO_L_BACKW);
SERVO_R_REG = US2TIMER0(SERVO_R_STOP);
}