Skip to content

Commit

Permalink
battery alert
Browse files Browse the repository at this point in the history
  • Loading branch information
gbr1 committed Oct 9, 2024
1 parent bfb9cf7 commit 5a938c7
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 107 deletions.
207 changes: 105 additions & 102 deletions examples/firmware/firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -96,110 +96,113 @@ void loop(){
}
if (packeter.checkPayload()) {
code = packeter.payloadTop();
switch (code){
case 'J':
packeter.unpacketC2F(code,left,right);
alvik.disableKinematicsMovement();
alvik.disablePositionControl();
alvik.setRpm(left, right);
break;

case 'V':
packeter.unpacketC2F(code,linear,angular);
alvik.disableKinematicsMovement();
alvik.disablePositionControl();
alvik.drive(linear,angular);
break;

case 'W':
packeter.unpacketC2B1F(code,label,control_type,value);
alvik.disableKinematicsMovement();
if (label=='L'){
switch (control_type){
case 'V':
alvik.disablePositionControlLeft();
alvik.setRpmLeft(value);
break;
case 'P':
alvik.setPositionLeft(value);
ack_required=MOVEMENT_LEFT;
ack_check=true;
break;
case 'Z':
alvik.resetPositionLeft(value);
break;
if (!alvik.isBatteryAlert()){
switch (code){
case 'J':
packeter.unpacketC2F(code,left,right);
alvik.disableKinematicsMovement();
alvik.disablePositionControl();
alvik.setRpm(left, right);
break;

case 'V':
packeter.unpacketC2F(code,linear,angular);
alvik.disableKinematicsMovement();
alvik.disablePositionControl();
alvik.drive(linear,angular);
break;

case 'W':
packeter.unpacketC2B1F(code,label,control_type,value);
alvik.disableKinematicsMovement();
if (label=='L'){
switch (control_type){
case 'V':
alvik.disablePositionControlLeft();
alvik.setRpmLeft(value);
break;
case 'P':
alvik.setPositionLeft(value);
ack_required=MOVEMENT_LEFT;
ack_check=true;
break;
case 'Z':
alvik.resetPositionLeft(value);
break;
}
}
}
if (label=='R'){
switch (control_type){
case 'V':
alvik.disablePositionControlRight();
alvik.setRpmRight(value);
break;
case 'P':
alvik.setPositionRight(value);
ack_required=MOVEMENT_RIGHT;
ack_check=true;
break;
case 'Z':
alvik.resetPositionRight(value);
break;
if (label=='R'){
switch (control_type){
case 'V':
alvik.disablePositionControlRight();
alvik.setRpmRight(value);
break;
case 'P':
alvik.setPositionRight(value);
ack_required=MOVEMENT_RIGHT;
ack_check=true;
break;
case 'Z':
alvik.resetPositionRight(value);
break;
}
}
}
break;


case 'A':
packeter.unpacketC2F(code,position_left, position_right);
alvik.disableKinematicsMovement();
alvik.setPosition(position_left, position_right);
ack_required=MOVEMENT_POSITION;
ack_check=true;
break;


case 'S':
packeter.unpacketC2B(code,servo_A,servo_B);
alvik.setServoA(servo_A);
alvik.setServoB(servo_B);
break;

case 'L':
packeter.unpacketC1B(code,leds);
alvik.setAllLeds(leds);
break;

case 'P':
packeter.unpacketC1B3F(code,pid,kp,ki,kd);
if (pid=='L'){
alvik.setKPidLeft(kp,ki,kd);
}
if (pid=='R'){
alvik.setKPidRight(kp,ki,kd);
}
break;

case 'R':
packeter.unpacketC1F(code, value);
alvik.disablePositionControl();
alvik.rotate(value);
ack_required=MOVEMENT_ROTATE;
ack_check=true;
break;

case 'G':
packeter.unpacketC1F(code, value);
alvik.disablePositionControl();
alvik.move(value);
ack_required=MOVEMENT_MOVE;
ack_check=true;
break;

case 'Z':
packeter.unpacketC3F(code, x, y, theta);
alvik.resetPose(x, y, theta);
break;

break;


case 'A':
packeter.unpacketC2F(code,position_left, position_right);
alvik.disableKinematicsMovement();
alvik.setPosition(position_left, position_right);
ack_required=MOVEMENT_POSITION;
ack_check=true;
break;


case 'S':
packeter.unpacketC2B(code,servo_A,servo_B);
alvik.setServoA(servo_A);
alvik.setServoB(servo_B);
break;

case 'L':
packeter.unpacketC1B(code,leds);
alvik.setAllLeds(leds);
break;

case 'P':
packeter.unpacketC1B3F(code,pid,kp,ki,kd);
if (pid=='L'){
alvik.setKPidLeft(kp,ki,kd);
}
if (pid=='R'){
alvik.setKPidRight(kp,ki,kd);
}
break;

case 'R':
packeter.unpacketC1F(code, value);
alvik.disablePositionControl();
alvik.rotate(value);
ack_required=MOVEMENT_ROTATE;
ack_check=true;
break;

case 'G':
packeter.unpacketC1F(code, value);
alvik.disablePositionControl();
alvik.move(value);
ack_required=MOVEMENT_MOVE;
ack_check=true;
break;

case 'Z':
packeter.unpacketC3F(code, x, y, theta);
alvik.resetPose(x, y, theta);
break;
}
}
switch (code){
case 'X':
packeter.unpacketC1B(code, ack_code);
if (ack_code == 'K') {
Expand Down
19 changes: 16 additions & 3 deletions src/Arduino_AlvikCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ float Arduino_AlvikCarrier::isBatteryCharging(){
return charging;
}

bool Arduino_AlvikCarrier::isBatteryAlert(){
return battery_alert;
}



/******************************************************************************************************/
Expand Down Expand Up @@ -982,6 +986,7 @@ void Arduino_AlvikCarrier::beginBehaviours(){
first_lift = true;
battery_alert_time = millis();
battery_alert_wave = 100;
battery_alert = false;
}


Expand All @@ -1007,7 +1012,7 @@ void Arduino_AlvikCarrier::updateBehaviours(){

// battery alert
if ((1<<(BATTERY_ALERT-1)) & behaviours){
if (getBatteryVoltage()<BATTERY_ALERT_MINIMUM_VOLTAGE){
if ((isBatteryCharging()==-1)&&(getBatteryChargePercentage()<BATTERY_ALERT_MINIMUM_CHARGE)){
if (millis()-battery_alert_time>battery_alert_wave){
battery_alert_time = millis();
if (battery_alert_wave==400){
Expand All @@ -1018,11 +1023,19 @@ void Arduino_AlvikCarrier::updateBehaviours(){
setLeds(COLOR_BLACK);
battery_alert_wave=400;
}
}
if (getBatteryChargePercentage()<BATTERY_ALERT_STOP_CHARGE){
battery_alert = true;
setRpm(0,0);
motor_left->stop();
motor_right->stop();
setIlluminator(false);
}
}
else{
battery_alert = false;
}
}
else{
battery_alert = false;
}

}
Expand Down
3 changes: 2 additions & 1 deletion src/Arduino_AlvikCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Arduino_AlvikCarrier{
bool first_lift;
unsigned long battery_alert_time;
unsigned long battery_alert_wave;
bool battery_alert;



Expand Down Expand Up @@ -159,6 +160,7 @@ class Arduino_AlvikCarrier{
float getBatteryVoltage(); // get Voltage
float getBatteryChargePercentage(); // get battery percentage
float isBatteryCharging(); // return -1 if battery discharge or 1 if charging
bool isBatteryAlert(); // return true if battery is LOW and alert behaviour is setted, otherwise false



Expand Down Expand Up @@ -190,7 +192,6 @@ class Arduino_AlvikCarrier{




// Touch
int beginTouch(); // initialize touch
void updateTouch(); // update touch status
Expand Down
3 changes: 2 additions & 1 deletion src/definitions/robot_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ const float MOTION_FX_PERIOD = (1000U / MOTION_FX_FREQ);
#define VERSION_BYTE_LOW 3

// Battery stats
#define BATTERY_ALERT_MINIMUM_VOLTAGE 4.0
#define BATTERY_ALERT_MINIMUM_CHARGE 96.0
#define BATTERY_ALERT_STOP_CHARGE 94.0



Expand Down

0 comments on commit 5a938c7

Please sign in to comment.