added APPs

This commit is contained in:
Fenoglio 2018-12-03 16:12:07 +01:00
parent 766f3d6d1e
commit b1782714a6
6 changed files with 137 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -5,6 +5,7 @@
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
#include "BluetoothSerial.h"
#include <CodeRacer.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
@ -13,13 +14,32 @@
BluetoothSerial SerialBT;
bool motioncontrol = false;
String recvddata = "";
int init_azimuth = 1000;
int azimuth = 0;
int minroll = 20;
int roll = 20;
int maxroll = 90;
int minpitch = 10;
int pitch = 0;
int maxpitch = 90;
int defaultleft = 200;
int left = 0;
int defaultright = 200;
int right = 0;
CodeRacer coderacer;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
coderacer.begin();
}
String recvddata = "";
void loop() {
if (Serial.available()) {
@ -43,6 +63,7 @@ void BTcontrol()
if(recvddata.startsWith("motion_on"))
{
SerialBT.print("motion_ready");
init_azimuth = 1000;
motioncontrol = true;
return;
}
@ -51,6 +72,7 @@ void BTcontrol()
{
SerialBT.print("motion_disabled");
motioncontrol = false;
coderacer.stop_driving();
return;
}
@ -71,6 +93,64 @@ void BTcontrol()
String BTmotioncontrol(String recvddata)
{
// split the string ...
String apr_substr=recvddata.substring(recvddata.indexOf("=")+1);
String a = apr_substr.substring(0,apr_substr.indexOf(";"));
String p = apr_substr.substring(apr_substr.indexOf(";")+1,apr_substr.lastIndexOf(";"));
String r = apr_substr.substring(apr_substr.lastIndexOf(";")+1);
azimuth = a.toInt();
pitch = p.toInt();
roll = r.toInt();
if(init_azimuth == 1000)
{
init_azimuth = azimuth;
}
azimuth = azimuth - init_azimuth;
if(abs(pitch)<minpitch){
pitch = 0;
coderacer.stop_driving();
}
else
{
pitch = pitch;
if(pitch > 0)
{
left = defaultleft+pitch;
if(left > 256) left = 256;
right = defaultright+pitch;
if(right > 256) right = 256;
coderacer.drive_forward(left,right);
}
else
{
left = defaultleft-pitch;
if(left > 256) left = 256;
right = defaultright-pitch;
if(right > 256) right = 256;
coderacer.drive_backward(left,right);
}
}
if(abs(roll)<minroll){
roll = 0;
}
/*
int defaultleft = 240;
int left = 0;
int defaultright = 240;
int right = 0;
*/
Serial.println(azimuth);
Serial.println(pitch);
Serial.println(roll);
return "motion_values_ok";
}

View file

@ -0,0 +1,56 @@
// Full API description of the coderacer.h can be found here: https://fenoglio.pages.itsblue.de/coderacer/
// Repository with all needed data and users guide is here: https://git.itsblue.de/Fenoglio/coderacer/tree/master
// An example for a application to control the coderacer via bluetooth can be found here:
// - this app was developed with MIT App Inventor and can be uploaded to your account to rework it.
#include <CodeRacer.h>
CodeRacer coderacer;
String recvddata = ""; //Variable in der der Bluetooth Befehl gespeichert wird
void setup() {
Serial.begin(115200);
coderacer.begin();
coderacer.bt_start("CodeRacer"); //Bluetooth für den Coderacer anschalten
coderacer.bt_enable_stopOnLostConnection(); //Coderacer anhalten, wenn 1 Sekunde nichts per Bluetooth empfangen wurde
coderacer.bt_addStringToIgnoreList("."); //das "." Zeichen wird beim empfangen ignoriert
}
void loop() {
// Prüfen ob Bluetooth Nachrichten angekommen sind und die gleich abholen ...
recvddata = coderacer.bt_getString(); //die Nachtricht merken (sie steht jetzt in recvdata und kann später benutzt werden)
if (recvddata != "") //wenn eine Nachricht empfangen wurde, in der was drin steht ...
{
Serial.println(recvddata);
if(recvddata == "stop")
{
coderacer.stop_driving();
}
if(recvddata == "vor")
{
coderacer.drive_forward(255,255);
}
if(recvddata.startsWith("rueck"))
{
coderacer.drive_backward(255,255);
}
if(recvddata.startsWith("links"))
{
coderacer.turn_left();
}
if(recvddata.startsWith("rechts"))
{
coderacer.turn_right();
}
}
delay(20);
}