Open atc1441 opened 5 years ago
Hey, nice to see someone using the code :+1: I'm well aware that it's a work in progress, cleanup is a big part of it ;)
Which branch are you using as a base right now? Do you have fork? You are correct, the readings get mixed together as of now. I started to isolate the protocol stuff, but some global variables are still being used. If I remember correctly, I started restructuring the protocol into that direction before my vacation, but I need to check in which state I left my work.
I'll probably be able to give you a quick and dirty solution quickly if you need something fast.
Hi again, i hope you had a nice vacation.
I am pretty happy with what you made so no problem of not so clean code :) I use this version of Hoverboard API https://github.com/p-h-a-i-l/HoverboardAPI/tree/b8d0454b3b8bf4ba77d26c7c00144bf8d3a84ee8
Unfortunately i am not that big into GitHub until now so i didn't made any Fork, made a git clone recurse of testrun and edited it that way that i put all the files needed in one folder to make it work under arduino ide. also i made a cleanup of the code but in a very heavy way. removed every #define and the not needed parts between #ifdef to make the code shorter.
if you want to i can upload that code to github?! but as said its ugly and even more unreadable. here is a short version of what i am doing:
volatile motorControl motor1 = {{0.0, 0.0}, {0.0, 0.0}};
int serialWrapper(unsigned char data, int len) { return (int) COM[2]->write(data, len); } HoverboardAPI hoverboard = HoverboardAPI(serialWrapper); int serialWrapper1(unsigned char data, int len) { return (int) COM[1]->write(data, len); } HoverboardAPI hoverboard1 = HoverboardAPI(serialWrapper1);
void processHalldata ( PROTOCOL_STAT s, PARAMSTAT param, uint8_t fn_type, int len ) { switch (fn_type) { case FN_TYPE_POST_READRESPONSE: case FN_TYPE_POST_WRITE: motor.measured.actualSpeed_kmh = hoverboard.getSpeed_kmh(); motor.measured.actualSteer_kmh = hoverboard.getSteer_kmh(); break; } } void processHalldata1 ( PROTOCOL_STAT s, PARAMSTAT param, uint8_t fn_type, int len ) { switch (fn_type) { case FN_TYPE_POST_READRESPONSE: case FN_TYPE_POST_WRITE: motor1.measured.actualSpeed_kmh = hoverboard1.getSpeed_kmh(); motor1.measured.actualSteer_kmh = hoverboard1.getSteer_kmh(); break; } } SETUP
hoverboard.sendPWMData(0, 0, 1000, -1000, 1, PROTOCOL_SOM_ACK); hoverboard1.sendPWMData(0, 0, 1000, -1000, 1, PROTOCOL_SOM_ACK); hoverboard.setParamHandler(hoverboard.Codes::sensHall, processHalldata); hoverboard1.setParamHandler(hoverboard1.Codes::sensHall, processHalldata1); hoverboard.sendBuzzer( 5, 0, 30); hoverboard1.sendBuzzer( 5, 0, 30);
LOOP
hoverboard.requestRead(hoverboard.Codes::protocolCountSum); hoverboard.requestRead(hoverboard.Codes::sensElectrical); hoverboard.requestRead(hoverboard.Codes::sensHall); COM[0]->print("V: "); COM[0]->print(hoverboard.getBatteryVoltage()); COM[0]->print(" Current0: "); COM[0]->print(hoverboard.getMotorAmpsAvg(0)); COM[0]->print(" Current1: "); COM[0]->print(hoverboard.getMotorAmpsAvg(1)); COM[0]->print(" Speed: "); COM[0]->print(hoverboard.getSpeed_kmh()); COM[0]->print(" Steer: "); COM[0]->print(hoverboard.getSteer_kmh()); COM[0]->println();
int i = 0; while (COM[2]->available() && i++ < 1024) { // read maximum 1024 byte at once. unsigned char readChar = COM[2]->read(); hoverboard.protocolPush( readChar ); } hoverboard.protocolTick();
hoverboard1.requestRead(hoverboard1.Codes::protocolCountSum); hoverboard1.requestRead(hoverboard1.Codes::sensElectrical); hoverboard1.requestRead(hoverboard1.Codes::sensHall); COM[0]->print("V: "); COM[0]->print(hoverboard1.getBatteryVoltage()); COM[0]->print(" Current0: "); COM[0]->print(hoverboard1.getMotorAmpsAvg(0)); COM[0]->print(" Current1: "); COM[0]->print(hoverboard1.getMotorAmpsAvg(1)); COM[0]->print(" Speed: "); COM[0]->print(hoverboard1.getSpeed_kmh()); COM[0]->print(" Steer: "); COM[0]->print(hoverboard1.getSteer_kmh()); COM[0]->println(); int er = 0; while (COM[1]->available() && er++ < 1024) { // read maximum 1024 byte at once. unsigned char readChar = COM[1]->read(); hoverboard1.protocolPush( readChar ); } hoverboard1.protocolTick(); so i create two hoverboard api classes if you call it that way.
Thank you for your offer, but i dont need it that fast :) as i can control the motors for itself and only the read-back is not working. i connected both HB mainboards on one Battery so the Voltage is the same.
And Thank you again for this Repo :) and i think if you would promote it somehow more people will use it, it was very hard to find the right branch etc. but i think you know it and want to clean it up first.
Hi, and sry for opening an issue again.
I have a 4WD Drive made out of two hoverboards and want to connect one on serial 1 and one on serial 2 of the esp32 if have it running so far and can control the motor speed etc. but unfortunatly the readings from HB boards gets mixed together, so when i read speed data only the last received ones getting showed. i think that is because of the hbprotocol and that it has only one variable to save the data ?!
also another thing. the current from the motors is not right, on motor 0 it is shown correctly but on motor 1 it will just show the same value as motor 0.
Here is a short video of my current status: https://youtu.be/4yjYoxfnXfc