Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2c83067

Browse files
authored
Merge pull request #3 from arduino-libraries/devel
0.4.0
2 parents 0a65c78 + 8087e19 commit 2c83067

File tree

7 files changed

+98
-22
lines changed

7 files changed

+98
-22
lines changed

‎README.md‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
11
# Arduino_Alvik
2-
Arduino Alvik library, code with your Alvik
2+
Arduino Alvik library, code your Alvik
3+
4+
<br>
5+
6+
To use this library, you need an [Arduino® Alvik](https://store.arduino.cc/pages/alvik) robot.
7+
8+
Once the Arduino® Nano ESP32 of the robot is attached to the computer, select `Arduino Nano ESP32` from Arduino IDE 2 to program it.
9+
10+
<br>
11+
12+
## Color Calibration
13+
14+
Flash `color_calibration` sketch into Arduino Nano ESP32 mounted on Alvik and follow the instructions on serial monitor.
15+
16+
The white and black values will be written into ESP32 EEPROM.
17+
18+
<br>
19+
20+
## How to update firmware of Arduino Alvik Carrier
21+
22+
Since this [issue](https://github.com/stm32duino/Arduino_Core_STM32/issues/2292), Arduino® Alvik Carrier is not integrated yet into STM32duino's boards.
23+
24+
<br>
25+
26+
At the moment, it is possible to:
27+
- flash `bridge_firmware_updater` example into Arduino Nano ESP32 mounted on Alvik
28+
- use [STM32CubeProgrammer](https://www.st.com/en/development-tools/stm32cubeprog.html) to flash the new firmware.
29+
30+
<br>
31+
32+
33+
In particular these settings are needed:
34+
- UART communication with DTR setted to 1 in STM32CubeProgrammer
35+
- robot must be turned on.
36+
37+
38+
## Useful links
39+
40+
- [arduino-alvik-mpy](https://github.com/arduino/arduino-alvik-mpy), micropython version of the library
41+
- [Arduino_AlvikCarrier](https://github.com/arduino-libraries/Arduino_AlvikCarrier), arduino library required to build the firmware
42+

‎examples/bridge_firmware_updater/bridge_firmware_updater‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
This allows to flash firmware into the Arduino Alvik Carrier via Arduino Nano ESP32.
1616

1717
Please refer to Arduino_AlvikCarrier library available at https://github.com/arduino-libraries/Arduino_AlvikCarrier
18+
1819
*/
1920

2021

@@ -60,9 +61,6 @@ void setup() {
6061
digitalWrite(RESET_STM32,LOW);
6162
delay(1000);
6263
digitalWrite(RESET_STM32,HIGH);
63-
64-
65-
6664
}
6765

6866
void loop() {

‎library.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Arduino_Alvik
2-
version=0.3.0
2+
version=0.4.0
33
author=Arduino, Giovanni di Dio Bruno, Lucio Rossi
44
maintainer=Arduino <info@arduino.cc>
55
sentence=Library to code Arduino Alvik robot

‎src/Arduino_Alvik.cpp‎

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void Arduino_Alvik::reset_hw(){
4545
}
4646

4747
void Arduino_Alvik::wait_for_ack(){
48+
waiting_ack = 0x00;
4849
while(last_ack != 0x00){
4950
delay(20);
5051
}
@@ -57,6 +58,7 @@ int Arduino_Alvik::begin(const bool verbose, const uint8_t core){
5758
verbose_output = verbose;
5859

5960
last_ack = 0;
61+
waiting_ack = NO_ACK;
6062

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

131133

132134
uart->begin(UART_BAUD_RATE);
133-
uart->flush();
134135

135-
136+
136137
pinMode(CHECK_STM32, INPUT_PULLDOWN);
137138
pinMode(RESET_STM32, OUTPUT);
138139
pinMode(NANO_CHK, OUTPUT);
@@ -149,6 +150,11 @@ int Arduino_Alvik::begin(const bool verbose, const uint8_t core){
149150
delay(100);
150151
reset_hw();
151152

153+
uart->flush();
154+
while (uart->available()){
155+
uart->read();
156+
}
157+
152158
wait_for_ack();
153159

154160
set_illuminator(true);
@@ -238,7 +244,12 @@ int Arduino_Alvik::parse_message(){
238244
switch(code){
239245
// get ack code
240246
case 'x':
241-
packeter->unpacketC1B(code, last_ack);
247+
if (waiting_ack == NO_ACK){
248+
packeter->unpacketC1B(code, last_ack);
249+
last_ack = 0x00;
250+
} else {
251+
packeter->unpacketC1B(code, last_ack);
252+
}
242253
break;
243254

244255

@@ -406,35 +417,54 @@ void Arduino_Alvik::reset_pose(const float x, const float y, const float theta,
406417
}
407418

408419
bool Arduino_Alvik::is_target_reached(){
409-
if ((last_ack != 'M') && (last_ack != 'R')){
420+
421+
if (waiting_ack == NO_ACK){
422+
return true;
423+
}
424+
425+
if (last_ack != waiting_ack){
410426
delay(50);
411427
return false;
412428
}
413429
msg_size = packeter->packetC1B('X', 'K');
414430
uart->write(packeter->msg, msg_size);
431+
waiting_ack = NO_ACK;
432+
last_ack = 0x00;
415433
delay(200);
416434
return true;
417435
}
418436

419-
void Arduino_Alvik::wait_for_target(){ //it is private
420-
while (!is_target_reached()){}
437+
void Arduino_Alvik::wait_for_target(const int idle_time){ //it is private
438+
unsigned long start_t = millis();
439+
440+
while (true){
441+
if (((millis() - start_t) >= idle_time*1000) && is_target_reached()) {
442+
break;
443+
} else
444+
{
445+
delay(100);
446+
}
447+
448+
}
421449
}
422450

423451
void Arduino_Alvik::rotate(const float angle, const uint8_t unit, const bool blocking){
424452
delay(200);
425453
msg_size = packeter->packetC1F('R', convert_angle(angle, unit, DEG));
426454
uart->write(packeter->msg, msg_size);
455+
waiting_ack = 'R';
427456
if (blocking){
428-
wait_for_target();
457+
wait_for_target(round(angle/MOTOR_CONTROL_DEG_S));
429458
}
430459
}
431460

432461
void Arduino_Alvik::move(const float distance, const uint8_t unit, const bool blocking){
433462
delay(200);
434463
msg_size = packeter->packetC1F('G', convert_distance(distance, unit, MM));
435464
uart->write(packeter->msg, msg_size);
465+
waiting_ack = 'M';
436466
if (blocking){
437-
wait_for_target();
467+
wait_for_target(round(distance/MOTOR_CONTROL_MM_S));
438468
}
439469
}
440470

‎src/Arduino_Alvik.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Arduino_Alvik{
3636
uint8_t msg_size;
3737

3838
uint8_t last_ack;
39+
uint8_t waiting_ack;
3940

4041
float converted_angular;
4142

@@ -96,7 +97,7 @@ class Arduino_Alvik{
9697

9798
void get_touch(); // service function to parse touch
9899
void set_leds(); // service function to set leds by a byte
99-
void wait_for_target(); // service function that wait for ack
100+
void wait_for_target(constint idle_time); // service function that wait for ack
100101

101102
float limit(float value, const float min, const float max); // limit a value
102103
float normalize(float value, const float min, const float max); // normalize a value

‎src/default_colors.h‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515

1616
#include "Arduino.h"
1717

18-
#define WHITE_DEFAULT_RED 444
19-
#define WHITE_DEFAULT_GREEN 342
20-
#define WHITE_DEFAULT_BLUE 345
21-
#define BLACK_DEFAULT_RED 153
22-
#define BLACK_DEFAULT_GREEN 135
23-
#define BLACK_DEFAULT_BLUE 123
18+
#define WHITE_DEFAULT_RED 450
19+
#define WHITE_DEFAULT_GREEN 500
20+
#define WHITE_DEFAULT_BLUE 510
21+
#define BLACK_DEFAULT_RED 160
22+
#define BLACK_DEFAULT_GREEN 200
23+
#define BLACK_DEFAULT_BLUE 190
2424
//int16_t WHITE_CAL[3] = {444, 342, 345};
2525
//int16_t BLACK_CAL[3] = {153, 135, 123};
2626

27+
2728
#define WHITE_OFFSET 0
2829
#define BLACK_OFFSET 6
2930
#define COLOR_SIZE 20
@@ -41,7 +42,7 @@
4142
#define LIGHT_GREEN_MAX 140
4243
#define GREEN_MAX 170
4344
#define LIGHT_BLUE_MAX 210
44-
#define BLUE_MAX 260
45+
#define BLUE_MAX 250
4546
#define VIOLET_MAX 280
4647
#define BROWN_MAX_VALUE 0.5
4748
#define BROWN_MAX_SATURATION 0.45

‎src/definitions.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@
2727
#define UART 0
2828
#define UART_BAUD_RATE 460800
2929

30+
#define DL1 left_led
31+
#define DL2 right_led
32+
3033
#define CHARGE_THRESHOLD 97
3134

35+
#define NO_ACK 0xFF
36+
3237
const float WHEEL_DIAMETER_MM = 34.0;
3338
const float WHEEL_TRACK_MM = 89.0;
3439
const float MOTOR_MAX_RPM = 70.0;
3540
const float ROBOT_MAX_DEG_S = 6*(2*MOTOR_MAX_RPM*WHEEL_DIAMETER_MM)/WHEEL_TRACK_MM;
36-
41+
const float MOTOR_CONTROL_MM_S = 100.0;
42+
const float MOTOR_CONTROL_DEG_S = 100.0;
3743

3844
// unit conversion constants
3945

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /