public void controlTank(float horizontal, float vertical) { JSONObject json = new JSONObject(); if (sendMode == SendMode.SERIAL) { int left = (int)((vertical + horizontal) * 255 * (maxSpeed / 100)); int right = (int)((vertical - horizontal) * 255 * (maxSpeed / 100)); if (left > 255) { left = 255; } if (left < -255) { left = -255; } if (right > 255) { right = 255; } if (right < -255) { right = -255; } json.AddField("L", left); json.AddField("R", right); if (serialPort) { serialPort.Write(json.ToString() + "\r\n"); } } else { json.AddField("x", (int)(horizontal * maxSpeed)); json.AddField("y", (int)(vertical * maxSpeed)); if (sendMode == SendMode.BLUETOOTH) { if (bluetoothSender) { bluetoothSender.sendMessage("t" + json.ToString() + "\r\n"); } } else if (sendMode == SendMode.UDP) { if (udpSender) { udpSender.sendMessage("t" + json.ToString() + "\r\n"); } } } }
///**************************************************/// ///***************CONNECTION FUNCTIONS***************/// ///**************************************************/// public void sendBluetoothMessage() { bluetoothSender.sendMessage(getJSON()); }