accelerometer and display fix
This commit is contained in:
parent
c8ea3f3a91
commit
64ea0cbd78
10 changed files with 54 additions and 87 deletions
|
@ -75,7 +75,7 @@
|
|||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
@ -130,7 +130,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=204,363,702,652,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=1045,583,1603,1080,0)(121=971,583,1529,1080,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=200,173,988,1026,0)(131=405,227,1193,1080,0)(132=161,47,949,900,0)(133=1013,172,1801,1025,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=320,247,1120,1026,0)(151=1120,301,1920,1080,0)</Name>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=204,363,702,652,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=293,271,851,768,0)(121=854,376,1412,873,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=200,173,988,1026,0)(131=410,141,1198,994,0)(132=161,47,949,900,0)(133=966,188,1754,1041,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=320,247,1120,1026,0)(151=1120,301,1920,1080,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -157,41 +157,9 @@
|
|||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>41</LineNumber>
|
||||
<EnabledFlag>0</EnabledFlag>
|
||||
<Address>134220664</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\Services\Accelerometer.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\NUCLEO_F103RB\../Services/Accelerometer.c\41</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>33</LineNumber>
|
||||
<EnabledFlag>0</EnabledFlag>
|
||||
<Address>134231164</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\Services\Accelerometer.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\NUCLEO_F103RB\../Services/Accelerometer.c\33</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>2</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>33</LineNumber>
|
||||
<EnabledFlag>0</EnabledFlag>
|
||||
<Address>134231194</Address>
|
||||
<Address>134231986</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
|
@ -207,37 +175,12 @@
|
|||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>windAngle,0x0A</ItemText>
|
||||
<ItemText>sailAngle,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>angleDeg,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>volts</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>angleRad</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>value,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>speed,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>6</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>TIMx->CCR2</ItemText>
|
||||
<ItemText>dutyCycle</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<Tracepoint>
|
||||
|
@ -352,7 +295,7 @@
|
|||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
|
|
@ -229,10 +229,14 @@ float Timer_pwmo_getDutyCycle(TIM_TypeDef * timer, int channel)
|
|||
{
|
||||
int compare = 0;
|
||||
const int arr = LL_TIM_GetAutoReload(timer);
|
||||
if (channel == LL_TIM_CHANNEL_CH1) compare = LL_TIM_OC_GetCompareCH1(timer);
|
||||
else if (channel == LL_TIM_CHANNEL_CH2) compare = LL_TIM_OC_GetCompareCH2(timer);
|
||||
else if (channel == LL_TIM_CHANNEL_CH3) compare = LL_TIM_OC_GetCompareCH3(timer);
|
||||
else compare = LL_TIM_OC_GetCompareCH4(timer);
|
||||
if (channel == LL_TIM_CHANNEL_CH1)
|
||||
compare = LL_TIM_OC_GetCompareCH1(timer);
|
||||
else if (channel == LL_TIM_CHANNEL_CH2)
|
||||
compare = LL_TIM_OC_GetCompareCH2(timer);
|
||||
else if (channel == LL_TIM_CHANNEL_CH3)
|
||||
compare = LL_TIM_OC_GetCompareCH3(timer);
|
||||
else
|
||||
compare = LL_TIM_OC_GetCompareCH4(timer);
|
||||
return ((float) compare) / ((float) arr);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc);
|
|||
* @brief Configure le timer en mode PWM input
|
||||
* @note
|
||||
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
|
||||
* int channel : Le channel utilisé par la PWM
|
||||
* int channel : Le channel utilisé par la PWM (pas LL)
|
||||
* @retval None
|
||||
*/
|
||||
void Timer_pwmi_conf(TIM_TypeDef * timer, int channel);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Accelerometer.h"
|
||||
#include "ADC.h"
|
||||
#include "math.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
|
@ -8,8 +9,10 @@
|
|||
// Donc sensibilité de +- 480 mv/g
|
||||
|
||||
|
||||
const float ZERO_G = 1.65; // 0 g
|
||||
const float SENSITIVITY = 0.48;
|
||||
const float ZERO_G = 1.27; // 0 g
|
||||
const float SENSITIVITY = 1.35-0.9;
|
||||
// max: 1.75
|
||||
// min: 0.935
|
||||
|
||||
void Accelerometer_conf(ADC_TypeDef *adc, GPIO_TypeDef * gpio, int pinx, int piny)
|
||||
{
|
||||
|
@ -35,10 +38,11 @@ float voltsToG(float volts)
|
|||
|
||||
int Accelerometer_getAngle(ADC_TypeDef *adc, int channel)
|
||||
{
|
||||
const float readG = voltsToG(ADC_readVolt(adc, channel));
|
||||
const float readV = ADC_readVolt(adc, channel);
|
||||
const float readG = voltsToG(readV);
|
||||
|
||||
float angleRad = asin(readG);
|
||||
int angleDeg = angleRad * (180/M_PI);
|
||||
|
||||
|
||||
return angleDeg;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,11 @@ float convertAngleToDutyCycle(int angle) {
|
|||
return (float)angle / 1800.0 + 0.05;
|
||||
}
|
||||
|
||||
int convertDutyCycleToAngle(float dutyCycle) {
|
||||
// fonction lineaire [0.049 - 0.1] -> [0 - 90]
|
||||
return (dutyCycle - 0.049) * 1800;
|
||||
}
|
||||
|
||||
void ServoMotor_setAngle(TIM_TypeDef * timer, int channel, int angle)
|
||||
{
|
||||
Timer_pwmo_setDutyCycle(timer, channel, convertAngleToDutyCycle(angle));
|
||||
|
@ -26,5 +31,5 @@ void ServoMotor_setAngle(TIM_TypeDef * timer, int channel, int angle)
|
|||
int ServoMotor_getAngle(TIM_TypeDef * timer, int channel)
|
||||
{
|
||||
const float dutyCycle = Timer_pwmo_getDutyCycle(timer, channel);
|
||||
return 359 * dutyCycle;
|
||||
return convertDutyCycleToAngle(dutyCycle);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ void Display_start()
|
|||
RFEmitter_start(EMITTER_USART);
|
||||
}
|
||||
|
||||
|
||||
void Display_background(int secCounter)
|
||||
{
|
||||
static int previousEmergencyState = 0;
|
||||
|
@ -36,20 +35,27 @@ void Display_background(int secCounter)
|
|||
|
||||
const int emergency = Sail_getEmergencyState();
|
||||
|
||||
if (secCounter - prevSendSec == 3 || (emergency && !previousEmergencyState)) {
|
||||
if (secCounter - prevSendSec == 1 || (emergency && !previousEmergencyState)) {
|
||||
previousEmergencyState = emergency;
|
||||
prevSendSec = secCounter;
|
||||
|
||||
const float voltage = Voltage_getVoltage(VOLTAGE_ADC, VOLTAGE_CHANNEL);
|
||||
const int sailAngle = Sail_getSailAngle();
|
||||
const int relativeAngle = sailAngle >= 180 ? 360 - sailAngle : sailAngle;
|
||||
const int sailPercent = (90 - relativeAngle) * 100 / 90;
|
||||
const int sailPercent = sailAngle * 100 / 90.0;
|
||||
// const int relativeAngle = sailAngle >= 180 ? 360 - sailAngle : sailAngle;
|
||||
// const int sailPercent = (90 - relativeAngle) * 100 / 90;
|
||||
|
||||
char displayStr[100];
|
||||
|
||||
sprintf(displayStr, "Bordage actuel = %d%%\nTension de la batterie = %fV\n", sailPercent, voltage);
|
||||
if (emergency)
|
||||
sprintf(displayStr, "Limite de roulis atteinte !\n%s", displayStr);
|
||||
|
||||
char displayStr[100] = "";
|
||||
char emergStr[30] = "";
|
||||
|
||||
if (emergency) {
|
||||
sprintf(emergStr, "Limite de roulis atteinte !\n\r");
|
||||
RFEmitter_send(EMITTER_USART, emergStr, strlen(emergStr), EMITTER_GPIO, EMITTER_PIN);
|
||||
}
|
||||
|
||||
sprintf(displayStr, "Angle de la voile : %ddeg\n\rBordage actuel = %d%% \n\rTension de la batterie = %fV \n\r\n\r", sailAngle, sailPercent, voltage);
|
||||
RFEmitter_send(EMITTER_USART, displayStr, strlen(displayStr), EMITTER_GPIO, EMITTER_PIN);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ const int RECEIVER_CHANNEL = LL_TIM_CHANNEL_CH1;
|
|||
TIM_TypeDef * DCMOTOR_TIMER = TIM2;
|
||||
const int DCMOTOR_CHANNEL = LL_TIM_CHANNEL_CH2;
|
||||
GPIO_TypeDef * DCMOTOR_GPIO = GPIOA;
|
||||
const int DCMOTOR_PIN_PWM = LL_GPIO_PIN_2;
|
||||
const int DCMOTOR_PIN_PWM = LL_GPIO_PIN_1;
|
||||
const int DCMOTOR_PIN_DIRECTION = LL_GPIO_PIN_2;
|
||||
|
||||
|
||||
|
|
11
Src/Roll.c
11
Src/Roll.c
|
@ -29,12 +29,17 @@ int Roll_getEmergencyState(void)
|
|||
return Roll_isEmergencyState;
|
||||
}
|
||||
|
||||
int current = 0;
|
||||
int angle= 0;
|
||||
|
||||
void Roll_background(void)
|
||||
{
|
||||
const int xAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_X_CHANNEL);
|
||||
// const int xAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_X_CHANNEL);
|
||||
const int yAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL);
|
||||
|
||||
const int currentState = abs(yAngle) >= 40;
|
||||
angle = yAngle;
|
||||
|
||||
const int currentState = Roll_isEmergencyState ? abs(yAngle) >= 10 : abs(yAngle) >= 40;
|
||||
current = currentState;
|
||||
if (Roll_isEmergencyState != currentState) {
|
||||
Sail_setEmergency(currentState);
|
||||
Roll_isEmergencyState = currentState;
|
||||
|
|
|
@ -11,7 +11,7 @@ TIM_TypeDef * ENCODER_TIMER = TIM3;
|
|||
GPIO_TypeDef * ENCODER_GPIO = GPIOA;
|
||||
const int ENCODER_PIN = LL_GPIO_PIN_5;
|
||||
|
||||
const int RESET_ANGLE = 90;
|
||||
const int RESET_ANGLE = 0;
|
||||
|
||||
int Sail_isEmergencyState = 0;
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ int main(void)
|
|||
Scheduler_start();
|
||||
|
||||
while (1) {
|
||||
// Display_background(secCounter);
|
||||
Display_background(secCounter);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue