-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c07198
commit 99de8a2
Showing
11 changed files
with
516 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.