Skip to content

Commit

Permalink
Add flipper visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Finchiedev committed Jul 4, 2019
1 parent 8b52812 commit fb1512c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
45 changes: 40 additions & 5 deletions App/JS/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ WristSlider.oninput = function() {
}
*/

function lineToAngle(ctx, x1, y1, length, angle, colour) {

angle *= Math.PI / 180;

var x2 = x1 + length * Math.cos(angle),
y2 = y1 + length * Math.sin(angle);

ctx.beginPath();
ctx.strokeStyle = colour;
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
ctx.closePath();

return {x: x2, y: y2};
}

function drawFlipperLines(ctx) {
lineToAngle(ctx, 100, 100, 50, 180 * (lastVals[6]/100) + 90, 'Green')
lineToAngle(ctx, 200, 100, 50, -180 * (lastVals[8]/100) + 90, 'Green')
lineToAngle(ctx, 100, 200, 50, 180 * (lastVals[5]/100) + 90, 'Red')
lineToAngle(ctx, 200, 200, 50, -180 * (lastVals[7]/100) + 90, 'Red')
}

var flipperCanvas = document.getElementById('flippers')
var context = flipperCanvas.getContext('2d')

drawFlipperLines(context)
// lineToAngle(context, 50, 50, 25, 45)

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
Expand Down Expand Up @@ -151,7 +181,7 @@ function moveJointWithPercentage(ID, percentage) {
// Ensures sent servo destination data fits within their limits.
if(destination > flipperJointLimits[ID-5][1]) {destination = flipperJointLimits[ID-5][1];}
if(destination < flipperJointLimits[ID-5][0]) {destination = flipperJointLimits[ID-5][0];}
if (ID < 10 && ID != 9) {
if (ID < 9) {
sendWithCheck(`0${ID} ${destination} 200`, 9999, '192.168.100.1');
} else if (ID == 9) {
sendWithCheck(`09 ${destination} 1024`, 9999, '192.168.100.1');
Expand Down Expand Up @@ -206,9 +236,9 @@ function moveWheel(dynamixel, axis, gamepad, sticks) {
val *= multipliers[1][1];
}

if (-150 <= val >= 150) {
val = 0;
}
// if (-150 <= val >= 150) {
// val = 0;
// }
sendWheelValue(dynamixel, val);
}

Expand Down Expand Up @@ -312,7 +342,7 @@ async function writeDefaultValues() {
moveGrabber(1);

clientSocket.send('20,100', 25565, '192.168.100.1')
// lastCameraVals = [0, 100]
lastCameraVals = [20, 100]
}

/**
Expand All @@ -336,6 +366,11 @@ async function pollGamepad(gamepad, sticks = false) {
moveArm(9, 3, 2);
moveWrist(10, 1, 0);
// moveCamera()
context.beginPath();
context.clearRect(0, 0, 100000000000, 100000000000000);
context.stroke();
context.closePath();
drawFlipperLines(context);
}

// client.connect(5000, '192.168.100.1', function() {
Expand Down
1 change: 1 addition & 0 deletions App/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<h1 class="text" id="main-header">Dashboard - Robotics GUI</h1>
<p id="marker"></p>
<img src="http://192.168.100.1:8080" width="auto" height="auto"></img>
<canvas id="flippers" width="640" height="360"></canvas>
<div class="slidecontainer">
<h4>Grabber Direction </h4>
<p id="grabberPositionDisplay">Grabber position: 0%</p>
Expand Down

0 comments on commit fb1512c

Please sign in to comment.