Skip to content

Commit

Permalink
Merge pull request #25 from arduino-libraries/devel
Browse files Browse the repository at this point in the history
1.1.0 - major update
  • Loading branch information
gbr1 authored Oct 16, 2024
2 parents 1dc4029 + 430f130 commit 28fb1d2
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 131 deletions.
219 changes: 121 additions & 98 deletions examples/firmware/firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -96,104 +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);
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);
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);
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 All @@ -207,6 +216,9 @@ void loop(){
case 1:
alvik.setBehaviour(LIFT_ILLUMINATOR, true);
break;
case 2:
alvik.setBehaviour(BATTERY_ALERT, true);
break;
default:
alvik.setBehaviour(ALL_BEHAVIOURS, false);
}
Expand All @@ -227,6 +239,8 @@ void loop(){
alvik.updateTouch();
msg_size = packeter.packetC1B('t', alvik.getTouchKeys());
alvik.serial->write(packeter.msg,msg_size);
msg_size = packeter.packetC1B('m', alvik.getMotion());
alvik.serial->write(packeter.msg,msg_size);
break;
case 2:
alvik.updateAPDS();
Expand Down Expand Up @@ -278,13 +292,22 @@ void loop(){
msg_size = packeter.packetC3B(0x7E, version[0], version[1], version[2]);
alvik.serial->write(packeter.msg,msg_size);
}
if (ack_check && alvik.isTargetReached()){
if (ack_check && (alvik.isTargetReached() || alvik.isPositionReached() || alvik.isPositionLeftReached() || alvik.isPositionRightReached())){
if (ack_required == MOVEMENT_ROTATE){
msg_size = packeter.packetC1B('x', 'R');
}
if (ack_required == MOVEMENT_MOVE){
msg_size = packeter.packetC1B('x', 'M');
}
if (ack_required == MOVEMENT_POSITION){
msg_size = packeter.packetC1B('x', 'P');
}
if (ack_required == MOVEMENT_LEFT){
msg_size = packeter.packetC1B('x', 'P');
}
if (ack_required == MOVEMENT_RIGHT){
msg_size = packeter.packetC1B('x', 'P');
}
}
else{
msg_size = packeter.packetC1B('x', 0);
Expand All @@ -309,7 +332,7 @@ void loop(){
if (millis()-tbattery>1000){
tbattery = millis();
alvik.updateBMS();
msg_size = packeter.packetC1F('p', alvik.getBatteryChargePercentage());
msg_size = packeter.packetC1F('p', alvik.isBatteryCharging()*alvik.getBatteryChargePercentage());
alvik.serial->write(packeter.msg,msg_size);
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Arduino_AlvikCarrier
version=1.0.1
version=1.1.0
author=Arduino, Giovanni di Dio Bruno, Lucio Rossi
maintainer=Arduino <[email protected]>
sentence=Library and firmware for Arduino Alvik Carrier board
Expand Down
Loading

0 comments on commit 28fb1d2

Please sign in to comment.