Skip to content
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

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft

New pid #11

wants to merge 29 commits into from

Conversation

Czechos02
Copy link
Collaborator

working pid

Comment on lines 63 to 90
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);
}
}
Copy link
Collaborator

@jprokopczuk jprokopczuk Feb 19, 2023

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.

Comment on lines +46 to +52
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;
Copy link
Collaborator

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) {
Copy link
Collaborator

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (i = 0; i < array_length; i += 1) {
for (i = 0; i < array_length; i ++) {

Comment on lines 60 to 65
// 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)
Copy link
Collaborator

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)
Copy link
Collaborator

@jprokopczuk jprokopczuk Feb 19, 2023

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?

PWM_SetDutyCycle(CHANNEL1, 750+*(float*)PID_map[i].ptr);
}
if(params[i].id == LM || params[i].id == RM){
old_duty = hPwm.Instance->CCR2;
Copy link
Collaborator

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);
Copy link
Collaborator

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
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeśli już to:

Suggested change
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatowanie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants