Skip to content

Commit

Permalink
Change Hbridge so it now receives a [1,-1] speed range, changed contr…
Browse files Browse the repository at this point in the history
…ollers gains accordingly

Fix robotadasufsc#11

Signed-off-by: Willian Galvani <williangalvani@gmail.com>
  • Loading branch information
Williangalvani committed Jun 25, 2016
1 parent cbe2253 commit 55e9b90
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Firmware/ControladorRobo/ControladorRobo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ISR(TIMER1_COMPA_vect)
float u_dir = controle_dir.update(refDir, rightAngularSpeed);

HBridge* bridge = &HBridge::self();
bridge->setWheelPWM(bridge->LEFT,(int)floor(u_esq*51));
bridge->setWheelPWM(bridge->RIGHT,(int)floor(u_dir*51));
bridge->setWheelPWM(bridge->LEFT,u_esq);
bridge->setWheelPWM(bridge->RIGHT,u_dir);

}
8 changes: 4 additions & 4 deletions Firmware/ControladorRobo/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

#include <Arduino.h>

#define kc_dir 5.0
#define kc_dir 1.0
#define ti_dir 0.2
#define td_dir 0

#define kc_esq 5.0
#define kc_esq 1.0
#define ti_esq 0.2
#define td_esq 0

#define Ts 0.02
#define umin -5.0
#define umax 5.0
#define umin -1.0
#define umax 1.0

//Modelo Esquerdo
//float kpesq = (4.86*(500/255)), t1esq = (1.06/3), tetaesq = .02;
Expand Down
8 changes: 5 additions & 3 deletions Firmware/ControladorRobo/hbridge.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "hbridge.h"

#define sat(x, a, b) ( max( min (x, a), b ))

HBridge::HBridge()
{
Expand All @@ -25,8 +25,10 @@ HBridge& HBridge::self()
return self;
}

void HBridge::setWheelPWM(uint8_t wheel, int16_t speed)
void HBridge::setWheelPWM(uint8_t wheel, float speed)
{
speed = sat(speed,1,-1);
uint8_t PWM = (int) abs(speed)*255;
uint8_t pin_f; //forward pin
uint8_t pin_b; //backward pin
uint8_t pin_s; //signal pin
Expand Down Expand Up @@ -54,7 +56,7 @@ void HBridge::setWheelPWM(uint8_t wheel, int16_t speed)
digitalWrite(pin_f,LOW);
digitalWrite(pin_b,HIGH);
}
analogWrite(pin_s, abs(speed));
analogWrite(pin_s, PWM);
}

void HBridge::forward(int16_t vel)
Expand Down
2 changes: 1 addition & 1 deletion Firmware/ControladorRobo/hbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class HBridge
enum {LEFT, RIGHT};


void setWheelPWM(uint8_t wheel, int16_t speed);
void setWheelPWM(uint8_t wheel, float speed);
void forward(int16_t vel);
};

0 comments on commit 55e9b90

Please sign in to comment.