Bugfix in NodeMCU checksum
Calculated in the wrong function New value for resend. 30ms works like a charm and feels responsive
This commit is contained in:
parent
f9745a2e44
commit
35479c6f0a
@ -11,7 +11,7 @@
|
|||||||
char ssid[] = "ROBOT";
|
char ssid[] = "ROBOT";
|
||||||
char pass[] = "myrobotisawesome";
|
char pass[] = "myrobotisawesome";
|
||||||
|
|
||||||
const long sendInterval = 25; // in ms
|
const long sendInterval = 30; // in ms
|
||||||
|
|
||||||
WiFiUDP Udp;
|
WiFiUDP Udp;
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ void setup() {
|
|||||||
IPAddress apip = WiFi.softAPIP();
|
IPAddress apip = WiFi.softAPIP();
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
//Serial.begin(115200);
|
//Serial.begin(115200);
|
||||||
Serial.begin(57600);
|
Serial.begin(250000);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.print("AP IP: ");
|
Serial.print("AP IP: ");
|
||||||
Serial.println(apip);
|
Serial.println(apip);
|
||||||
@ -82,17 +82,18 @@ void setup() {
|
|||||||
pPacket->MagicWordLow = 0x0DED;
|
pPacket->MagicWordLow = 0x0DED;
|
||||||
pPacket->MagicWordHigh = 0x0DEC;
|
pPacket->MagicWordHigh = 0x0DEC;
|
||||||
|
|
||||||
pPacket->Throttle = 0;
|
pPacket->Throttle = 1;
|
||||||
pPacket->Steering = 0;
|
pPacket->Steering = 2;
|
||||||
pPacket->Kp = 0;
|
pPacket->Kp = 3;
|
||||||
pPacket->Ki = 0;
|
pPacket->Ki = 4;
|
||||||
pPacket->Kd = 0;
|
pPacket->Kd = 5;
|
||||||
pPacket->Enabled = false;
|
pPacket->Enabled = false;
|
||||||
pPacket->checksum = 0;
|
pPacket->checksum = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendPacket()
|
void sendPacket()
|
||||||
{
|
{
|
||||||
|
calcChecksum();
|
||||||
Serial.write(buffer, bufferSize);
|
Serial.write(buffer, bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ void OSCMsgReceive()
|
|||||||
}
|
}
|
||||||
if (!msgIN.hasError())
|
if (!msgIN.hasError())
|
||||||
{
|
{
|
||||||
msgIN.route("/Robot/Enable",toggleEnabled);
|
msgIN.route("/Robot/Enable",funcEnabled);
|
||||||
msgIN.route("/Fader/Throttle",funcThrottle);
|
msgIN.route("/Fader/Throttle",funcThrottle);
|
||||||
msgIN.route("/Fader/Steering",funcSteering);
|
msgIN.route("/Fader/Steering",funcSteering);
|
||||||
msgIN.route("/Gain/Kp",funcKp);
|
msgIN.route("/Gain/Kp",funcKp);
|
||||||
@ -121,7 +122,6 @@ void OSCMsgReceive()
|
|||||||
void sendUdp(OSCMessage* pMessage)
|
void sendUdp(OSCMessage* pMessage)
|
||||||
{
|
{
|
||||||
IPAddress remoteIp = Udp.remoteIP();
|
IPAddress remoteIp = Udp.remoteIP();
|
||||||
//outIp = Udp.remoteIP();
|
|
||||||
if (remoteIp != outIp)
|
if (remoteIp != outIp)
|
||||||
{
|
{
|
||||||
outIp = remoteIp;
|
outIp = remoteIp;
|
||||||
@ -136,11 +136,9 @@ void sendUdp(OSCMessage* pMessage)
|
|||||||
pMessage->send(Udp); // send the bytes
|
pMessage->send(Udp); // send the bytes
|
||||||
Udp.endPacket(); // mark the end of the OSC Packet
|
Udp.endPacket(); // mark the end of the OSC Packet
|
||||||
pMessage->empty(); // free space occupied by message
|
pMessage->empty(); // free space occupied by message
|
||||||
|
|
||||||
calcChecksum();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleEnabled(OSCMessage &msg, int addrOffset){
|
void funcEnabled(OSCMessage &msg, int addrOffset){
|
||||||
ledState = !(boolean) msg.getFloat(0);
|
ledState = !(boolean) msg.getFloat(0);
|
||||||
OSCMessage msgOUT("/Robot/Enable");
|
OSCMessage msgOUT("/Robot/Enable");
|
||||||
|
|
||||||
@ -148,7 +146,7 @@ void toggleEnabled(OSCMessage &msg, int addrOffset){
|
|||||||
|
|
||||||
msgOUT.add(!ledState);
|
msgOUT.add(!ledState);
|
||||||
sendUdp(&msgOUT);
|
sendUdp(&msgOUT);
|
||||||
pPacket->Enabled = ledState;
|
pPacket->Enabled = !ledState;
|
||||||
|
|
||||||
//Serial.println( ledState ? "Robot disabled" : "Robot enabled");
|
//Serial.println( ledState ? "Robot disabled" : "Robot enabled");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user