Skip to content

Commit

Permalink
#2 Now charging of main accumulator starts when power source is plugg…
Browse files Browse the repository at this point in the history
…ed in. And it stops when power source is off.
  • Loading branch information
DmitryDzz committed Mar 18, 2014
1 parent 4dfe221 commit abac2b3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions robo_body/rm_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ namespace robot_mitya
static const float VOLTAGE_CHARGER_R1 = 7.5;
static const float VOLTAGE_CHARGER_R2 = 4.7;

static const float CHARGER_LISTENER_DELAY = 3000;
static const float CHARGER_MIN_VOLTAGE = 1000; // x 0.01 Volts (like in "=XXXX" and "~XXXX" messages)

// Instruction values.
static const int INSTRUCTION_HEADLIGHTS_OFF = 0x0000;
static const int INSTRUCTION_HEADLIGHTS_ON = 0x0001;
Expand Down
30 changes: 30 additions & 0 deletions robo_body/rm_equ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ static VoltageDivider* voltageDividerBattery = new VoltageDivider(Cfg::VOLTAGE_B
static VoltageDivider* voltageDividerCharger = new VoltageDivider(Cfg::VOLTAGE_CHARGER_DIVIDER_INDEX,
Cfg::VOLTAGE_CHARGER_PIN, Cfg::AREF_VOLTAGE, Cfg::VOLTAGE_CHARGER_R1, Cfg::VOLTAGE_CHARGER_R2);

// Voltage divider to identify charging process. Plugging in an external power source should start charging.
// When power source is plugged off the charging must be interrupted.
static VoltageDivider* chargerListener = new VoltageDivider(Cfg::VOLTAGE_CHARGER_DIVIDER_INDEX,
Cfg::VOLTAGE_CHARGER_PIN, Cfg::AREF_VOLTAGE, Cfg::VOLTAGE_CHARGER_R1, Cfg::VOLTAGE_CHARGER_R2);
static bool connectedToCharger = false;

void Equipment::initialize()
{
// Initializing headlights:
Expand Down Expand Up @@ -77,12 +83,16 @@ void Equipment::initialize()

// Initializing robot's state:
State::initialize();

connectedToCharger = false;
chargerListener->setTimer(Cfg::CHARGER_LISTENER_DELAY, chargerHandler);
}

void Equipment::refresh()
{
voltageDividerBattery->refresh();
voltageDividerCharger->refresh();
chargerListener->refresh();

Reflex::refresh();

Expand Down Expand Up @@ -357,3 +367,23 @@ void Equipment::buttonsHandler(ButtonState buttonState, Button button)
}
}

void Equipment::chargerHandler(int voltageDivider, unsigned int voltage)
{
if (voltage > Cfg::CHARGER_MIN_VOLTAGE)
{
if (!connectedToCharger)
{
executeInstruction(Cfg::INSTRUCTION_MAIN_ACCUMULATOR_CHARGE_ON);
connectedToCharger = true;
}
}
else
{
if (connectedToCharger)
{
executeInstruction(Cfg::INSTRUCTION_MAIN_ACCUMULATOR_CHARGE_OFF);
connectedToCharger = false;
}
}
}

1 change: 1 addition & 0 deletions robo_body/rm_equ.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace robot_mitya
static void setVoltageTimer(int dividerIndex, unsigned long timerDelay, void (*handler)(int, unsigned int));
private:
static void buttonsHandler(ButtonState buttonState, Button button);
static void chargerHandler(int voltageDivider, unsigned int voltage);
};
}

Expand Down

0 comments on commit abac2b3

Please sign in to comment.