Compare commits

...

7 commits

Author SHA1 Message Date
Jasper Güldenstein
db573aee04 Merge branch 'master' of https://git.etud.insa-toulouse.fr/guldenst/projet_voilier 2020-11-15 17:08:32 +01:00
Jasper Güldenstein
d2a19989fd documentation rfinput 2020-11-15 17:08:21 +01:00
Jasper Güldenstein
a4c1eaa559 increase adaptability and understandability of incremental incoder to
sail angle
2020-11-15 16:57:02 +01:00
Jasper Güldenstein
779b5cfaf1 alimenation documentation and move of includes to c 2020-11-15 16:52:49 +01:00
Jasper Güldenstein
625998d321 move includes from h to c file 2020-11-15 16:26:48 +01:00
Jasper Güldenstein
cacd44d03d RFOutput docs 2020-11-15 16:07:08 +01:00
Jasper Güldenstein
dc1aa96d9a ifndef in all the h files 2020-11-15 15:31:25 +01:00
13 changed files with 144 additions and 63 deletions

View file

@ -1,5 +1,10 @@
#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){
RCC -> CFGR |= (0x1<<15);

View file

@ -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
#define ALIMENTATION_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 of the power supply/battery level
* Peripherals used: ADC1
* Pins used: PC2 (Analog input)
*/
void ALIMENTATION_Init(void);
/**
* @brief Reads the power supply/battery level
* @retval battery level in Volts
*/
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);

View file

@ -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);
// set a speed between -100 (full throttle clockwise) 0 (stop) and 100 (full throttle counterclockwise)
void DC_MOTOR_SetSpeed(int speed);
#endif

View file

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

View file

@ -1,11 +1,15 @@
#ifndef INCR_ENCODER
#ifndef INCR_ENCODER_H
#define INCR_ENCODER_H
/**
*/
void INCR_ENCODER_Init(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

View file

@ -26,7 +26,7 @@ void RF_INPUT_Init(void)
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
LL_TIM_InitTypeDef tim4_init_struct;
tim4_init_struct.Autoreload= 0xFFFF; // ??
tim4_init_struct.Autoreload= 0xFFFF;
tim4_init_struct.Prescaler=71;
tim4_init_struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
tim4_init_struct.CounterMode=LL_TIM_COUNTERMODE_UP;

View file

@ -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);
// 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);
// 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);
// 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);
#endif

View file

@ -1,4 +1,8 @@
#include "RFOutput.h"
#include "stm32f1xx_ll_bus.h"
#include "stm32f1xx_ll_usart.h"
#include "stm32f1xx_ll_gpio.h"
#include <stdio.h>
char RF_OUTPUT_buf[100];

View file

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

View file

@ -1,15 +1,32 @@
#include "Sail.h"
#include "Servo.h"
#include "Servo.h"
#include <stdlib.h>
#include <math.h>
#define SAIL_TRANSFER_FACTOR 1.0
#define SAIL_TRANSFER_OFFSET 0
#define ANGLE_DEBUT 45
void SAIL_Init(void)
{
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)
{
float servo_angle = angle * SAIL_TRANSFER_FACTOR + SAIL_TRANSFER_OFFSET;

View file

@ -1,6 +1,12 @@
//codé par Kévin Cavailles et Jasper Güldenstein
#ifndef SAIL_H
#define SAIL_H
void SAIL_Init(void);
int SAIL_AngleFromGirouette(float girouette_value);
// sets the opening angle of the sail
void SAIL_SetAngle(float angle);
void SAIL_SetAngle(float angle);
#endif

View file

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

View file

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