Skip to content

Commit

Permalink
Add arm functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Finchiedev committed Jun 23, 2019
1 parent a2b455f commit a125a8d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 0 additions & 1 deletion App/control.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<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/egg.js"></script>
</head>
<body>
<h1 id="main-header">Controller visualisation</h1>
Expand Down
28 changes: 25 additions & 3 deletions App/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@
}
}

function moveJoint(ID, percentage) {
function moveJointWithPercentage(ID, percentage) {
destination = 1023 + (percentage * 2048) / 100;
if (ID == 5 || ID == 8) {
destination = 3071 - (percentage*2048)/100;
}
if (ID == 9) {
destination = (percentage * 2680) / 100;
console.log(destination);
}
clientSocket.send(`0${ID} ${destination} 200`, 9999, '192.168.100.1');
}

Expand Down Expand Up @@ -100,6 +104,21 @@
sendWheelValue(dynamixel, val);
}

function moveArm(dynamixel, upButton, downButton) {
var gamepad = navigator.getGamepads()[0];
if (gamepad.buttons[upButton].value > 0) {
if (lastVals[dynamixel] != lastVals[dynamixel]+10 && lastVals[dynamixel] < 100) {
moveJointWithPercentage(dynamixel, lastVals[dynamixel]+10);
lastVals[dynamixel] += 10;
}
} else if (gamepad.buttons[downButton].value > 0) {
if (lastVals[dynamixel] != lastVals[dynamixel] - 10 && lastVals[dynamixel] > 0) {
moveJointWithPercentage(dynamixel, lastVals[dynamixel] - 10);
lastVals[dynamixel] -= 10;
}
}
}

function moveFlipper(dynamixel, axis, holdMode, holdButton) {
var gamepad = navigator.getGamepads()[0];
var change = Math.round((gamepad.axes[axis])*10)
Expand All @@ -108,7 +127,7 @@
if(val >= 0 && val <= 100) {
if (val != lastVals[dynamixel]) {
lastVals[dynamixel] = val;
moveJoint(dynamixel, val);
moveJointWithPercentage(dynamixel, val);
}
}
}
Expand All @@ -126,9 +145,11 @@
lastVals[i] = 0;
}
for (var i = 5; i <= 8; i++) {
moveJoint(i, 100);
moveJointWithPercentage(i, 100);
lastVals[i] = 100;
}
moveJointWithPercentage(9, 0);
lastVals[9] = 0;
// clientSocket.send("0902000200", 9999, '192.168.100.1');
// await sleep(interval);
// clientSocket.send("1002000200", 9999, '192.168.100.1');
Expand Down Expand Up @@ -161,6 +182,7 @@
moveFlipper(7, 1, true, 10);
moveFlipper(6, 3, false, 0);
moveFlipper(8, 3, true, 11);
moveArm(9, 3, 0);
// await sleep(interval);
// cameraPan('11', gamepad, 300, jointSpeed);
// await sleep(interval);
Expand Down
4 changes: 2 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ let win;

function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600
width: 1600,
height: 1200
});
win.loadFile('App/loading.html');
setTimeout(function() {
Expand Down

0 comments on commit a125a8d

Please sign in to comment.