Skip to content

Commit

Permalink
Change from TCP to UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
Finchiedev committed Dec 23, 2018
1 parent 13c622a commit b87e364
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
44 changes: 22 additions & 22 deletions App/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
<script type="text/javascript" src="JS/main.js"></script>
<script type="text/javascript">
var net = require('net');
var dgram = require('dgram');
var client = new net.Socket();
var childProcess = require('child_process');
var clientSocket = new net.Socket();
var clientSocket = new dgram.createSocket('udp4');
var jointSpeed = 500;
var direction = 5270;
var stopped = [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]
Expand Down Expand Up @@ -88,36 +89,34 @@
}

async function writeStartingValues(interval) {
clientSocket.write("0502000200");
clientSocket.send("0502000200", 9999, '192.168.100.1');
await sleep(interval);
clientSocket.write("0602000200");
clientSocket.send("0602000200", 9999, '192.168.100.1');
await sleep(interval);
clientSocket.write("0705120512");
clientSocket.send("0705120512", 9999, '192.168.100.1');
await sleep(interval);
}

async function pollGamepad(interval) {
while (true) {
async function pollGamepad(gamepad) {
var gamepad = navigator.getGamepads()[0];
var wheel1 = axisValue(1, 3, gamepad)
var wheel3 = axisValue(3, 3, gamepad)
var wheel2 = axisValue(2, 1, gamepad)
var wheel4 = axisValue(2, 1, gamepad)
var cameraPanValue = cameraPan(7, leftCameraButton, gamepad, 300, jointSpeed)

clientSocket.write('02' + wheel1);
await sleep(interval);
clientSocket.write('04' + wheel3);
await sleep(interval);
clientSocket.write('01' + wheel2);
await sleep(interval);
clientSocket.write('03' + wheel4);
await sleep(interval)
clientSocket.write(cameraPanValue);
await sleep(interval)
// clientSocket.write(rightCamera);
clientSocket.send('02' + wheel1, 9999, '192.168.100.1');
// await sleep(interval);
clientSocket.send('04' + wheel3, 9999, '192.168.100.1');
// await sleep(interval);
clientSocket.send('01' + wheel2, 9999, '192.168.100.1');
// await sleep(interval);
clientSocket.send('03' + wheel4, 9999, '192.168.100.1');
// await sleep(interval)
clientSocket.send(cameraPanValue, 9999, '192.168.100.1');
// await sleep(interval)
// clientSocket.send(rightCamera);
// await sleep(interval)
}
}

function runScript(scriptPath, callback) {
Expand Down Expand Up @@ -157,12 +156,13 @@
}, 1000)
writeToServer('START');
setTimeout(async function() {
clientSocket.connect(9999, '192.168.100.1', async function() {
// clientSocket.connect(9999, '192.168.100.1', async function() {
await writeStartingValues(30)
window.addEventListener("gamepadconnected", function(event) {
pollGamepad(30);
let gamepadInterval;
window.addEventListener("gamepadconnected", function(event) {
gamepadInterval = setInterval(pollGamepad, 30, event.gamepad);
});
});
// });
}, 3000)
}, 3000)
</script>
Expand Down
12 changes: 6 additions & 6 deletions Server/Server-Code-2018/RoboCupServer-Current.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

class MyTCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
while True:
# while True:
#sc.flush()
self.data = self.request.recv(2048).decode('utf-8').strip()
self.data = self.request[0].decode('utf-8').strip()
new = self.data.split('\n')
for i in new:
if i != "":
Expand All @@ -38,9 +38,9 @@ def handle(self):
if ID < 5:
try:
moveWheel(ID, int(i[2:]))
except:
except e:
print(e)
print('brokeWheel ',ID)
pass
else:
try:
moveJoint(ID, int(i[2:-4]), i[-4:])
Expand All @@ -53,8 +53,8 @@ def handle(self):
if __name__ == "__main__":
HOST, PORT = "", 9999

SocketServer.TCPServer.allow_reuse_address = True
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
SocketServer.UDPServer.allow_reuse_address = True
server = SocketServer.UDPServer((HOST, PORT), MyTCPHandler)

print('Servre Started')
server.serve_forever()
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit b87e364

Please sign in to comment.