Skip to content

0.3.0 #1

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 12 commits into from
Mar 1, 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
85 changes: 85 additions & 0 deletions examples/bridge_firmware_updater/bridge_firmware_updater
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
This file is part of the Arduino_Alvik library.

Copyright (c) 2024 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/


/*
You can use this sketch to make your Arduino Nano ESP32 an USB-to-serial adapter.
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
*/




#include "Arduino_Alvik.h"

unsigned long baud = 115200;

int rts = -1;
int dtr = -1;


static void onLineChange(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
if (event_base == ARDUINO_USB_CDC_EVENTS) {
arduino_usb_cdc_event_data_t * data = (arduino_usb_cdc_event_data_t*)event_data;
switch (event_id) {
case ARDUINO_USB_CDC_LINE_CODING_EVENT:
auto baud = data->line_coding.bit_rate;
Serial0.updateBaudRate(baud);
while (Serial0.available()) {
Serial0.read();
}
break;
}
}
}

void setup() {
Serial.onEvent(onLineChange);
Serial.enableReboot(false);
Serial.begin(baud);
Serial.setRxBufferSize(0);
Serial.setRxBufferSize(2048);
Serial0.setRxBufferSize(8192);
Serial0.setTxBufferSize(8192);
Serial0.begin(baud, SERIAL_8E1);
Serial0.flush();
pinMode(BOOT_STM32, OUTPUT);
pinMode(RESET_STM32, OUTPUT);
digitalWrite(BOOT_STM32,HIGH);
delay(1000);
digitalWrite(RESET_STM32,LOW);
delay(1000);
digitalWrite(RESET_STM32,HIGH);



}

void loop() {
int len = 0;
uint8_t auc_buffer[488];
while (Serial.available() && len < sizeof(auc_buffer)) {
auc_buffer[len++] = Serial.read();
}
if (len) {
Serial0.write(auc_buffer, len);
}

len = 0;
while (Serial0.available() && len < sizeof(auc_buffer)) {
auc_buffer[len++] = Serial0.read();
}
if (len) {
Serial.write(auc_buffer, len);
}
}
2 changes: 1 addition & 1 deletion examples/color_calibration/color_calibration.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void setup() {
}

void loop() {
int16_t color[3];
int color[3];
float rgb[3];
float hsv[3];
alvik.get_color_raw(color[0], color[1], color[2]);
Expand Down
25 changes: 25 additions & 0 deletions examples/drive/drive.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
This file is part of the Arduino_Alvik library.

Copyright (c) 2024 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include "Arduino_Alvik.h"

Arduino_Alvik alvik;

void setup() {
alvik.begin();
}

void loop() {
alvik.drive(10, 45);
delay(10000);
alvik.drive(10, -45);
delay(10000);
}
83 changes: 83 additions & 0 deletions examples/line_follower/line_follower.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
This file is part of the Arduino_Alvik library.

Copyright (c) 2024 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include "Arduino_Alvik.h"

Arduino_Alvik alvik;

int line_sensors[3];
float error = 0;
float control = 0;
float kp = 50.0;



void setup() {
Serial.begin(115200);
while((!Serial)&&(millis()>3000));
alvik.begin();
alvik.left_led.set_color(0,0,1);
alvik.right_led.set_color(0,0,1);

while(!alvik.get_touch_ok()){
delay(50);
}
}

void loop() {
while (!alvik.get_touch_cancel()){

alvik.get_line_sensors(line_sensors[0], line_sensors[1], line_sensors[2]);
Serial.print(line_sensors[0]);
Serial.print("\t");
Serial.print(line_sensors[1]);
Serial.print("\t");
Serial.print(line_sensors[2]);
Serial.print("\n");
error = calculate_center(line_sensors[0], line_sensors[1], line_sensors[2]);
control = error * kp;
if (control > 0.2){
alvik.left_led.set_color(1,0,0);
alvik.right_led.set_color(0,0,0);
}
else{
if (control < -0.2){
alvik.left_led.set_color(0,0,0);
alvik.right_led.set_color(1,0,0);
}
else{
alvik.left_led.set_color(0,1,0);
alvik.right_led.set_color(0,1,0);
}
}

alvik.set_wheels_speed(30-control, 30+control);
delay(100);
}

while (!alvik.get_touch_ok()){
alvik.left_led.set_color(0,0,1);
alvik.right_led.set_color(0,0,1);
alvik.brake();
delay(100);
}
}

float calculate_center(const int left, const int center, const int right){
float centroid = 0.0;
float sum_weight = left + center + right;
float sum_values = left + center * 2 + right * 3;
if (sum_weight!=0.0){ // divide by zero protection
centroid=sum_values/sum_weight;
centroid=-centroid+2.0; // so it is right on robot axis Y
}
return centroid;
}
122 changes: 122 additions & 0 deletions examples/remote_control/remote_control.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
This file is part of the Arduino_Alvik library.

Copyright (c) 2024 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

// This example shows how to interface 2 Alvik robots via ESPnow.
// At startup, you can select if an Alvik is a trasmitter by pressing the "check button" or a receiver by pressing "cancel button". Use arrows to move the robot.

#include "Arduino_Alvik.h"
#include <esp_now.h>
#include <WiFi.h>

Arduino_Alvik alvik;

uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t myData;
esp_now_peer_info_t peerInfo;


int alvik_mode = -1; // 0 is receiver, 1 is sender

bool led_blink = false;


void setup() {
Serial.begin(115200);
while((!Serial)&&(millis()>3000));

alvik.begin();

WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}

while (alvik_mode == -1){
if (alvik.get_touch_cancel()){
alvik_mode = 0;
}
if (alvik.get_touch_ok()){
alvik_mode = 1;
}
}
if (alvik_mode == 0){
esp_now_register_recv_cb(OnDataRecv);
}
else{
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;

if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
}
}

void loop() {
if (alvik_mode==0){
alvik.left_led.set_color(led_blink, !led_blink, 0);
alvik.right_led.set_color(!led_blink, led_blink, 0);
delay(500);
}
else{
if (alvik.get_touch_any()){
if (alvik.get_touch_up()){
myData = 'F';
esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
}
if (alvik.get_touch_down()){
myData = 'B';
esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
}
if (alvik.get_touch_left()){
myData = 'L';
esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
}
if (alvik.get_touch_right()){
myData = 'R';
esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
}
if (alvik.get_touch_center()){
myData = 'S';
esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
}
}
alvik.left_led.set_color(0, 0, led_blink);
alvik.right_led.set_color(0, 0, led_blink);
delay(100);
}
led_blink = !led_blink;
}

void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len){
Serial.print(incomingData[0]);
switch (incomingData[0]){
case 'F':
alvik.drive(7, 0);
break;
case 'B':
alvik.drive(-7, 0);
break;
case 'L':
alvik.drive(0, 45);
break;
case 'R':
alvik.drive(0, -45);
break;
case 'S':
alvik.brake();
break;
}
Serial.println();
}
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.2.0
version=0.3.0
author=Arduino, Giovanni di Dio Bruno, Lucio Rossi
maintainer=Arduino <[email protected]>
sentence=Library to code Arduino Alvik robot
Expand Down
Loading