1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-05-18 04:56:00 +02:00
cdf2018-principal/chef/src/movement.c

84 lines
1.4 KiB
C
Raw Normal View History

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
2018-04-04 16:17:13 +02:00
#include <math.h>
2018-05-01 08:45:02 +02:00
#include "movement.h"
#include "CF.h"
2018-04-04 16:17:13 +02:00
void configureMovement()
{
2018-05-01 08:45:02 +02:00
stop();
}
2018-04-04 16:17:13 +02:00
void aller(struct position* pos);
int dbg = 0;
2018-05-01 08:45:02 +02:00
uint8_t tensionToPWM(float V)
2018-02-16 22:13:24 +01:00
{
2018-05-01 08:45:02 +02:00
if (V >= PWM_MAX_V) {
return PWM_MAX;
} else if (V <= 0) {
return 0;
} else {
return V * (float) PWM_MAX / (float) PWM_MAX_V;
}
}
// Tension de PWM
// TODO Changer en tension de moteur
int setMoteurTension(float lVolt, float rVolt)
{
static struct C2FD_PWMs msg;
msg.in = 0x00;
2018-05-02 05:51:14 +02:00
// TODO Protections
2018-04-04 16:17:13 +02:00
// Gauche
2018-05-01 08:45:02 +02:00
bool lFor = lVolt < 0;
lVolt = fabs(lVolt);
msg.in |= 1 << (lFor ? IN1 : IN2);
msg.ena = tensionToPWM(lVolt);
2018-04-04 16:17:13 +02:00
// Droite
2018-05-01 08:45:02 +02:00
bool rFor = rVolt < 0;
rVolt = fabs(rVolt);
msg.in |= 1 << (rFor ? IN3 : IN4);
msg.enb = tensionToPWM(rVolt);
sendCF(C2FD_PWM, &msg, sizeof(struct C2FD_PWMs));
2018-02-16 22:13:24 +01:00
}
2018-05-01 08:45:02 +02:00
int changerMoteurs(float lVit, float rVit)
{
// TODO Conversion en vitesse
setMoteurTension(lVit, rVit);
}
static struct C2FD_PWMs msgBrake = {0, 0, 0x00};
static struct C2FD_PWMs msgFree = {0, 0, (1 << IN1) | (1 << IN2) | (1 << IN3) | (1 << IN4)};
2018-04-04 16:17:13 +02:00
int brake()
2018-02-16 22:13:24 +01:00
{
2018-05-01 08:45:02 +02:00
sendCF(C2FD_PWM, &msgBrake, sizeof(struct C2FD_PWMs));
2018-02-16 22:13:24 +01:00
}
2018-04-04 16:17:13 +02:00
int freewheel()
{
2018-05-01 08:45:02 +02:00
sendCF(C2FD_PWM, &msgFree, sizeof(struct C2FD_PWMs));
}
2018-04-30 16:15:47 +02:00
int stop()
{
brake();
2018-05-01 08:45:02 +02:00
// TODO Actionneurs
2018-04-30 16:15:47 +02:00
}
2018-05-01 09:03:33 +02:00
void deconfigureMovement()
{
stop();
}