-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
130 lines (123 loc) · 5.33 KB
/
index.html
File metadata and controls
130 lines (123 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Hello World!</title>
<script src="js/jquery1.11.1.js"></script>
<script src="js/hros_js_api.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<!--joystick scripts-->
<script src="js/virtualjoystick.js"></script>
<style>
#container {
width : 700px;
height : 1000px;
overflow : hidden;
padding : 0;
margin : 0;
-webkit-user-select : none;
-moz-user-select : none;
}
</style>
</head>
<body>
<script type="text/javascript">
var JSRobotCalls = new HROS_JS();
function Connect(){
JSRobotCalls.Connect(document.getElementById("ipAddress").value);
$("#connectionStatus").text("Connecting");
}
// check the connection status and update UI
setInterval(function(){
var status = JSRobotCalls.ConnectionStatus();
if(status === JSRobotCalls.ConnectedStates.CONNECTED){
$("#actionCalls").show("fast");
$("#connectionStatus").text("Connected");
}
else if(status === JSRobotCalls.ConnectedStates.DISCONNECTED){
$("#actionCalls").hide();
$("#walkingOn").hide();
$("#connectionStatus").text("Disconnected");
}
else if(status === JSRobotCalls.ConnectedStates.CONNECTING){
$("#connectionStatus").text("Connecting")
$("#actionCalls").hide();
}
else
$("#connectionStatus").text("Failed");
},600);
/**********************************************************
***** Joystick
**********************************************************/
function startJoystick(){
joystick = new VirtualJoystick({
container:document.getElementById("container"),
mouseSupport: true,
limitStickTravel: true,
stickRadius: 50,
strokeStyle:"black"
});
initJoystick();
}
function initJoystick(){
requestAnimationFrame(initJoystick);
if(JSRobotCalls.CurrentActionStatus() === JSRobotCalls.ActionStates.WALKING){
var x = joystick.deltaX();
var y = joystick.deltaY();
// Send X, Y coordinates to Walk Position, 50 < x , y < 50
JSRobotCalls.WalkPosition(x,y);
}
}
/**********************************************************
***** Walking UI Management
**********************************************************/
function toggleWalking() {
JSRobotCalls.ToggleWalk();
if(JSRobotCalls.CurrentActionStatus() === JSRobotCalls.ActionStates.WALKING) {
$("#walkToggle").text("Turn walk off");
$("#walkingOn").show("fast");
startJoystick();
}
else {
$("#walkToggle").text("Turn walk on");
$("#walkingOn").hide();
joystick.destroy();
}
}
/**************************************************
***** Speech *******
/**************************************************/
function SaySomething() {
JSRobotCalls.SayString($("#SpeechToSay").val());
}
/**************************************************
***** Natural Language Processor *******
/**************************************************/
function NaturalLanguageProcessor() {
JSRobotCalls.NaturalLangProc($("#NaturalLanguage").val());
}
</script>
<!--=========================================
=connectionStatus: HROS looks for connectionStatus to update connection status
=buttons to call the actions using the object created on init
=========================================-->
<input class="form-control" id="ipAddress" placeholder="Enter IP Address">
<button name="button" onclick="Connect()">Connect</button>
Connection Status: <label id="connectionStatus">Updating...</label>
<div style="display:none" id="actionCalls">
<button name="button" onclick="JSRobotCalls.PlayAction('stand')">Stand</button>
<button name="button" onclick="JSRobotCalls.PlayAction('sit')">Sit</button>
<button name="button" onclick="JSRobotCalls.PlayAction('wave')">Wave</button>
<button name="button" id="walkToggle" onclick="toggleWalking()">Turn walk on</button>
<input class="form-control" id="SpeechToSay" placeholder="What To Say">
<button name="button" onclick="SaySomething()">Say Something</button>
<input class="form-control" id="NaturalLanguage" placeholder="Natural Language Processor (Hey, Stand up)">
<button name="button" onclick="NaturalLanguageProcessor()">Do it!</button>
</div>
<div id="walkingOn" style="display:none">
<h3>Select anywhere to activate joystick</h3>
<div id="container"></div>
</div>
</body>
</html>