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

English translation and comments corrections #26

Merged
merged 4 commits into from
Aug 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions Firmware/ControladorRobo/ControladorRobo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ char debug_buffer[128];
#define freq 50.0
#define actFreq 20

//variaveis para controle de velocidade
// variables for velocity control
float refDir = 0.0;
float refEsq = 0.0;
float basespeed = 0.3;

// posicao angular de cada roda, com provavel perda de resolucao depois de algum tempo.
// será usada para controle de posicao do robô (girar 90º, por exemplo)
// angular position of each wheel, with loss of resolution after some time
// will be used to know robot position
float leftAngPos = 0;
float rightAngPos = 0;

Expand All @@ -42,7 +42,7 @@ Controller directionController = Controller(0.1, 0, 0, 1/actFreq);

void peripheralsSetup()
{
// Seta os pinos de chave como entrada em pull-up
// Sets switch pins to PULLUP mode
pinMode(SWITCH1, INPUT_PULLUP);
pinMode(SWITCH2, INPUT_PULLUP);
Serial.begin(115200);
Expand Down Expand Up @@ -93,14 +93,10 @@ void loop()
basespeed *= 1.001;
}

///////////////////////////////////////////////////////////funcoes//////////////////////////////////////////////////////////////////////////////


// interrupcao para TIMER1, periodo de amostragem para controle de velocidade
// TIMER1 interruption, sample time for velocity control
ISR(TIMER1_COMPA_vect)
{
// Calculo das velocidades dos motores

// encoder ticks to angular velocity
float rightAngularDelta = ((float)right.read()/ENCODER_RESOLUTION)*M_PI;
float leftAngularDelta = ((float)left.read()/ENCODER_RESOLUTION)*M_PI;

Expand Down
16 changes: 8 additions & 8 deletions Firmware/ControladorRobo/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

void controllersSetup()
{
//Interrupcao do TIMER1, aka periodo de amostragem para calculo do controle de velocidade
// TIMER1 interruption, sample time for velocity control
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
Expand Down Expand Up @@ -32,21 +32,21 @@ Controller::~Controller()
{
}

float Controller::update(float setpoint, float current_value)
/* Returns control output */
float Controller::update(float setpoint, float current_value)
{
float erro,up,ui,ud, u_total, u_sat;
erro = setpoint - current_value;
up = kc*erro; //termo proporcional
ui = ui_k1 + ((kc*ts)/ti)*erro_k1; //termo integral
ud = ((kc*td)/ts)*(erro - erro_k1); //termo derivativo
ui= ui + (taw)*eaw_k1; //termo anti windup
up = kc*erro; // proporcional
ui = ui_k1 + ((kc*ts)/ti)*erro_k1; // integral
ud = ((kc*td)/ts)*(erro - erro_k1); // derivative
ui = ui + (taw)*eaw_k1; // anti windup

u_total = up + ui + ud;

u_sat = min(umax,max(u_total,umin)); //saturação
u_sat = min(umax, max(u_total, umin)); // saturation

eaw_k1 = u_sat - u_total; // erro de saturação
eaw_k1 = u_sat - u_total; // saturation error

erro_k1 = erro;
ui_k1 = ui;
Expand Down
4 changes: 2 additions & 2 deletions Firmware/ControladorRobo/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#define umin -1.0
#define umax 1.0

//Modelo Esquerdo
// Right model
Copy link
Contributor

@Williangalvani Williangalvani Aug 5, 2016

Choose a reason for hiding this comment

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

Right model is kind of vague. This is actually a linear approximation of the system motor + wheel using a "first-order plus deadtime" (FOPDT) transfer function, where t1 is the time constant, theta is the delay, and kp is the gain.

Copy link
Member Author

Choose a reason for hiding this comment

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

// Linear approximation of motor-wheel system with a first-order equation
what you think ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Its good, a better explanation should be given when fixing issue #21

//float kpesq = (4.86*(500/255)), t1esq = (1.06/3), tetaesq = .02;

//Modelo Direito
// Left model
//float kpdir = (5.15*(500/255)), t1dir = (0.8/3), tetadir = .02;
void controllersSetup();

Expand Down
8 changes: 4 additions & 4 deletions Firmware/ControladorRobo/hbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HBridge::HBridge()
pinMode(RIGHT_WHEEL_BACKWARD_PIN, OUTPUT);
pinMode(RIGHT_WHEEL_SPEED_PIN, OUTPUT);

//inicia com motores desligados
// start with motors off
digitalWrite(LEFT_WHEEL_FORWARD_PIN,LOW);
digitalWrite(LEFT_WHEEL_BACKWARD_PIN,LOW);
digitalWrite(RIGHT_WHEEL_FORWARD_PIN,LOW);
Expand All @@ -29,9 +29,9 @@ void HBridge::setWheelPWM(uint8_t wheel, float speed)
{
speed = sat(speed,1,-1);
uint8_t PWM = (uint8_t)(float)(abs(speed)*255.0);
uint8_t pin_f; //forward pin
uint8_t pin_b; //backward pin
uint8_t pin_s; //signal pin
uint8_t pin_f; // forward pin
uint8_t pin_b; // backward pin
uint8_t pin_s; // signal pin
switch (wheel)
{
case LEFT:
Expand Down
2 changes: 1 addition & 1 deletion Firmware/ControladorRobo/irarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void IRArray::saveCalibrationToEEPROM()
}
}

// le os valores do branco da eeprom
// read values from eeprom
void IRArray::loadCalibrationFromEEPROM()
{
for (uint16_t i = CALLIB_ADDRESS; i<CALLIB_ADDRESS + NUMBER_OF_SENSORS; i++)
Expand Down
6 changes: 3 additions & 3 deletions Firmware/ControladorRobo/irarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <Arduino.h>

// Passar parte da eeprom para um outra classe
// TODO: create eeprom class
// eeprom address for the sensors
#define CALLIB_ADDRESS 0

Expand All @@ -21,15 +21,15 @@ class IRArray
void saveCalibrationToEEPROM();
void loadCalibrationFromEEPROM();

// pinos para leitura analógica
// pins for analog read
static uint16_t m_sensorPin[NUMBER_OF_SENSORS];
uint8_t m_sensorLow[NUMBER_OF_SENSORS];
uint8_t m_sensorHigh[NUMBER_OF_SENSORS];
byte m_enablePin;
uint16_t m_sensorRaw[NUMBER_OF_SENSORS];
uint16_t m_sensor[NUMBER_OF_SENSORS];

// le os sensores e salva o valor lido de cada um no byte[9]
// run calibration routine
bool m_calibrating;

public:
Expand Down