1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-14 20:36:03 +01:00
cdf2018-principal/chef/src/movement.c

95 lines
1.8 KiB
C
Raw Normal View History

#include "movement.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
2018-04-04 16:17:13 +02:00
#include <math.h>
2018-04-04 16:17:13 +02:00
void configureMovement()
{
2018-04-04 16:17:13 +02:00
pinMode(ENA, PWM_OUTPUT);
pinMode(ENB, PWM_OUTPUT);
}
2018-04-04 16:17:13 +02:00
void aller(struct position* pos);
int dbg = 0;
2018-04-04 16:17:13 +02:00
int changerMoteurs(float lVit, float rVit)
2018-02-16 22:13:24 +01:00
{
2018-04-04 16:17:13 +02:00
// Gauche
bool lFor = lVit < 0;
float lVolt = fabs(lVit); // TODO Utiliser les vitesses
if (lVolt > MOT_MAX_V) {
lVolt = MOT_MAX_V;
}
if (lVolt < MOT_MIN_V) {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
printf("x");
} else if (lFor) {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
printf("");
} else {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
printf("");
}
int lAbs = lVolt * PWM_MAX / PWM_MAX_V;
pwmWrite(ENA, lAbs);
printf("%6d", lAbs);
// Droite
bool rFor = rVit < 0;
float rVolt = fabs(rVit); // TODO Utiriser res vitesses
if (rVolt > MOT_MAX_V) {
rVolt = MOT_MAX_V;
}
if (rVolt < MOT_MIN_V) {
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
printf("x");
} else if (rFor) {
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
printf("");
} else {
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
printf("");
}
int rAbs = rVolt * PWM_MAX / PWM_MAX_V;
pwmWrite(ENB, rAbs);
printf("%6d", rAbs);
printf("\n");
2018-02-16 22:13:24 +01:00
}
2018-04-04 16:17:13 +02:00
int brake()
2018-02-16 22:13:24 +01:00
{
2018-04-04 16:17:13 +02:00
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
2018-02-16 22:13:24 +01:00
}
2018-04-04 16:17:13 +02:00
int freewheel()
{
2018-04-04 16:17:13 +02:00
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
}
2018-04-04 16:17:13 +02:00
void deconfigureMovement()
{
}
2018-04-30 16:15:47 +02:00
int stop()
{
brake();
// TODO
}