Skip to content

Commit

Permalink
Finish base JS client code
Browse files Browse the repository at this point in the history
  • Loading branch information
Finchiedev committed Nov 6, 2018
1 parent f222c29 commit 09500a7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
49 changes: 21 additions & 28 deletions App/JS/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var net = require('net');
var client = new net.Socket();

function terminateConnection(connection) {
connection.write("010000");
connection.write("020000");
connection.write("030000");
connection.write("040000");
connection.write("010");
connection.write("020");
connection.write("030");
connection.write("040");
}

function axisValue(dynamixel, axis) {
Expand All @@ -16,28 +16,22 @@ function axisValue(dynamixel, axis) {
console.error("Controller value is out of bounds! (" + val + ")");
}

//Logic to make controller value proper
if (val <= 512) {
val = (val - 512) * -2;
} else if (val < 512) {
val <<= 1;
// if (val <= 512) {
// val = (val - 512) * -2;
// } else {
// val = (val - 512) * -2;
// // val = -val;
// console.log(val, -val);
// }
//
// // if (dynamixel == 1 || dynamixel == 3) {
// // val = -val
// // }
val = (val - 512) * -2;
if (dynamixel == 1 || dynamixel == 3) {
val = -val;
}

var out = "";
if (val < 10) {
out += "000";
out += val;
} else if (val < 100) {
out += "00";
out += val;
} else if (val < 1000) {
out += "0";
out += val;
} else {
out += val;
}

return out;
return val;
}

function sleep(ms) {
Expand All @@ -46,12 +40,11 @@ function sleep(ms) {

async function pollGamepad(interval) {
while (true) {
console.log(axisValue(2, 1));
client.write('01-' + axisValue(1, 3));
client.write('01' + axisValue(1, 3));
await sleep(interval);
client.write('02' + axisValue(2, 1));
await sleep(interval);
client.write('03-' + axisValue(3, 3));
client.write('03' + axisValue(3, 3));
await sleep(interval);
client.write('04' + axisValue(4, 1));
}
Expand Down
6 changes: 3 additions & 3 deletions App/control.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Robot Control</title>
<link rel="stylesheet" href="CSS/main.css">
<script type="text/javascript" src="JS/main.js"></script>
<!--<script type="text/javascript" src="JS/controller.js"></script>-->
<script type="text/javascript" src="JS/client.js"></script>
<script type="text/javascript">
if (process.platform == 'win32' || process.platform == 'win64') {
execute('py App/JS/Resources/CurrentEmuBotCode2/client.py')
Expand All @@ -22,8 +22,8 @@
<a href="version.html">Version</a>
</div>
<div class="main">
<button type="button" name="start" onclick="controlServerCode(false)">[UNSTABLE] Start</button>
<button type="button" name="kill" onclick="controlServerCode(true)">[UNSTABLE] Kill</button>
<button type="button" name="start" onclick="controlServerCode(false)">[UNSTABLE PYTHON] Start</button>
<button type="button" name="kill" onclick="controlServerCode(true)">[UNSTABLE PYTHON] Kill</button>
<p id="status"></p>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function createWindow() {
width: 800,
height: 600
})
win.loadFile('App/controlTest.html')
win.loadFile('App/control.html')
// win.loadURL('http://localhost:8080')
win.webContents.openDevTools()

Expand Down

0 comments on commit 09500a7

Please sign in to comment.