Compare commits
7 commits
ae29b5de4a
...
db573aee04
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db573aee04 | ||
|
|
d2a19989fd | ||
|
|
a4c1eaa559 | ||
|
|
779b5cfaf1 | ||
|
|
625998d321 | ||
|
|
cacd44d03d | ||
|
|
dc1aa96d9a |
13 changed files with 144 additions and 63 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
#include "Alimentation.h"
|
#include "Alimentation.h"
|
||||||
|
|
||||||
|
#include "stm32f1xx_ll_adc.h"
|
||||||
|
#include "stm32f1xx_ll_bus.h"
|
||||||
|
#include "stm32f1xx_ll_rcc.h"
|
||||||
|
#include "stm32f1xx_ll_gpio.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
void ALIMENTATION_Init(void){
|
void ALIMENTATION_Init(void){
|
||||||
RCC -> CFGR |= (0x1<<15);
|
RCC -> CFGR |= (0x1<<15);
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,30 @@
|
||||||
// RIEN A MODIFIER //
|
/**
|
||||||
|
******************************************************************************
|
||||||
//codé par Léonie GALLOIS et Morgane FOUSSATS
|
* @file RFOutput.h
|
||||||
|
* @author GALLOIS, Leonie and GÜLDENSTEIN, Jasper and FOUSSATS, Morgane
|
||||||
|
* @brief Service for using the RF Module to transmit characters.
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
#ifndef ALIMENTATION_H
|
#ifndef ALIMENTATION_H
|
||||||
#define ALIMENTATION_H
|
#define ALIMENTATION_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes for reading of the power supply/battery level
|
||||||
#include "stm32f103xb.h"
|
* Peripherals used: ADC1
|
||||||
#include "stm32f1xx_ll_adc.h"
|
* Pins used: PC2 (Analog input)
|
||||||
#include "stm32f1xx_ll_bus.h"
|
*/
|
||||||
#include "stm32f1xx_ll_rcc.h"
|
|
||||||
#include "stm32f1xx_ll_gpio.h"
|
|
||||||
#include "math.h"
|
|
||||||
|
|
||||||
/* =====================================================================================
|
|
||||||
Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1)
|
|
||||||
=======================================================================================*/
|
|
||||||
|
|
||||||
void ALIMENTATION_Init(void);
|
void ALIMENTATION_Init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads the power supply/battery level
|
||||||
|
* @retval battery level in Volts
|
||||||
|
*/
|
||||||
float ALIMENTATION_GetBatteryLevel(void);
|
float ALIMENTATION_GetBatteryLevel(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns if the power supply/battery level is above acceptable level
|
||||||
|
* @retval state (0 or 1)
|
||||||
|
*/
|
||||||
int ALIMENTATION_IsLevelEnough(void);
|
int ALIMENTATION_IsLevelEnough(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
//codé par Kévin Cavailles et Jasper Güldenstein
|
#ifndef DC_MOTOR_H
|
||||||
|
#define DC_MOTOR_H
|
||||||
|
|
||||||
void DC_MOTOR_Init(void);
|
void DC_MOTOR_Init(void);
|
||||||
|
|
||||||
// set a speed between -100 (full throttle clockwise) 0 (stop) and 100 (full throttle counterclockwise)
|
// set a speed between -100 (full throttle clockwise) 0 (stop) and 100 (full throttle counterclockwise)
|
||||||
void DC_MOTOR_SetSpeed(int speed);
|
void DC_MOTOR_SetSpeed(int speed);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,11 @@
|
||||||
#include "stm32f1xx_ll_exti.h"
|
#include "stm32f1xx_ll_exti.h"
|
||||||
#include "stm32f1xx_ll_tim.h"
|
#include "stm32f1xx_ll_tim.h"
|
||||||
|
|
||||||
#define RESOLUTION 1
|
#define ZERO_POSITION 0
|
||||||
#define ANGLE_DEBUT 45
|
#define TICKS_PER_REVOLUTION 360*4
|
||||||
#define INCR_ENCODER_MID_VALUE 719
|
#define DEGREE_PER_TICKS 0.25
|
||||||
|
|
||||||
|
|
||||||
int index_passed = 0;
|
int index_passed = 0;
|
||||||
int counts_per_revolution = 360;
|
|
||||||
|
|
||||||
void INCR_ENCODER_Init(void){
|
void INCR_ENCODER_Init(void){
|
||||||
|
|
||||||
|
|
@ -33,7 +31,7 @@ void INCR_ENCODER_Init(void){
|
||||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
||||||
LL_TIM_InitTypeDef tim3_init_struct;
|
LL_TIM_InitTypeDef tim3_init_struct;
|
||||||
|
|
||||||
tim3_init_struct.Autoreload= counts_per_revolution*4-1;
|
tim3_init_struct.Autoreload= TICKS_PER_REVOLUTION-1;
|
||||||
tim3_init_struct.Prescaler=0;
|
tim3_init_struct.Prescaler=0;
|
||||||
tim3_init_struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
|
tim3_init_struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
|
||||||
tim3_init_struct.CounterMode=LL_TIM_COUNTERMODE_UP;
|
tim3_init_struct.CounterMode=LL_TIM_COUNTERMODE_UP;
|
||||||
|
|
@ -101,17 +99,12 @@ int INCR_ENCODER_IsAbsolute(void)
|
||||||
return index_passed;
|
return index_passed;
|
||||||
};
|
};
|
||||||
|
|
||||||
int INCR_ENCODER_GetAngle(void)
|
float INCR_ENCODER_GetAngle(void)
|
||||||
{
|
{
|
||||||
int counter_value = LL_TIM_ReadReg(TIM3, CNT);
|
int counter_value = LL_TIM_ReadReg(TIM3, CNT);
|
||||||
float vabs = abs(counter_value-INCR_ENCODER_MID_VALUE);
|
// center
|
||||||
float vIEAngleDebut = INCR_ENCODER_MID_VALUE -(ANGLE_DEBUT*4);
|
int centered_counter_value = (counter_value - ZERO_POSITION) % TICKS_PER_REVOLUTION;
|
||||||
float nbIncrements = 90/RESOLUTION;
|
// translate ticks to angle
|
||||||
|
float angle = centered_counter_value * DEGREE_PER_TICKS;
|
||||||
if(vabs > vIEAngleDebut)
|
return angle;
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}else{
|
|
||||||
return 90 - RESOLUTION*floor(vabs/(vIEAngleDebut/nbIncrements) ) ;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
#ifndef INCR_ENCODER
|
#ifndef INCR_ENCODER_H
|
||||||
|
#define INCR_ENCODER_H
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
void INCR_ENCODER_Init(void);
|
void INCR_ENCODER_Init(void);
|
||||||
|
|
||||||
int INCR_ENCODER_IsAbsolute(void);
|
int INCR_ENCODER_IsAbsolute(void);
|
||||||
|
|
||||||
int INCR_ENCODER_GetAngle(void);
|
/**
|
||||||
|
* @brief Returns the angle of the incremental encoder
|
||||||
|
* @retval -180 to 180 where 0 is the incremental encoder pointing towards the back of the boat
|
||||||
|
*/
|
||||||
|
float INCR_ENCODER_GetAngle(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ void RF_INPUT_Init(void)
|
||||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||||||
LL_TIM_InitTypeDef tim4_init_struct;
|
LL_TIM_InitTypeDef tim4_init_struct;
|
||||||
|
|
||||||
tim4_init_struct.Autoreload= 0xFFFF; // ??
|
tim4_init_struct.Autoreload= 0xFFFF;
|
||||||
tim4_init_struct.Prescaler=71;
|
tim4_init_struct.Prescaler=71;
|
||||||
tim4_init_struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
|
tim4_init_struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
|
||||||
tim4_init_struct.CounterMode=LL_TIM_COUNTERMODE_UP;
|
tim4_init_struct.CounterMode=LL_TIM_COUNTERMODE_UP;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,38 @@
|
||||||
//codé par Kévin Cavailles et Jasper Güldenstein
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file RFInput.h
|
||||||
|
* @author CAVAILLES, Kevin and GÜLDENSTEIN, Jasper
|
||||||
|
* @brief Service for reveiving a PWM signal from an RF remote
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef RF_INPUT_H
|
||||||
|
#define RF_INPUT_H
|
||||||
|
|
||||||
|
/**
|
||||||
// initializes the PWM input of the remote on PB6
|
* @brief Initialziation function for the RF_OUTPUT module.
|
||||||
|
* Peripherals used: TIM4
|
||||||
|
* Pins used: PB6 (PWM Input)
|
||||||
|
*/
|
||||||
void RF_INPUT_Init(void);
|
void RF_INPUT_Init(void);
|
||||||
|
|
||||||
// returns the period of the PWM signal of the remote in us
|
/**
|
||||||
|
* @brief Reads the period of the PWM signal
|
||||||
|
* @retval period of the PWM signal in microseconds (10^(-6))
|
||||||
|
*/
|
||||||
int RF_INPUT_GetPeriodUs(void);
|
int RF_INPUT_GetPeriodUs(void);
|
||||||
|
|
||||||
// returns the duty time of the PWM signal of the remote in us
|
|
||||||
|
/**
|
||||||
|
* @brief Reads the length of the active time of the PWM signal
|
||||||
|
* @retval active time of the PWM signal in microseconds (10^(-6))
|
||||||
|
*/
|
||||||
int RF_INPUT_GetDutyTimeUs(void);
|
int RF_INPUT_GetDutyTimeUs(void);
|
||||||
|
|
||||||
// returns the duty time of the PWM signal of the remote as a value between -100 and 100
|
/**
|
||||||
|
* @brief Reads the length of the active time of the PWM signal and converts it to a relative value
|
||||||
|
* @retval value between -100 corresponding to 1000us and 100 corresponding to 2000us active time of the PWM signal
|
||||||
|
*/
|
||||||
int RF_INPUT_GetDutyTimeRelative(void);
|
int RF_INPUT_GetDutyTimeRelative(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
#include "RFOutput.h"
|
#include "RFOutput.h"
|
||||||
|
|
||||||
|
#include "stm32f1xx_ll_bus.h"
|
||||||
|
#include "stm32f1xx_ll_usart.h"
|
||||||
|
#include "stm32f1xx_ll_gpio.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
char RF_OUTPUT_buf[100];
|
char RF_OUTPUT_buf[100];
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,36 @@
|
||||||
#ifndef RECEPTEURHF_INPUT_H
|
/**
|
||||||
#define RECEPTEURHF_INPUT_H
|
******************************************************************************
|
||||||
|
* @file RFOutput.h
|
||||||
//codé par Léonie GALLOIS et Morgane FOUSSATS
|
* @author GALLOIS, Leonie and GÜLDENSTEIN, Jasper and FOUSSATS, Morgane
|
||||||
|
* @brief Service for using the RF Module to transmit characters.
|
||||||
#include "stm32f1xx_ll_bus.h"
|
******************************************************************************
|
||||||
#include "stm32f1xx_ll_usart.h"
|
*/
|
||||||
#include "stm32f1xx_ll_gpio.h"
|
#ifndef RF_OUTPUT_INPUT_H
|
||||||
|
#define RF_OUTPUT_INPUT_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialziation function for the RF_OUTPUT module.
|
||||||
|
* Peripherals used: USART1
|
||||||
|
* Pins used: PA9 (USART1 TX)
|
||||||
|
* PA11 (TX Enable)
|
||||||
|
*/
|
||||||
void RF_OUTPUT_Init(void);
|
void RF_OUTPUT_Init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transmits a given number of bytes from a buffer using the RF Module
|
||||||
|
* @param buf pointer to start of buffer to be transmitted
|
||||||
|
* @param len length of the data to be transmitted
|
||||||
|
*/
|
||||||
void RF_OUTPUT_SendBytes(char* buf, int len);
|
void RF_OUTPUT_SendBytes(char* buf, int len);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transmits a formatted string of the given parameters
|
||||||
|
* @param rouli_bon whether or not the angle is in an acceptable range
|
||||||
|
* @param alimentation_bon whether or not the battery voltage has acceptable level
|
||||||
|
* @param angle_voile opening angle of the sail between 0 and 90
|
||||||
|
*/
|
||||||
void RF_OUTPUT_SendMessage(int rouli_bon, int alimentation_bon, float angle_voile);
|
void RF_OUTPUT_SendMessage(int rouli_bon, int alimentation_bon, float angle_voile);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,32 @@
|
||||||
#include "Sail.h"
|
#include "Sail.h"
|
||||||
#include "Servo.h"
|
|
||||||
|
|
||||||
|
#include "Servo.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define SAIL_TRANSFER_FACTOR 1.0
|
#define SAIL_TRANSFER_FACTOR 1.0
|
||||||
#define SAIL_TRANSFER_OFFSET 0
|
#define SAIL_TRANSFER_OFFSET 0
|
||||||
|
|
||||||
|
#define ANGLE_DEBUT 45
|
||||||
|
|
||||||
void SAIL_Init(void)
|
void SAIL_Init(void)
|
||||||
{
|
{
|
||||||
SERVO_Init();
|
SERVO_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SAIL_AngleFromGirouette(float girouette_value){
|
||||||
|
float vabs = fabs(girouette_value);
|
||||||
|
|
||||||
|
if(vabs < ANGLE_DEBUT)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
// map 45 to 180 -> 0 to 90 and floor it to get an integer
|
||||||
|
return floor((90 / (180 - ANGLE_DEBUT)) * (vabs - ANGLE_DEBUT));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void SAIL_SetAngle(float angle)
|
void SAIL_SetAngle(float angle)
|
||||||
{
|
{
|
||||||
float servo_angle = angle * SAIL_TRANSFER_FACTOR + SAIL_TRANSFER_OFFSET;
|
float servo_angle = angle * SAIL_TRANSFER_FACTOR + SAIL_TRANSFER_OFFSET;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
//codé par Kévin Cavailles et Jasper Güldenstein
|
//codé par Kévin Cavailles et Jasper Güldenstein
|
||||||
|
|
||||||
|
#ifndef SAIL_H
|
||||||
|
#define SAIL_H
|
||||||
|
|
||||||
void SAIL_Init(void);
|
void SAIL_Init(void);
|
||||||
|
|
||||||
|
int SAIL_AngleFromGirouette(float girouette_value);
|
||||||
// sets the opening angle of the sail
|
// sets the opening angle of the sail
|
||||||
void SAIL_SetAngle(float angle);
|
void SAIL_SetAngle(float angle);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#ifndef SERVO
|
#ifndef SERVO_H
|
||||||
#define SERVO
|
#define SERVO_H
|
||||||
|
|
||||||
//codé par Kévin Cavailles et Jasper Güldenstein
|
|
||||||
|
|
||||||
void SERVO_Init(void);
|
void SERVO_Init(void);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ int angle_roulis_good = 0;
|
||||||
int angle_sail = 0;
|
int angle_sail = 0;
|
||||||
int RF_Input_Duty = 0;
|
int RF_Input_Duty = 0;
|
||||||
int TX_Flag = 0, CONTROL_LOOP_Flag = 0;
|
int TX_Flag = 0, CONTROL_LOOP_Flag = 0;
|
||||||
|
float angle_incr_encoder = 0;
|
||||||
|
|
||||||
char wait_for_girouette[] = "En attente d'initialisation de la girouette\r\n";
|
char wait_for_girouette[] = "En attente d'initialisation de la girouette\r\n";
|
||||||
|
|
||||||
|
|
@ -79,8 +80,9 @@ int main(void)
|
||||||
SAIL_SetAngle(90);
|
SAIL_SetAngle(90);
|
||||||
DC_MOTOR_SetSpeed(0);
|
DC_MOTOR_SetSpeed(0);
|
||||||
}else{
|
}else{
|
||||||
angle_sail = INCR_ENCODER_GetAngle();
|
angle_incr_encoder = INCR_ENCODER_GetAngle();
|
||||||
SAIL_SetAngle(angle_sail/2);
|
angle_sail = SAIL_AngleFromGirouette(angle_incr_encoder);
|
||||||
|
SAIL_SetAngle(angle_sail);
|
||||||
RF_Input_Duty = RF_INPUT_GetDutyTimeRelative();
|
RF_Input_Duty = RF_INPUT_GetDutyTimeRelative();
|
||||||
DC_MOTOR_SetSpeed(RF_Input_Duty);
|
DC_MOTOR_SetSpeed(RF_Input_Duty);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue