-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New pid #11
base: main
Are you sure you want to change the base?
Conversation
…xtern is in usage
Modules/motors/motor_interface.c
Outdated
if(params[i].id == LR || params[i].id == RR){ | ||
old_duty = hPwm.Instance->CCR1; | ||
if(750+*(float*)PID_map[i].ptr > PWM_MAX_DUTY) | ||
PWM_SetDutyCycle(CHANNEL1, PWM_MAX_DUTY); | ||
else if(750+*(float*)PID_map[i].ptr < PWM_MIN_DUTY) | ||
PWM_SetDutyCycle(CHANNEL1, PWM_MIN_DUTY); | ||
else | ||
PWM_SetDutyCycle(CHANNEL1, 750+*(float*)PID_map[i].ptr); | ||
} | ||
if(params[i].id == LM || params[i].id == RM){ | ||
old_duty = hPwm.Instance->CCR2; | ||
if(750+*(float*)PID_map[i].ptr > PWM_MAX_DUTY) | ||
PWM_SetDutyCycle(CHANNEL2, PWM_MAX_DUTY); | ||
else if(750+*(float*)PID_map[i].ptr < PWM_MIN_DUTY) | ||
PWM_SetDutyCycle(CHANNEL2, PWM_MIN_DUTY); | ||
else | ||
PWM_SetDutyCycle(CHANNEL2, 750+*(float*)PID_map[i].ptr); | ||
} | ||
if(params[i].id == LF || params[i].id == RF){ | ||
old_duty = hPwm.Instance->CCR3; | ||
if(750+*(float*)PID_map[i].ptr > PWM_MAX_DUTY) | ||
PWM_SetDutyCycle(CHANNEL3, PWM_MAX_DUTY); | ||
else if(750+*(float*)PID_map[i].ptr < PWM_MIN_DUTY) | ||
PWM_SetDutyCycle(CHANNEL3, PWM_MIN_DUTY); | ||
else | ||
PWM_SetDutyCycle(CHANNEL3, 750+*(float*)PID_map[i].ptr); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To można zamknąć pod jednym ifem. Dla wszystkich trzech silników ustawiamy ten sam PWM. To co musimy osiągnąć to to samo wypełnienie na trzech wyjściach.
struct Map encoders_map[3] = { { .key = 0, .ptr = &g_encoder1Tick }, { | ||
.key = 1, .ptr = &g_encoder2Tick }, { .key = 2, .ptr = | ||
&g_encoder3Tick } }; | ||
if (params == NULL || array_length == 0) { | ||
return false; | ||
} | ||
int i = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatowanie poszło w las.
return false; | ||
} | ||
int i = 0; | ||
for (i = 0; i < array_length; i += 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Po co inicjalizacja i
poza pętlą jak tutaj ją zerujesz?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (i = 0; i < array_length; i += 1) { | |
for (i = 0; i < array_length; i ++) { |
Modules/motors/motor_interface.c
Outdated
// setting PWM duty to concrete channel; | ||
for (uint8_t i=0; i<3; i++) | ||
{ | ||
if(params[i].id == LR || params[i].id == RR){ | ||
old_duty = hPwm.Instance->CCR1; | ||
if(750+*(float*)PID_map[i].ptr > PWM_MAX_DUTY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FORMATOWANIE!
} | ||
if(params[i].id == LM || params[i].id == RM){ | ||
old_duty = hPwm.Instance->CCR2; | ||
if(750+*(float*)PID_map[i].ptr > PWM_MAX_DUTY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic numbers, co to 750?
Modules/motors/motor_interface.c
Outdated
PWM_SetDutyCycle(CHANNEL1, 750+*(float*)PID_map[i].ptr); | ||
} | ||
if(params[i].id == LM || params[i].id == RM){ | ||
old_duty = hPwm.Instance->CCR2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nie da się tego zrobić bez grzebania w rejestrach? HAL nie udostępnia API, które to umożliwia?
else if(750+*(float*)PID_map[i].ptr < PWM_MIN_DUTY) | ||
PWM_SetDutyCycle(CHANNEL3, PWM_MIN_DUTY); | ||
else | ||
PWM_SetDutyCycle(CHANNEL3, 750+*(float*)PID_map[i].ptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obstawiam, że da się zrobić coś takiego jak:
PWM_SetDutyCycle(CHANNEL1 | CHANNEL2 | CHANNEL3, 750+*(float*)PID_map[i].ptr);
// RM - right middle | ||
// RR - right rear | ||
typedef enum { | ||
LF, LM, LR, RF, RM, RR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wystarczy L i R. Nie ma potrzeby sterować oddzielnie każdym silnikiem.
// @param params array of singleMotorParam structures for 3 motors from one side of the rover | ||
// @param array_length length of params array (is anticipated to be always 3 - 3 motors connected to one board) | ||
// @returns true if iteration succeeded, false otherwise | ||
bool setOneSideSpeeds(struct singleMotorParam *params, int array_length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeśli już to:
bool setOneSideSpeeds(struct singleMotorParam *params, int array_length); | |
bool MotorInterface_setOneSideSpeeds(struct singleMotorParam *params, int array_length); |
#include "pwm.h" | ||
#include "timers.h" | ||
|
||
TIM_HandleTypeDef hPwm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatowanie
working pid