--- /dev/null
+function init() {
+ var ros = new ROSLIB.Ros();
+ ros.connect('ws://wildthumper:9090');
+ var isDragging = false;
+
+ ros.on('connection', function() {
+ information.alerts.push({message: "Connected to websocket server.", success: true});
+ });
+
+ ros.on('error', function(error) {
+ information.alerts.push({message: "Error connecting to websocket server.", danger: true});
+ });
+
+ ros.on('close', function() {
+ information.alerts.push({message: "Connection to websocket server closed.", info: true});
+ });
+
+ //tfClient.subscribe('base_link', function(tf) {
+ // var now = new Date();
+ // $("#pose").text(now.toLocaleTimeString() + ": (" + tf.translation.x + ", " + tf.translation.y + ")");
+
+ // robotMarker.x = tf.translation.x;
+ // robotMarker.y = -tf.translation.y;
+ // robotMarker.rotation = viewer2D.scene.rosQuaternionToGlobalTheta(tf.rotation);
+ //});
+ var poseTopic = new ROSLIB.Topic({ros: ros, name: '/robot_pose', messageType: 'geometry_msgs/Pose'});
+ var sensorTopic = new ROSLIB.Topic({ros: ros, name: '/sensors', messageType: 'wild_thumper/Sensor'});
+ var batteryTopic = new ROSLIB.Topic({ros: ros, name: '/battery', messageType: 'sensor_msgs/BatteryState'});
+ var ledStripeTopic = new ROSLIB.Topic({ros: ros, name: '/led_stripe', messageType: 'wild_thumper/LedStripe'});
+ var cmdVelTopic = new ROSLIB.Topic({ros: ros, name: '/teleop/cmd_vel', messageType: 'geometry_msgs/Twist'});
+
+ poseTopic.subscribe(function(message) {
+ var now = new Date();
+ $("#pose").text(now.toLocaleTimeString() + ": (" + message.position.x + ", " + message.position.y + ")");
+ });
+
+ sensorTopic.subscribe(function(message) {
+ sensors.light = message.light;
+ sensors.temp = message.temp.toFixed(1);
+ sensors.humidity = message.humidity;
+ sensors.pressure = message.pressure.toFixed(1);
+ sensors.co = message.co;
+ });
+
+ batteryTopic.subscribe(function(message) {
+ power.voltage = message.voltage.toFixed(1);
+ power.current = message.current.toFixed(1);
+ });
+
+ viewer2D = new ROS2D.Viewer({
+ divID: 'map',
+ width: 640,
+ height: 480,
+ background: "#efefef"
+ });
+ $('#map')
+ .bind('mousewheel', function(e) {
+ if (e.originalEvent.wheelDelta/120 > 0) {
+ viewer2D.scaleToDimensions(10, 10)
+ } else {
+ viewer2D.scaleToDimensions(5, 5)
+ }
+ })
+ .mousedown(function() {
+ isDragging = true;
+ mousePreX = undefined;
+ mousePreY = undefined;
+ })
+ .mouseup(function() {
+ isDragging = false;
+ })
+ .mousemove(function(event) {
+ if (isDragging) {
+ if (mousePreX != undefined && mousePreY != undefined) {
+ var diffX = event.pageX - mousePreX;
+ var diffY = event.pageY - mousePreY;
+ console.log("Moving viewer2D by " + diffX + ", " + diffY);
+ viewer2D.shift(diffX, diffY);
+ }
+ mousePreX = event.pageX;
+ mousePreY = event.pageY;
+ }
+ });
+
+ // Setup the nav client.
+ NAV2D.OccupancyGridClientNav({
+ ros : ros,
+ rootObject : viewer2D.scene,
+ viewer : viewer2D,
+ serverName : '/move_base'
+ });
+
+ // Initialize the teleop.
+ teleop = new KEYBOARDTELEOP.Teleop({
+ ros : ros,
+ topic : '/teleop/cmd_vel'
+ });
+
+ // Create a UI slider using JQuery UI.
+ $('#speed-slider').slider({
+ range : 'min',
+ min : 0.10,
+ max : 1.0,
+ step : 0.05,
+ value : 0.5,
+ slide : function(event, ui) {
+ // Change the speed label.
+ speed_label.speed = ui.value;
+ // Scale the speed.
+ teleop.scale = (ui.value * 2);
+ }
+ });
+
+ // Set the initial speed.
+ teleop.scale = ($('#speed-slider').slider('value') * 2);
+
+ $('.led_color').minicolors({
+ control: 'wheel',
+ format: 'rgb',
+ defaultValue: '#000000',
+ change: function(value) {
+ var rgb = $(this).minicolors('rgbObject');
+ var nums = jQuery.parseJSON($(this).prop("name"));
+ var msg = new ROSLIB.Message({
+ leds: []
+ });
+ jQuery.each(nums, function(i, num) {
+ msg["leds"].push({
+ num: num,
+ red: parseInt(rgb.r*127/255),
+ green: parseInt(rgb.g*127/255),
+ blue: parseInt(rgb.b*127/255)
+ })
+ });
+ ledStripeTopic.publish(msg);
+ }
+ });
+
+ function setSpeed(trans, rot) {
+ var msg = new ROSLIB.Message({
+ linear: {
+ x : trans,
+ y : 0,
+ z : 0
+ },
+ angular: {
+ x : 0,
+ y : 0,
+ z : rot
+ },
+ });
+ cmdVelTopic.publish(msg);
+ }
+
+ $('.cmd_vel_circle')
+ .bind('mousedown touchstart', function(e) {
+ isDragging = true;
+ })
+ .bind('mouseup touchend mouseleave', function(e) {
+ isDragging = false;
+ setSpeed(0, 0);
+ })
+ .bind('mousemove touchmove', function(e) {
+ if (isDragging) {
+ // absolute click position
+ var X,Y;
+ if (e.originalEvent.touches) {
+ X = e.originalEvent.touches[0].pageX;
+ Y = e.originalEvent.touches[0].pageY;
+ } else {
+ X = e.pageX;
+ Y = e.pageY;
+ }
+ // relative click position
+ var Xrel = X - this.offsetLeft - $(this).width()/2;
+ var Yrel = Y - this.offsetTop - $(this).height()/2;
+ // scale to -1..+1
+ var trans = -Yrel / ($(this).height()/2);
+ var rot = -Xrel / ($(this).width()/2);
+ setSpeed(trans, rot*3);
+ }
+ });
+
+ information = new Vue({
+ el: '#information',
+ data: {
+ alerts: [],
+ },
+ methods: {
+ classObject: function(id) {
+ return {
+ "alert-success": this.alerts[id].success,
+ "alert-danger": this.alerts[id].danger,
+ "alert-info": this.alerts[id].info
+ }
+ }
+ }
+ })
+
+ sensors = new Vue({
+ el: '#sensors',
+ data: {light: '', temp: '', humidity: '', pressure: '', co: ''}
+ })
+
+ power = new Vue({
+ el: '#power',
+ data: {
+ voltage: '',
+ current: '',
+ }
+ })
+
+ speed_label = new Vue({
+ el: '#speed-label',
+ data: {
+ speed: $('#speed-slider').slider('value'),
+ }
+ })
+}
<link rel="stylesheet" href="assets/stylesheets/bootstrap.min.css">
<link rel="stylesheet" href="assets/stylesheets/jquery-ui.css">
<link rel="stylesheet" href="assets/stylesheets/jquery.minicolors.css">
+ <link rel="stylesheet" href="assets/stylesheets/application.css">
- <style>
- .minicolors-theme-default.minicolors { margin: 5px; }
- .bottom-leds > .minicolors-theme-default.minicolors { margin: 5px 0; }
- .top-leds > .minicolors-theme-default.minicolors { margin-top: 70px; }
- .wt-icon {background: url('assets/images/wt_top.png'); background-size: cover; background-size: 100%; background-repeat: no-repeat; background-position: center; height: 260px;}
- .cmd_vel_circle {
- height: 250px;
- width: 250px;
- background-color: #bbb;
- border-radius: 50%;
- display: inline-block;
- }
- </style>
-
- <script type="text/javascript">
- function init() {
- var ros = new ROSLIB.Ros();
- ros.connect('ws://wildthumper:9090');
- var isDragging = false;
-
- ros.on('connection', function() {
- information.alerts.push({message: "Connected to websocket server.", success: true});
- });
-
- ros.on('error', function(error) {
- information.alerts.push({message: "Error connecting to websocket server.", danger: true});
- });
-
- ros.on('close', function() {
- information.alerts.push({message: "Connection to websocket server closed.", info: true});
- });
-
- //tfClient.subscribe('base_link', function(tf) {
- // var now = new Date();
- // $("#pose").text(now.toLocaleTimeString() + ": (" + tf.translation.x + ", " + tf.translation.y + ")");
-
- // robotMarker.x = tf.translation.x;
- // robotMarker.y = -tf.translation.y;
- // robotMarker.rotation = viewer2D.scene.rosQuaternionToGlobalTheta(tf.rotation);
- //});
- var poseTopic = new ROSLIB.Topic({ros: ros, name: '/robot_pose', messageType: 'geometry_msgs/Pose'});
- var sensorTopic = new ROSLIB.Topic({ros: ros, name: '/sensors', messageType: 'wild_thumper/Sensor'});
- var batteryTopic = new ROSLIB.Topic({ros: ros, name: '/battery', messageType: 'sensor_msgs/BatteryState'});
- var ledStripeTopic = new ROSLIB.Topic({ros: ros, name: '/led_stripe', messageType: 'wild_thumper/LedStripe'});
- var cmdVelTopic = new ROSLIB.Topic({ros: ros, name: '/teleop/cmd_vel', messageType: 'geometry_msgs/Twist'});
-
- poseTopic.subscribe(function(message) {
- var now = new Date();
- $("#pose").text(now.toLocaleTimeString() + ": (" + message.position.x + ", " + message.position.y + ")");
- });
-
- sensorTopic.subscribe(function(message) {
- sensors.light = message.light;
- sensors.temp = message.temp.toFixed(1);
- sensors.humidity = message.humidity;
- sensors.pressure = message.pressure.toFixed(1);
- sensors.co = message.co;
- });
-
- batteryTopic.subscribe(function(message) {
- power.voltage = message.voltage.toFixed(1);
- power.current = message.current.toFixed(1);
- });
-
- viewer2D = new ROS2D.Viewer({
- divID: 'map',
- width: 640,
- height: 480,
- background: "#efefef"
- });
- $('#map')
- .bind('mousewheel', function(e) {
- if (e.originalEvent.wheelDelta/120 > 0) {
- viewer2D.scaleToDimensions(10, 10)
- } else {
- viewer2D.scaleToDimensions(5, 5)
- }
- })
- .mousedown(function() {
- isDragging = true;
- mousePreX = undefined;
- mousePreY = undefined;
- })
- .mouseup(function() {
- isDragging = false;
- })
- .mousemove(function(event) {
- if (isDragging) {
- if (mousePreX != undefined && mousePreY != undefined) {
- var diffX = event.pageX - mousePreX;
- var diffY = event.pageY - mousePreY;
- console.log("Moving viewer2D by " + diffX + ", " + diffY);
- viewer2D.shift(diffX, diffY);
- }
- mousePreX = event.pageX;
- mousePreY = event.pageY;
- }
- });
-
- // Setup the nav client.
- NAV2D.OccupancyGridClientNav({
- ros : ros,
- rootObject : viewer2D.scene,
- viewer : viewer2D,
- serverName : '/move_base'
- });
-
- // Initialize the teleop.
- teleop = new KEYBOARDTELEOP.Teleop({
- ros : ros,
- topic : '/teleop/cmd_vel'
- });
-
- // Create a UI slider using JQuery UI.
- $('#speed-slider').slider({
- range : 'min',
- min : 0.10,
- max : 1.0,
- step : 0.05,
- value : 0.5,
- slide : function(event, ui) {
- // Change the speed label.
- speed_label.speed = ui.value;
- // Scale the speed.
- teleop.scale = (ui.value * 2);
- }
- });
-
- // Set the initial speed.
- teleop.scale = ($('#speed-slider').slider('value') * 2);
-
- $('.led_color').minicolors({
- control: 'wheel',
- format: 'rgb',
- defaultValue: '#000000',
- change: function(value) {
- var rgb = $(this).minicolors('rgbObject');
- var nums = jQuery.parseJSON($(this).prop("name"));
- var msg = new ROSLIB.Message({
- leds: []
- });
- jQuery.each(nums, function(i, num) {
- msg["leds"].push({
- num: num,
- red: parseInt(rgb.r*127/255),
- green: parseInt(rgb.g*127/255),
- blue: parseInt(rgb.b*127/255)
- })
- });
- ledStripeTopic.publish(msg);
- }
- });
-
- function setSpeed(trans, rot) {
- var msg = new ROSLIB.Message({
- linear: {
- x : trans,
- y : 0,
- z : 0
- },
- angular: {
- x : 0,
- y : 0,
- z : rot
- },
- });
- cmdVelTopic.publish(msg);
- }
-
- $('.cmd_vel_circle')
- .bind('mousedown touchstart', function(e) {
- isDragging = true;
- })
- .bind('mouseup touchend mouseleave', function(e) {
- isDragging = false;
- setSpeed(0, 0);
- })
- .bind('mousemove touchmove', function(e) {
- if (isDragging) {
- // absolute click position
- var X,Y;
- if (e.originalEvent.touches) {
- X = e.originalEvent.touches[0].pageX;
- Y = e.originalEvent.touches[0].pageY;
- } else {
- X = e.pageX;
- Y = e.pageY;
- }
- // relative click position
- var Xrel = X - this.offsetLeft - $(this).width()/2;
- var Yrel = Y - this.offsetTop - $(this).height()/2;
- // scale to -1..+1
- var trans = -Yrel / ($(this).height()/2);
- var rot = -Xrel / ($(this).width()/2);
- setSpeed(trans, rot*3);
- }
- });
-
- information = new Vue({
- el: '#information',
- data: {
- alerts: [],
- },
- methods: {
- classObject: function(id) {
- return {
- "alert-success": this.alerts[id].success,
- "alert-danger": this.alerts[id].danger,
- "alert-info": this.alerts[id].info
- }
- }
- }
- })
-
- sensors = new Vue({
- el: '#sensors',
- data: {light: '', temp: '', humidity: '', pressure: '', co: ''}
- })
-
- power = new Vue({
- el: '#power',
- data: {
- voltage: '',
- current: '',
- }
- })
+ <script src="assets/javascripts/jquery-3.3.1.min.js"></script>
+ <script src="assets/javascripts/popper.min.js"></script>
+ <script src="assets/javascripts/bootstrap.min.js"></script>
+ <script src="assets/javascripts/jquery-ui.min.js"></script>
+ <script src="assets/javascripts/easeljs.min.js"></script>
+ <script src="assets/javascripts/eventemitter2.js"></script>
+ <script src="assets/javascripts/roslib.js"></script>
+ <script src="assets/javascripts/ros2d.js"></script>
+ <script src="assets/javascripts/nav2d.js"></script>
+ <script src="assets/javascripts/keyboardteleop.js"></script>
+ <script src="assets/javascripts/jquery.minicolors.js"></script>
+ <script src="assets/javascripts/vue.js"></script>
+ <script src="assets/javascripts/application.js"></script>
- speed_label = new Vue({
- el: '#speed-label',
- data: {
- speed: $('#speed-slider').slider('value'),
- }
- })
- }
- </script>
<title>Wild Thumper control</title>
</head>
<body onload="init()">
</div>
</div>
</div>
- <script src="assets/javascripts/jquery-3.3.1.min.js"></script>
- <script src="assets/javascripts/popper.min.js"></script>
- <script src="assets/javascripts/bootstrap.min.js"></script>
- <script src="assets/javascripts/jquery-ui.min.js"></script>
- <script src="assets/javascripts/easeljs.min.js"></script>
- <script src="assets/javascripts/eventemitter2.js"></script>
- <script src="assets/javascripts/roslib.js"></script>
- <script src="assets/javascripts/ros2d.js"></script>
- <script src="assets/javascripts/nav2d.js"></script>
- <script src="assets/javascripts/keyboardteleop.js"></script>
- <script src="assets/javascripts/jquery.minicolors.js"></script>
- <script src="assets/javascripts/vue.js"></script>
</body>
</html>