Compare commits

..

No commits in common. "db573aee0458fa7221c7d7449a39a5f5e57a365b" and "ae29b5de4a7f0807c803be7788ba0ad5bee8d8f0" have entirely different histories.

13 changed files with 63 additions and 144 deletions

View file

@ -1,10 +1,5 @@
#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);

View file

@ -1,30 +1,25 @@
/** // RIEN A MODIFIER //
******************************************************************************
* @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.
******************************************************************************
*/
#ifndef ALIMENTATION_H #ifndef ALIMENTATION_H
#define ALIMENTATION_H #define ALIMENTATION_H
/**
* @brief Initializes for reading of the power supply/battery level
* Peripherals used: ADC1 #include "stm32f103xb.h"
* Pins used: PC2 (Analog input) #include "stm32f1xx_ll_adc.h"
*/ #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);

View file

@ -1,9 +1,6 @@
#ifndef DC_MOTOR_H //codé par Kévin Cavailles et Jasper Güldenstein
#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

View file

@ -7,11 +7,13 @@
#include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_exti.h"
#include "stm32f1xx_ll_tim.h" #include "stm32f1xx_ll_tim.h"
#define ZERO_POSITION 0 #define RESOLUTION 1
#define TICKS_PER_REVOLUTION 360*4 #define ANGLE_DEBUT 45
#define DEGREE_PER_TICKS 0.25 #define INCR_ENCODER_MID_VALUE 719
int index_passed = 0; int index_passed = 0;
int counts_per_revolution = 360;
void INCR_ENCODER_Init(void){ void INCR_ENCODER_Init(void){
@ -31,7 +33,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= TICKS_PER_REVOLUTION-1; tim3_init_struct.Autoreload= counts_per_revolution*4-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;
@ -99,12 +101,17 @@ int INCR_ENCODER_IsAbsolute(void)
return index_passed; return index_passed;
}; };
float INCR_ENCODER_GetAngle(void) int INCR_ENCODER_GetAngle(void)
{ {
int counter_value = LL_TIM_ReadReg(TIM3, CNT); int counter_value = LL_TIM_ReadReg(TIM3, CNT);
// center float vabs = abs(counter_value-INCR_ENCODER_MID_VALUE);
int centered_counter_value = (counter_value - ZERO_POSITION) % TICKS_PER_REVOLUTION; float vIEAngleDebut = INCR_ENCODER_MID_VALUE -(ANGLE_DEBUT*4);
// translate ticks to angle float nbIncrements = 90/RESOLUTION;
float angle = centered_counter_value * DEGREE_PER_TICKS;
return angle; if(vabs > vIEAngleDebut)
{
return 0;
}else{
return 90 - RESOLUTION*floor(vabs/(vIEAngleDebut/nbIncrements) ) ;
}
}; };

View file

@ -1,15 +1,11 @@
#ifndef INCR_ENCODER_H #ifndef INCR_ENCODER
#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

View file

@ -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;

View file

@ -1,38 +1,14 @@
/** //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
/**
* @brief Initialziation function for the RF_OUTPUT module. // initializes the PWM input of the remote on PB6
* 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

View file

@ -1,8 +1,4 @@
#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];

View file

@ -1,36 +1,16 @@
/** #ifndef RECEPTEURHF_INPUT_H
****************************************************************************** #define RECEPTEURHF_INPUT_H
* @file RFOutput.h
* @author GALLOIS, Leonie and GÜLDENSTEIN, Jasper and FOUSSATS, Morgane //codé par Léonie GALLOIS et Morgane FOUSSATS
* @brief Service for using the RF Module to transmit characters.
****************************************************************************** #include "stm32f1xx_ll_bus.h"
*/ #include "stm32f1xx_ll_usart.h"
#ifndef RF_OUTPUT_INPUT_H #include "stm32f1xx_ll_gpio.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

View file

@ -1,32 +1,15 @@
#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;

View file

@ -1,12 +1,6 @@
//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

View file

@ -1,5 +1,7 @@
#ifndef SERVO_H #ifndef SERVO
#define SERVO_H #define SERVO
//codé par Kévin Cavailles et Jasper Güldenstein
void SERVO_Init(void); void SERVO_Init(void);

View file

@ -44,7 +44,6 @@ 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";
@ -80,9 +79,8 @@ int main(void)
SAIL_SetAngle(90); SAIL_SetAngle(90);
DC_MOTOR_SetSpeed(0); DC_MOTOR_SetSpeed(0);
}else{ }else{
angle_incr_encoder = INCR_ENCODER_GetAngle(); angle_sail = INCR_ENCODER_GetAngle();
angle_sail = SAIL_AngleFromGirouette(angle_incr_encoder); SAIL_SetAngle(angle_sail/2);
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);
} }