Skip to content

Commit

Permalink
BTSerial
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Reisner committed Feb 4, 2022
1 parent 18047fa commit 53936d2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
monitor_speed = 11520
monitor_speed = 115200
framework = arduino
lib_deps =
arduino-libraries/Servo@^1.1.8
paulstoffregen/FlexiTimer2@^1.1.0
ppedro74/SerialCommands@^1.1
upload_port = COM3
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <Arduino.h>
#include <Servo.h> //to define and control servos
#include <FlexiTimer2.h>//to set a timer to manage all servos
#include <SoftwareSerial.h>
#include <SerialCommands.h>

/* ---------------------------------------------------------------------------*/
Expand All @@ -47,8 +48,9 @@ void cartesian_to_polar(volatile float &alpha, volatile float &beta, volatile fl
void polar_to_servo(int leg, float alpha, float beta, float gamma);

/* SerialCommands */
SoftwareSerial BTserial(A0, A1);
char serial_command_buffer_[32];
SerialCommands serial_commands_(&Serial, serial_command_buffer_, sizeof(serial_command_buffer_), "\r\n", " ");
SerialCommands serial_commands_(&BTserial, serial_command_buffer_, sizeof(serial_command_buffer_), "\r\n", " ");

int next_int(SerialCommands* sender, const int defaultValue) {
char* str = sender->Next();
Expand Down Expand Up @@ -189,6 +191,7 @@ const float turn_x1 = (temp_a - length_side) / 2;
const float turn_y1 = y_start + y_step / 2;
const float turn_x0 = turn_x1 - temp_b * cos(temp_alpha);
const float turn_y0 = temp_b * sin(temp_alpha) - turn_y1 - length_side;

/*
- setup function
---------------------------------------------------------------------------*/
Expand All @@ -197,6 +200,7 @@ void setup()
//start serial for debug
Serial.begin(115200);
Serial.println("Robot starts initialization");
BTserial.println("Robot starts initialization");
//initialize default parameter
set_site(0, x_default - x_offset, y_start + y_step, z_boot);
set_site(1, x_default - x_offset, y_start + y_step, z_boot);
Expand All @@ -213,9 +217,11 @@ void setup()
FlexiTimer2::set(20, servo_service);
FlexiTimer2::start();
Serial.println("Servo service started");
BTserial.println("Servo service started");
//initialize servos
servo_attach();
Serial.println("Servos initialized");
BTserial.println("Servos initialized");

serial_commands_.SetDefaultHandler(cmd_unrecognized);
serial_commands_.AddCommand(&cmd_angle_corrections_);
Expand All @@ -229,8 +235,10 @@ void setup()
serial_commands_.AddCommand(&cmd_wave_);
serial_commands_.AddCommand(&cmd_shake_);
Serial.println("CLI initialized");
BTserial.println("CLI initialized");

Serial.println("Robot initialization Complete");
BTserial.println("Robot initialization Complete");
sit();
}

Expand Down
8 changes: 8 additions & 0 deletions workspace.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}

0 comments on commit 53936d2

Please sign in to comment.