Compare commits
11 commits
db573aee04
...
4a430029df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a430029df | ||
|
|
3789f1b8ca | ||
|
|
bad2a4bd54 | ||
|
|
c5f0beac0b | ||
|
|
ea88a3601e | ||
|
|
9ccbfa5cac | ||
|
|
148ae858b5 | ||
|
|
6c6856c056 | ||
|
|
d71b640823 | ||
|
|
2b236173af | ||
|
|
11ff5e724f |
8 changed files with 134 additions and 41 deletions
|
|
@ -1,5 +1,24 @@
|
|||
#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){
|
||||
RCC -> CFGR |= (0x1<<15);
|
||||
RCC-> CFGR &= ~ (0x1<<14);
|
||||
|
|
@ -39,29 +58,29 @@ double ACCELEROMETER_GetX(void){
|
|||
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_1);
|
||||
LL_ADC_REG_StartConversionSWStart(ADC1);
|
||||
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1);
|
||||
double x= LL_ADC_REG_ReadConversionData12(ADC1);
|
||||
double x= (LL_ADC_REG_ReadConversionData12(ADC1) - ZERO_G_READING) * VOLT_PER_G;
|
||||
return x;
|
||||
}
|
||||
|
||||
double ACCELEROMETER_GetY(void){
|
||||
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_11);
|
||||
LL_ADC_REG_StartConversionSWStart(ADC1);
|
||||
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1);
|
||||
double y = LL_ADC_REG_ReadConversionData12(ADC1);
|
||||
return y;
|
||||
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1);
|
||||
double y = (LL_ADC_REG_ReadConversionData12(ADC1)-ZERO_G_READING) * VOLT_PER_G;
|
||||
return y;
|
||||
}
|
||||
|
||||
int ACCELEROMETER_AngleGood(void){
|
||||
double x = ACCELEROMETER_GetX();
|
||||
double y = ACCELEROMETER_GetY();
|
||||
double angle = x/y;
|
||||
double angle = atan(x/y);
|
||||
|
||||
if (angle>tan(0.698132)){
|
||||
return 0;
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
//le flag EOC n'est jamais mis à un ....
|
||||
// Soit la conversion est mal faite soit on n'utilise pas bien la simulation
|
||||
//soit on n'utilise pas bien isActiveFlag dans la boucle
|
||||
if (fabs(angle)>ANGLE_LIMIT_RAD){
|
||||
return 0;
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
//le flag EOC n'est jamais mis à un ....
|
||||
// Soit la conversion est mal faite soit on n'utilise pas bien la simulation
|
||||
//soit on n'utilise pas bien isActiveFlag dans la boucle
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,38 @@
|
|||
// 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 reading the analog signals of the Accelerometer.
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef ACCELERO_H
|
||||
#define ACCELERO_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"
|
||||
|
||||
/* =====================================================================================
|
||||
Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1)
|
||||
=======================================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Initializes for reading the Accelerometer
|
||||
* Peripherals used: ADC1
|
||||
* Pins used: PC0 (Analog Input, X channel accelerometer)
|
||||
* Pins used: PC1 (Analog Input, Y channel accelerometer)
|
||||
*/
|
||||
void ACCELEROMETER_Init(void);
|
||||
|
||||
/**
|
||||
* @brief Reads the accelerometer x channel
|
||||
* @retval acceleration in x direction in g
|
||||
*/
|
||||
double ACCELEROMETER_GetX(void);
|
||||
|
||||
/**
|
||||
* @brief Reads the accelerometer y channel
|
||||
* @retval acceleration in y direction in g
|
||||
*/
|
||||
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);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@
|
|||
#include "stm32f1xx_ll_bus.h"
|
||||
#include "stm32f1xx_ll_tim.h"
|
||||
|
||||
#define ARR_DC_MOTOR 50000
|
||||
#define ARR_DC_MOTOR 100
|
||||
void DC_MOTOR_Init(void) {
|
||||
// use TIM2 since it has pa1 at channel 2 output
|
||||
// setup timer 2
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
LL_TIM_InitTypeDef tim_init;
|
||||
// todo check switching behavior of the mosfet to determine period of switching
|
||||
tim_init.Prescaler = 71;
|
||||
tim_init.Prescaler = 35;
|
||||
tim_init.Autoreload = ARR_DC_MOTOR - 1;
|
||||
tim_init.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
|
||||
tim_init.CounterMode=LL_TIM_COUNTERMODE_UP;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,25 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @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
|
||||
#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);
|
||||
|
||||
// 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);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,13 +1,31 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file IncrEncoder.h
|
||||
* @author CAVAILLES, Kevin and GÜLDENSTEIN, Jasper
|
||||
* @brief Service for reading the incremental encoder.
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef 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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @brief Returns the angle of the incremental encoder
|
||||
* @brief Returns the angle reading 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);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#define RF_INPUT_H
|
||||
|
||||
/**
|
||||
* @brief Initialziation function for the RF_OUTPUT module.
|
||||
* @brief Initialziation function for the RF_INPUT module.
|
||||
* Peripherals used: TIM4
|
||||
* Pins used: PB6 (PWM Input)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,12 +1,27 @@
|
|||
//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
|
||||
#define SAIL_H
|
||||
|
||||
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);
|
||||
// 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);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,8 +1,26 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file Servo.h
|
||||
* @author CAVAILLES, Kevin and GÜLDENSTEIN, Jasper
|
||||
* @brief Service for using the Servo to set the sail angle.
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef 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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue