Compare commits

..

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

8 changed files with 41 additions and 134 deletions

View file

@ -1,24 +1,5 @@
#include "Accelerometer.h" #include "Accelerometer.h"
#include "stm32f103xb.h"
#include "stm32f1xx_ll_adc.h"
#include "stm32f1xx_ll_bus.h"
#include "stm32f1xx_ll_rcc.h"
#include "stm32f1xx_ll_gpio.h"
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define ANGLE_LIMIT_DEG 40
#define ANGLE_LIMIT_RAD ANGLE_LIMIT_DEG * (180.0 / M_PI)
#define ZERO_G_VOLTAGE 1.65
#define ZERO_G_READING (ZERO_G_VOLTAGE / 3.3) * 4095
#define VOLT_PER_G 0.48
void ACCELEROMETER_Init(void){ void ACCELEROMETER_Init(void){
RCC -> CFGR |= (0x1<<15); RCC -> CFGR |= (0x1<<15);
RCC-> CFGR &= ~ (0x1<<14); RCC-> CFGR &= ~ (0x1<<14);
@ -58,29 +39,29 @@ double ACCELEROMETER_GetX(void){
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_1); LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_1);
LL_ADC_REG_StartConversionSWStart(ADC1); LL_ADC_REG_StartConversionSWStart(ADC1);
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1);
double x= (LL_ADC_REG_ReadConversionData12(ADC1) - ZERO_G_READING) * VOLT_PER_G; double x= LL_ADC_REG_ReadConversionData12(ADC1);
return x; return x;
} }
double ACCELEROMETER_GetY(void){ double ACCELEROMETER_GetY(void){
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_11); LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_11);
LL_ADC_REG_StartConversionSWStart(ADC1); LL_ADC_REG_StartConversionSWStart(ADC1);
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1);
double y = (LL_ADC_REG_ReadConversionData12(ADC1)-ZERO_G_READING) * VOLT_PER_G; double y = LL_ADC_REG_ReadConversionData12(ADC1);
return y; return y;
} }
int ACCELEROMETER_AngleGood(void){ int ACCELEROMETER_AngleGood(void){
double x = ACCELEROMETER_GetX(); double x = ACCELEROMETER_GetX();
double y = ACCELEROMETER_GetY(); double y = ACCELEROMETER_GetY();
double angle = atan(x/y); double angle = x/y;
if (fabs(angle)>ANGLE_LIMIT_RAD){ if (angle>tan(0.698132)){
return 0; return 0;
}else { }else {
return 1; return 1;
} }
//le flag EOC n'est jamais mis à un .... //le flag EOC n'est jamais mis à un ....
// Soit la conversion est mal faite soit on n'utilise pas bien la simulation // Soit la conversion est mal faite soit on n'utilise pas bien la simulation
//soit on n'utilise pas bien isActiveFlag dans la boucle //soit on n'utilise pas bien isActiveFlag dans la boucle
} }

View file

@ -1,38 +1,29 @@
/** // 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 reading the analog signals of the Accelerometer.
******************************************************************************
*/
#ifndef ACCELERO_H #ifndef ACCELERO_H
#define ACCELERO_H #define ACCELERO_H
/**
* @brief Initializes for reading the Accelerometer
* Peripherals used: ADC1 #include "stm32f103xb.h"
* Pins used: PC0 (Analog Input, X channel accelerometer) #include "stm32f1xx_ll_adc.h"
* Pins used: PC1 (Analog Input, Y channel accelerometer) #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 ACCELEROMETER_Init(void); void ACCELEROMETER_Init(void);
/**
* @brief Reads the accelerometer x channel
* @retval acceleration in x direction in g
*/
double ACCELEROMETER_GetX(void); double ACCELEROMETER_GetX(void);
/**
* @brief Reads the accelerometer y channel
* @retval acceleration in y direction in g
*/
double ACCELEROMETER_GetY(void); double ACCELEROMETER_GetY(void);
/**
* @brief Reads the accelerometer x and y channel
Calculates if the roll angle lies between -40 and 40 degrees
* @retval state (0 or 1)
*/
int ACCELEROMETER_AngleGood(void); int ACCELEROMETER_AngleGood(void);

View file

@ -3,12 +3,14 @@
#include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_bus.h"
#include "stm32f1xx_ll_tim.h" #include "stm32f1xx_ll_tim.h"
#define ARR_DC_MOTOR 100 #define ARR_DC_MOTOR 50000
void DC_MOTOR_Init(void) { void DC_MOTOR_Init(void) {
// use TIM2 since it has pa1 at channel 2 output
// setup timer 2 // setup timer 2
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
LL_TIM_InitTypeDef tim_init; LL_TIM_InitTypeDef tim_init;
tim_init.Prescaler = 35; // todo check switching behavior of the mosfet to determine period of switching
tim_init.Prescaler = 71;
tim_init.Autoreload = ARR_DC_MOTOR - 1; tim_init.Autoreload = ARR_DC_MOTOR - 1;
tim_init.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1; tim_init.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
tim_init.CounterMode=LL_TIM_COUNTERMODE_UP; tim_init.CounterMode=LL_TIM_COUNTERMODE_UP;

View file

@ -1,25 +1,9 @@
/**
******************************************************************************
* @file DCMotor.h
* @author CAVAILLES, Kevin and GÜLDENSTEIN, Jasper
* @brief Service for setting the speed of a DC motor using a PWM signal.
******************************************************************************
*/
#ifndef DC_MOTOR_H #ifndef DC_MOTOR_H
#define DC_MOTOR_H #define DC_MOTOR_H
/**
* @brief Initialziation function for the DC_MOTOR module.
* Peripherals used: TIM2
* Pins used: PA1 (TIM2 channel 1, PWM Output)
* PA2 (GPIO, direction control)
*/
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)
* @brief Sets the speed of the DC motor using a PWM signal with a period of 50us -> frequency of 20kHz and a resolution of 0.5us
* @param speed value 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 #endif

View file

@ -1,31 +1,13 @@
/**
******************************************************************************
* @file IncrEncoder.h
* @author CAVAILLES, Kevin and GÜLDENSTEIN, Jasper
* @brief Service for reading the incremental encoder.
******************************************************************************
*/
#ifndef INCR_ENCODER_H #ifndef INCR_ENCODER_H
#define INCR_ENCODER_H #define INCR_ENCODER_H
/**
* @brief Initialziation function for the RF_OUTPUT module.
* Peripherals used: TIM3, EXTI
* Pins used: PA5 (incremental encoder index, interrupt)
* PA6 (incremental encoder channel a, TIM3 channel 1)
* PA7 (incremental encoder channel b, TIM3 channel 2)
*/
void INCR_ENCODER_Init(void); void INCR_ENCODER_Init(void);
/**
* @brief Indicates whether the index has been passed at least once.
* If this is not the case, the reading is not absolute.
* @retval state (0 or 1)
*/
int INCR_ENCODER_IsAbsolute(void); int INCR_ENCODER_IsAbsolute(void);
/** /**
* @brief Returns the angle reading of the incremental encoder * @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 * @retval -180 to 180 where 0 is the incremental encoder pointing towards the back of the boat
*/ */
float INCR_ENCODER_GetAngle(void); float INCR_ENCODER_GetAngle(void);

View file

@ -9,7 +9,7 @@
#define RF_INPUT_H #define RF_INPUT_H
/** /**
* @brief Initialziation function for the RF_INPUT module. * @brief Initialziation function for the RF_OUTPUT module.
* Peripherals used: TIM4 * Peripherals used: TIM4
* Pins used: PB6 (PWM Input) * Pins used: PB6 (PWM Input)
*/ */

View file

@ -1,27 +1,12 @@
/** //codé par Kévin Cavailles et Jasper Güldenstein
******************************************************************************
* @file Sail.h
* @author CAVAILLES, Kevin and GÜLDENSTEIN, Jasper
* @brief Service for using the RF Module to transmit characters.
******************************************************************************
*/
#ifndef SAIL_H #ifndef SAIL_H
#define SAIL_H #define SAIL_H
void SAIL_Init(void); void SAIL_Init(void);
/**
* @brief Calculates the "optimal" opening angle of the sail depending on the reading of the girouette
* @param girouette_value angle reading where 0 corresponds to the wind blowing from the front
*
* @retval angle between 0 and 90 (degrees)
*/
int SAIL_AngleFromGirouette(float girouette_value); int SAIL_AngleFromGirouette(float girouette_value);
// sets the opening angle of the sail
/**
* @brief Sets the opening angle of the sail
* @param opening angle of the sail between 0 and 90 (degrees)
*/
void SAIL_SetAngle(float angle); void SAIL_SetAngle(float angle);
#endif #endif

View file

@ -1,26 +1,8 @@
/**
******************************************************************************
* @file Servo.h
* @author CAVAILLES, Kevin and GÜLDENSTEIN, Jasper
* @brief Service for using the Servo to set the sail angle.
******************************************************************************
*/
#ifndef SERVO_H #ifndef SERVO_H
#define SERVO_H #define SERVO_H
/**
* @brief Initialziation function for the RF_OUTPUT module.
* The period of the PWM signal is 20ms.
* Peripherals used: TIM1
* Pins used: PA8 (TIM1 channel 1)
*/
void SERVO_Init(void); void SERVO_Init(void);
/**
* @brief Sets the angle of the servo using a PWM signal with a on time between 1ms and 2ms and a resolution of 1us
* @param angle of the servo between XXXXX and YYYYY degree
*/
void SERVO_SetAngle(int angle); void SERVO_SetAngle(int angle);
#endif #endif