Skip to content

Commit

Permalink
basic function with speed test
Browse files Browse the repository at this point in the history
  • Loading branch information
captFuture committed Apr 21, 2022
1 parent 0c07198 commit 99de8a2
Show file tree
Hide file tree
Showing 11 changed files with 516 additions and 362 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
lib
16 changes: 16 additions & 0 deletions data/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"cartname": "TarantlCart_000",
"ssid": "TarantlBros",
"passwd": "chillfumml",
"speedprofile":[
{
"speed_max":-300,
"speed_min":300,
"steer_max":200,
"steer_min":-200,
"accel":200,
"boost":100,
"symbol":0
}
]
}
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
platform = espressif32
board = m5stack-core-esp32
framework = arduino
lib_deps = madhephaestus/WiiChuck @ ^0.3.2, siteswapjuggler/Ramp @ ^0.6.0
lib_deps = madhephaestus/WiiChuck @ ^0.3.2, siteswapjuggler/Ramp @ ^0.6.0, ayushsharma82/AsyncElegantOTA @ ^2.2.6, me-no-dev/AsyncTCP @ ^1.1.1, me-no-dev/ESP Async WebServer @ ^1.2.3, WiFi, bblanchon/ArduinoJson @ ^6.19.4
;lib_deps = M5Stack, siteswapjuggler/Ramp @ ^0.6.0
monitor_speed = 115200
29 changes: 29 additions & 0 deletions src/buttons.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
if (M5.BtnA.wasReleased()) {
//motorOn = true;
myDrive = 0;
setDisplay(myDrive, true);
}

if (M5.BtnA.pressedFor(1000)) {
setDisplay(myDrive, true);
}

if (M5.BtnB.wasReleased()) {
//motorOn = false;
myDrive = 0;
setDisplay(myDrive, true);
}

if (M5.BtnB.pressedFor(1000)) {
setDisplay(myDrive, true);
}

if (M5.BtnC.wasReleased()) {
//motorOn = true;
myDrive = 0;
setDisplay(myDrive, true);
}

if (M5.BtnC.pressedFor(1000)) {
setDisplay(myDrive, true);
}
55 changes: 55 additions & 0 deletions src/configload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@


// Loads the configuration from a file
void loadConfiguration(const char *filename, Config &config) {
// Open file for reading
File file = SPIFFS.open(filename);
StaticJsonDocument<1024> doc;
DeserializationError error = deserializeJson(doc, file);
if (error)
Serial.println(F("Failed to read file, using default configuration"));

strlcpy(config.cartname, // <- destination
doc["cartname"] | "TarantlCart", // <- source
sizeof(config.cartname)); // <- destination's capacity

strlcpy(config.ssid, // <- destination
doc["ssid"] | "TarantlVR", // <- source
sizeof(config.ssid)); // <- destination's capacity

strlcpy(config.passwd, // <- destination
doc["passwd"] | "chillfumml", // <- source
sizeof(config.passwd)); // <- destination's capacity

JsonObject speedprofile_0 = doc["speedprofile"][0];

config.speed_max = speedprofile_0["speed_max"] | -100;
config.speed_min = speedprofile_0["speed_min"] | 100;
config.steer_max = speedprofile_0["steer_max"] | -100;
config.steer_min = speedprofile_0["steer_min"] | 100;
config.accel_min = speedprofile_0["accel_min"] | 200;
config.boost_max = speedprofile_0["boost"] | 100;



file.close();
}

// Prints the content of a file to the Serial
void printFile(const char *filename) {
// Open file for reading
File file = SPIFFS.open(filename);
if (!file) {
Serial.println(F("Failed to read file"));
return;
}

// Extract each characters by one by one
while (file.available()) {
Serial.print((char)file.read());
}
Serial.println();

// Close the file
file.close();
}
13 changes: 13 additions & 0 deletions src/display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
void setDisplay(int myDrive, boolean clear){
if(clear){M5.Lcd.fillScreen(TFT_BLACK);}
M5.Lcd.setCursor(0, 140, 2);
M5.Lcd.setTextSize(1);
M5.Lcd.print("speed: "); M5.Lcd.println(myDrive);
M5.Lcd.print("MAX: "); M5.Lcd.println(config.speed_max);
M5.Lcd.print("MIN: "); M5.Lcd.println(config.speed_min);
M5.Lcd.print("ST-MAX: "); M5.Lcd.println(config.steer_max);
M5.Lcd.print("ST-MIN: "); M5.Lcd.println(config.steer_min);
M5.Lcd.print("accel: "); M5.Lcd.println(accel);

//M5.Lcd.print("boost: "); M5.Lcd.println(boost);
}
69 changes: 69 additions & 0 deletions src/hoverboard_telemetry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// ########################## SEND ##########################
void Send(int16_t uSteer, int16_t uSpeed)
{
// Create command
Command.start = (uint16_t)START_FRAME;
//Command.pitch = 0;
//Command.dpitch = 0;
Command.steer = (int16_t)uSteer;
Command.speed = (int16_t)uSpeed;
//Command.sensors = ;
Command.checksum = (uint16_t)(Command.start ^ Command.steer ^ Command.speed);

// Write to Serial
HoverSerial.write((uint8_t *) &Command, sizeof(Command));
}

// ########################## RECEIVE ##########################
void Receive()
{
if (HoverSerial.available()) {
incomingByte = HoverSerial.read();
bufStartFrame = ((uint16_t)(incomingByte) << 8) | incomingBytePrev;
}
else {
return;
}

#ifdef DEBUG_RX
Serial.print(incomingByte);
return;
#endif

if (bufStartFrame == START_FRAME) {
p = (byte *)&NewFeedback;
*p++ = incomingBytePrev;
*p++ = incomingByte;
idx = 2;
} else if (idx >= 2 && idx < sizeof(SerialFeedback)) {
*p++ = incomingByte;
idx++;
}

if (idx == sizeof(SerialFeedback)) {
uint16_t checksum;
checksum = (uint16_t)(NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas
^ NewFeedback.batVoltage ^ NewFeedback.boardTemp ^ NewFeedback.cmdLed);

if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum) {
memcpy(&Feedback, &NewFeedback, sizeof(SerialFeedback));

Serial.print("1: "); Serial.print(Feedback.cmd1);
Serial.print(" 2: "); Serial.print(Feedback.cmd2);
Serial.print(" 3: "); Serial.print(Feedback.speedR_meas);
Serial.print(" 4: "); Serial.print(Feedback.speedL_meas);
Serial.print(" 5: "); Serial.print(Feedback.batVoltage);
Serial.print(" 6: "); Serial.print(Feedback.boardTemp);
Serial.print(" 7: "); Serial.println(Feedback.cmdLed);

//driveSpeed = 2*3,14*8,255*Feedback.speedR_meas*60/1000;
//driveSpeed = 3,11 * Feedback.speedL_meas;
driveSpeed = (float)Feedback.speedL_meas;
} else {
Serial.println("Non-valid data skipped");
}
idx = 0;
}

incomingBytePrev = incomingByte;
}
Loading

0 comments on commit 99de8a2

Please sign in to comment.