Skip to content

Commit

Permalink
Add directional indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Finchiedev committed Jul 4, 2019
1 parent efdaea5 commit e01b03b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
32 changes: 29 additions & 3 deletions App/JS/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,14 @@ function moveJointWithPercentage(ID, percentage) {
}

function changeFlipperSelection() {
if(flipperSelect) {flipperSelect = false;}
else {flipperSelect = true;}
if(flipperSelect) {
flipperDirection.innerHTML = `Flippers: back`
flipperSelect = false;
}
else {
flipperDirection.innerHTML = `Flippers: front`
flipperSelect = true;
}
}

/**
Expand Down Expand Up @@ -323,6 +329,10 @@ function moveFlipper(dynamixel, axis) {

}

var flipperDirection = document.getElementById('flipperDirection');
var leftWheelDirection = document.getElementById('leftWheelsDirection');
var rightWheelDirection = document.getElementById('rightWheelsDirection');

/**
* Writes the default values to the server
*/
Expand All @@ -346,6 +356,10 @@ async function writeDefaultValues() {
grabberValue = 0;
moveGrabber(1);

flipperDirection.innerHTML = 'Flippers: front';
leftWheelDirection.innerHTML = 'Left wheels: forwards';
rightWheelDirection.innerHTML = 'Right wheels: forwards'

setTimeout(function() {
clientSocket.send('10,100', 25565, '192.168.100.1')
lastCameraVals = [10, 100]
Expand All @@ -372,6 +386,7 @@ async function pollGamepad(gamepad, sticks = false) {
moveFlipper(8, 3);
moveArm(9, 3, 2);
moveWrist(10, 1, 0);

// moveCamera()
context.beginPath();
context.clearRect(0, 0, 100000000000, 100000000000000);
Expand Down Expand Up @@ -402,7 +417,6 @@ function stop() {
// client.write(data);
// console.log(`Wrote '${data}' to server`);
// }

let gamepadInterval;
writeDefaultValues();
window.addEventListener('gamepadconnected', function(event) {
Expand All @@ -418,15 +432,26 @@ window.addEventListener('gamepadconnected', function(event) {
if (gamepad.buttons[5].pressed && !multipliers[0][0]) {
multipliers[0][1] *= -1;
multipliers[0][0] = true;
if (multipliers[0][1] == 1) {
rightWheelDirection.innerHTML = `Right wheels: forwards`;
} else {
rightWheelDirection.innerHTML = `Right wheels: backwards`;
}
} else if(!gamepad.buttons[5].pressed){
multipliers[0][0] = false;
}

if (gamepad.buttons[4].pressed && !multipliers[1][0]) {
multipliers[1][1] *= -1;
multipliers[1][0] = true;
if (multipliers[1][1] == 1) {
leftWheelDirection.innerHTML = `Left wheels: forwards`;
} else {
leftWheelDirection.innerHTML = `Left wheels: backwards`;
}
} else if(!gamepad.buttons[4].pressed) {
multipliers[1][0] = false;
// leftWheelDirection.innerHTML = `Left wheels: backwards`;
}

if (gamepad.buttons[16].pressed) {
Expand All @@ -435,6 +460,7 @@ window.addEventListener('gamepadconnected', function(event) {
}
if (gamepad.buttons[8].pressed && !b_button_state) {
b_button_state = true;

changeFlipperSelection();
}
else if(!gamepad.buttons[8].pressed) {
Expand Down
3 changes: 3 additions & 0 deletions App/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ <h1 class="text" id="main-header">Dashboard - Robotics GUI</h1>
<div class="slidecontainer">
<button type="button" name="move" onclick="moveStraight()">Move forward</button>
<button type="button" name="button" onclick="stop()">Stop</button>
<p id="leftWheelsDirection">Left wheels: forwards</p>
<p id="rightWheelsDirection">Right wheels: forwards</p>
<p id="flipperDirection">Flippers: front</p>
<h4>Grabber Direction </h4>
<p id="grabberPositionDisplay">Grabber position: 0%</p>
<form id="grabberParent">
Expand Down

0 comments on commit e01b03b

Please sign in to comment.