Skip to content

0.4.0 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# Arduino_Alvik
Arduino Alvik library, code with your Alvik
Arduino Alvik library, code your Alvik

<br>

To use this library, you need an [Arduino® Alvik](https://store.arduino.cc/pages/alvik) robot.

Once the Arduino® Nano ESP32 of the robot is attached to the computer, select `Arduino Nano ESP32` from Arduino IDE 2 to program it.

<br>

## Color Calibration

Flash `color_calibration` sketch into Arduino Nano ESP32 mounted on Alvik and follow the instructions on serial monitor.

The white and black values will be written into ESP32 EEPROM.

<br>

## How to update firmware of Arduino Alvik Carrier

Since this [issue](https://github.com/stm32duino/Arduino_Core_STM32/issues/2292), Arduino® Alvik Carrier is not integrated yet into STM32duino's boards.

<br>

At the moment, it is possible to:
- flash `bridge_firmware_updater` example into Arduino Nano ESP32 mounted on Alvik
- use [STM32CubeProgrammer](https://www.st.com/en/development-tools/stm32cubeprog.html) to flash the new firmware.

<br>


In particular these settings are needed:
- UART communication with DTR setted to 1 in STM32CubeProgrammer
- robot must be turned on.


## Useful links

- [arduino-alvik-mpy](https://github.com/arduino/arduino-alvik-mpy), micropython version of the library
- [Arduino_AlvikCarrier](https://github.com/arduino-libraries/Arduino_AlvikCarrier), arduino library required to build the firmware

4 changes: 1 addition & 3 deletions examples/bridge_firmware_updater/bridge_firmware_updater
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
This allows to flash firmware into the Arduino Alvik Carrier via Arduino Nano ESP32.

Please refer to Arduino_AlvikCarrier library available at https://github.com/arduino-libraries/Arduino_AlvikCarrier

*/


Expand Down Expand Up @@ -60,9 +61,6 @@ void setup() {
digitalWrite(RESET_STM32,LOW);
delay(1000);
digitalWrite(RESET_STM32,HIGH);



}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Arduino_Alvik
version=0.3.0
version=0.4.0
author=Arduino, Giovanni di Dio Bruno, Lucio Rossi
maintainer=Arduino <[email protected]>
sentence=Library to code Arduino Alvik robot
Expand Down
46 changes: 38 additions & 8 deletions src/Arduino_Alvik.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void Arduino_Alvik::reset_hw(){
}

void Arduino_Alvik::wait_for_ack(){
waiting_ack = 0x00;
while(last_ack != 0x00){
delay(20);
}
Expand All @@ -57,6 +58,7 @@ int Arduino_Alvik::begin(const bool verbose, const uint8_t core){
verbose_output = verbose;

last_ack = 0;
waiting_ack = NO_ACK;

version[0] = 0;
version[1] = 0;
Expand Down Expand Up @@ -130,9 +132,8 @@ int Arduino_Alvik::begin(const bool verbose, const uint8_t core){


uart->begin(UART_BAUD_RATE);
uart->flush();


pinMode(CHECK_STM32, INPUT_PULLDOWN);
pinMode(RESET_STM32, OUTPUT);
pinMode(NANO_CHK, OUTPUT);
Expand All @@ -149,6 +150,11 @@ int Arduino_Alvik::begin(const bool verbose, const uint8_t core){
delay(100);
reset_hw();

uart->flush();
while (uart->available()){
uart->read();
}

wait_for_ack();

set_illuminator(true);
Expand Down Expand Up @@ -238,7 +244,12 @@ int Arduino_Alvik::parse_message(){
switch(code){
// get ack code
case 'x':
packeter->unpacketC1B(code, last_ack);
if (waiting_ack == NO_ACK){
packeter->unpacketC1B(code, last_ack);
last_ack = 0x00;
} else {
packeter->unpacketC1B(code, last_ack);
}
break;


Expand Down Expand Up @@ -406,35 +417,54 @@ void Arduino_Alvik::reset_pose(const float x, const float y, const float theta,
}

bool Arduino_Alvik::is_target_reached(){
if ((last_ack != 'M') && (last_ack != 'R')){

if (waiting_ack == NO_ACK){
return true;
}

if (last_ack != waiting_ack){
delay(50);
return false;
}
msg_size = packeter->packetC1B('X', 'K');
uart->write(packeter->msg, msg_size);
waiting_ack = NO_ACK;
last_ack = 0x00;
delay(200);
return true;
}

void Arduino_Alvik::wait_for_target(){ //it is private
while (!is_target_reached()){}
void Arduino_Alvik::wait_for_target(const int idle_time){ //it is private
unsigned long start_t = millis();

while (true){
if (((millis() - start_t) >= idle_time*1000) && is_target_reached()) {
break;
} else
{
delay(100);
}

}
}

void Arduino_Alvik::rotate(const float angle, const uint8_t unit, const bool blocking){
delay(200);
msg_size = packeter->packetC1F('R', convert_angle(angle, unit, DEG));
uart->write(packeter->msg, msg_size);
waiting_ack = 'R';
if (blocking){
wait_for_target();
wait_for_target(round(angle/MOTOR_CONTROL_DEG_S));
}
}

void Arduino_Alvik::move(const float distance, const uint8_t unit, const bool blocking){
delay(200);
msg_size = packeter->packetC1F('G', convert_distance(distance, unit, MM));
uart->write(packeter->msg, msg_size);
waiting_ack = 'M';
if (blocking){
wait_for_target();
wait_for_target(round(distance/MOTOR_CONTROL_MM_S));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Arduino_Alvik.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Arduino_Alvik{
uint8_t msg_size;

uint8_t last_ack;
uint8_t waiting_ack;

float converted_angular;

Expand Down Expand Up @@ -96,7 +97,7 @@ class Arduino_Alvik{

void get_touch(); // service function to parse touch
void set_leds(); // service function to set leds by a byte
void wait_for_target(); // service function that wait for ack
void wait_for_target(const int idle_time); // service function that wait for ack

float limit(float value, const float min, const float max); // limit a value
float normalize(float value, const float min, const float max); // normalize a value
Expand Down
15 changes: 8 additions & 7 deletions src/default_colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

#include "Arduino.h"

#define WHITE_DEFAULT_RED 444
#define WHITE_DEFAULT_GREEN 342
#define WHITE_DEFAULT_BLUE 345
#define BLACK_DEFAULT_RED 153
#define BLACK_DEFAULT_GREEN 135
#define BLACK_DEFAULT_BLUE 123
#define WHITE_DEFAULT_RED 450
#define WHITE_DEFAULT_GREEN 500
#define WHITE_DEFAULT_BLUE 510
#define BLACK_DEFAULT_RED 160
#define BLACK_DEFAULT_GREEN 200
#define BLACK_DEFAULT_BLUE 190
//int16_t WHITE_CAL[3] = {444, 342, 345};
//int16_t BLACK_CAL[3] = {153, 135, 123};


#define WHITE_OFFSET 0
#define BLACK_OFFSET 6
#define COLOR_SIZE 20
Expand All @@ -41,7 +42,7 @@
#define LIGHT_GREEN_MAX 140
#define GREEN_MAX 170
#define LIGHT_BLUE_MAX 210
#define BLUE_MAX 260
#define BLUE_MAX 250
#define VIOLET_MAX 280
#define BROWN_MAX_VALUE 0.5
#define BROWN_MAX_SATURATION 0.45
Expand Down
8 changes: 7 additions & 1 deletion src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@
#define UART 0
#define UART_BAUD_RATE 460800

#define DL1 left_led
#define DL2 right_led

#define CHARGE_THRESHOLD 97

#define NO_ACK 0xFF

const float WHEEL_DIAMETER_MM = 34.0;
const float WHEEL_TRACK_MM = 89.0;
const float MOTOR_MAX_RPM = 70.0;
const float ROBOT_MAX_DEG_S = 6*(2*MOTOR_MAX_RPM*WHEEL_DIAMETER_MM)/WHEEL_TRACK_MM;

const float MOTOR_CONTROL_MM_S = 100.0;
const float MOTOR_CONTROL_DEG_S = 100.0;

// unit conversion constants

Expand Down