Skip to content

Commit

Permalink
Merge pull request #10 from arduino-libraries/devel
Browse files Browse the repository at this point in the history
0.3.4
  • Loading branch information
gbr1 authored Mar 1, 2024
2 parents 2b62bdc + afc8518 commit 457f2b1
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/blink/blink.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void setup(){

void loop(){
alvik.setLedBuiltin(HIGH);
delay(100);
delay(1000);
alvik.setLedBuiltin(LOW);
delay(1000);
}
13 changes: 13 additions & 0 deletions examples/firmware/firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ unsigned long tsensor = 0;
unsigned long timu = 0;
unsigned long tack = 0;
unsigned long tbehaviours = 0;
unsigned long tbattery = 0;


float left, right, value;
Expand Down Expand Up @@ -73,6 +74,10 @@ void setup(){
msg_size = packeter.packetC3B(0x7E, version[0], version[1], version[2]);
alvik.serial->write(packeter.msg,msg_size);

alvik.updateBMS();
msg_size = packeter.packetC1F('p', alvik.getBatteryChargePercentage());
alvik.serial->write(packeter.msg,msg_size);

alvik.setLedBuiltin(LOW);
alvik.setLeds(COLOR_BLACK);

Expand Down Expand Up @@ -300,4 +305,12 @@ void loop(){
msg_size = packeter.packetC6F('i', alvik.getAccelerationX(), alvik.getAccelerationY(), alvik.getAccelerationZ(), alvik.getAngularVelocityX(), alvik.getAngularVelocityY(), alvik.getAngularVelocityZ());
alvik.serial->write(packeter.msg,msg_size);
}

// battery update
if (millis()-tbattery>1000){
tbattery = millis();
alvik.updateBMS();
msg_size = packeter.packetC1F('p', 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=0.3.0
version=0.3.4
author=Arduino, Giovanni di Dio Bruno, Lucio Rossi
maintainer=Arduino <[email protected]>
sentence=Library and firmware for Arduino Alvik Carrier board
Expand Down
77 changes: 67 additions & 10 deletions src/Arduino_AlvikCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Arduino_AlvikCarrier::Arduino_AlvikCarrier(){

int Arduino_AlvikCarrier::begin(){
beginLeds();
pinMode(NANO_CHK,INPUT_PULLDOWN);

serial->begin(UART_BAUD);
serial->flush();
Expand Down Expand Up @@ -254,6 +255,7 @@ void Arduino_AlvikCarrier::disconnectExternalI2C(){
/******************************************************************************************************/

int Arduino_AlvikCarrier::beginBMS(){
while(digitalRead(NANO_CHK)==HIGH){}
bms->begin();
return 0;
}
Expand Down Expand Up @@ -432,17 +434,55 @@ bool Arduino_AlvikCarrier::getTouchKey(const uint8_t key){
return false;
}

uint8_t Arduino_AlvikCarrier::getTouchKeys(){
uint8_t Arduino_AlvikCarrier::getTouchKeys(const bool single_touch){
touch_value=0;
if (getAnyTouchPressed()){
touch_value|=1;
touch_value|=getTouchOk()<<1;
touch_value|=getTouchDelete()<<2;
touch_value|=getTouchCenter()<<3;
touch_value|=getTouchUp()<<4;
touch_value|=getTouchLeft()<<5;
touch_value|=getTouchDown()<<6;
touch_value|=getTouchRight()<<7;
if (!single_touch){
touch_value|=getTouchOk()<<1;
touch_value|=getTouchDelete()<<2;
touch_value|=getTouchCenter()<<3;
touch_value|=getTouchUp()<<4;
touch_value|=getTouchLeft()<<5;
touch_value|=getTouchDown()<<6;
touch_value|=getTouchRight()<<7;
}
else{
if (getTouchOk()){
touch_value|=1<<1;
}else{
if (getTouchDelete()){
touch_value|=1<<2;
}
else{
if (getTouchCenter()){
touch_value|=1<<3;
}
else{
if (getTouchLeft()){
touch_value|=1<<5;
}
else{
if (getTouchDown()){
touch_value|=1<<6;
}
else{
if (getTouchRight()){
touch_value|=1<<7;
}
else{
if (getTouchUp()){
touch_value|=1<<4;
}
}
}

}
}
}
}
}

}
return touch_value;
}
Expand Down Expand Up @@ -693,7 +733,7 @@ void Arduino_AlvikCarrier::updateKinematics(){
if (kinematics_movement==MOVEMENT_ROTATE){
rotate_pid->update(kinematics->getTheta());
drive(0, round(rotate_pid->getControlOutput()/10.0)*10);
if (abs(rotate_pid->getError())<ROTATE_THREASHOLD){
if (abs(rotate_pid->getError())<ROTATE_THRESHOLD){
kinematics_achieved=true;
disableKinematicsMovement();
drive(0,0);
Expand All @@ -702,7 +742,7 @@ void Arduino_AlvikCarrier::updateKinematics(){
if (kinematics_movement==MOVEMENT_MOVE){
move_pid->update((kinematics->getTravel()-previous_travel)*move_direction);
drive(round(move_pid->getControlOutput()/10.0)*10, 0);
if (abs(move_pid->getError())<MOVE_THREADSHOLD){
if (abs(move_pid->getError())<MOVE_THRESHOLD){
kinematics_achieved=true;
disableKinematicsMovement();
drive(0,0);
Expand Down Expand Up @@ -892,4 +932,21 @@ bool Arduino_AlvikCarrier::isLifted(){
else{
return false;
}
}



/******************************************************************************************************/
/* Utilities */
/******************************************************************************************************/

void Arduino_AlvikCarrier::getSerialNumber(char * sn){
uint32_t id[3];
id[0] = HAL_GetUIDw0();
id[1] = HAL_GetUIDw1();
id[2] = HAL_GetUIDw2();
uint32_t top = id[0]+id[2];
uint16_t bottom = (id[1]&0xFFFF0000)>>16;
sprintf(sn,"%08lx", top);
sprintf(sn+8,"%x",bottom);
}
17 changes: 12 additions & 5 deletions src/Arduino_AlvikCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Arduino_AlvikCarrier{
void updateTouch(); // update touch status
bool getAnyTouchPressed(); // get any touch pressed
bool getTouchKey(const uint8_t key); // return true if key touch is pressed
uint8_t getTouchKeys(); // return touched pads as byte
uint8_t getTouchKeys(const bool single_touch = true); // return touched pads as byte
bool getTouchUp(); // get nav pad up
bool getTouchRight(); // get nav pad right
bool getTouchDown(); // get nav pad down
Expand Down Expand Up @@ -245,10 +245,17 @@ class Arduino_AlvikCarrier{
bool isTargetReached(); // get true if a movement is accomplished
uint8_t getKinematicsMovement(); // get which kind of motion is running in kinematic control

void beginBehaviours();
void updateBehaviours();
void setBehaviour(const uint8_t behaviour, const bool enable);
bool isLifted();

// Behaviours
void beginBehaviours(); // internal behaviours of the robot
void updateBehaviours(); // updated internal behaviours
void setBehaviour(const uint8_t behaviour, const bool enable); // set a behaviour
bool isLifted(); // is robot lifted?


// Utilities
void getSerialNumber(char * sn); // get STM32 serial number

};

#endif
2 changes: 2 additions & 0 deletions src/definitions/pinout_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
#define I2C_2_SCL PB10
#define ARDUINO_ROBOT_ADDRESS 0x2B

// Check
#define NANO_CHK PC0

// Touch
#define TOUCH_PAD_UP 7
Expand Down
8 changes: 4 additions & 4 deletions src/definitions/robot_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ const float MOTOR_RATIO = MOTOR_CPR*MOTOR_GEAR_RATIO;
#define ROTATE_KD_DEFAULT 0.001
#define ROTATE_CONTROL_PERIOD 0.02
#define ROTATE_MAX_SPEED 45.0
#define ROTATE_THREASHOLD 1
#define ROTATE_THRESHOLD 1

#define MOVE_KP_DEFAULT 5.0
#define MOVE_KI_DEFAULT 0.0
#define MOVE_KD_DEFAULT 0.001
#define MOVE_CONTROL_PERIOD 0.02
#define MOVE_MAX_SPEED 45.0
#define MOVE_THREADSHOLD 3
#define MOVE_THRESHOLD 3

#define MOVEMENT_DISABLED 0
#define MOVEMENT_ROTATE 1
Expand Down Expand Up @@ -87,8 +87,8 @@ const float MOTION_FX_PERIOD = (1000U / MOTION_FX_FREQ);

// Library version
#define VERSION_BYTE_HIGH 0
#define VERSION_BYTE_MID 2
#define VERSION_BYTE_LOW 1
#define VERSION_BYTE_MID 3
#define VERSION_BYTE_LOW 4



Expand Down

0 comments on commit 457f2b1

Please sign in to comment.