Robot Web GUI Guide

tags: apriltag localization

A simple web interface for ROS can be fully practiced after the following tutorials. The rest of the content will be based on these tutorials and give instruction on how to construct this specific webpage for apriltag localization along with what can be improved and be done.

  1. The Construct - Introduction to ROSBridge Server
  2. The Construct - Designing Frontend Webpage
  3. The Construct - Streaming Video (Images) on Webpage

Overall System

The system's foundation is rosbridge_suite package. It provides a simple method to setup a server on the robot and perform communication through a predefined protocol with a web client under a local network.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’

  • Client:
    โ€ƒ A web interface written in HTML and JavaScript on which user can request data from the server and send command to the server via JSON format text file. In order to send and request ROS compatible message, an opensource library, roslibjs, is provided along with rosbridge_suite

Ref: rosbridge_suite

  • Server:

    โ€ƒ A server in our case is the UPboard on the UAV which will run ROS and localization application. It can process the received and sent data from JSON to ROS message and vice versa via rosbridge_library. In order to send and receive at the same time without waiting the client to request, a sebsocket server is considered instead of TCP/UDP.
  • Client & Server Communication:

    โ€ƒ Briefly speaking, the communication can be thought of as a consistent action of writing, sending, and reading a JSON formatted text file between client and server. On the client end, we can assign a topic and message to send and receive through predefined classes in roslibjs. These information will be written to a JSON file following the protocol and be sent to server end. Then the server will process the JSON file to ROS message through rosbridge_library.

Client(Frontend Webpage)

Web server

  • SimpleHTTPServer
    • Single Page Web
    • Usage:
      โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹python -m SimpleHTTPServer

Web Design

HTML Basic Tutorials

Head(Libraries): roslibjs, mjpegcanvas, bootstrap, vue.js

<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Control Panel</title> <script type="text/javascript" src="http://static.robotwebtools.org/roslibjs/current/roslib.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/eventemitter2@5.0.1/lib/eventemitter2.min.js"></script> <script type="text/javascript" src="https://static.robotwebtools.org/mjpegcanvasjs/current/mjpegcanvas.min.js"></script> </head>

Body:

  1. Navigation bar
    User can redirect to different pages with navigation bar. The link of the button can be set with href in attribute tag. Note that with SimpleHTTPServer, only a single page can be created. If multiple pages needed to be setup, you can use FLASK to setup multiple web ip addresses.
    โ€‹โ€‹โ€‹โ€‹ <div> โ€‹โ€‹โ€‹โ€‹ <nav class="navbar navbar-expand-lg navbar-dark bg-secondary text-white"> โ€‹โ€‹โ€‹โ€‹ <a class="navbar-brand" href="#">NCRL</a> โ€‹โ€‹โ€‹โ€‹ <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> โ€‹โ€‹โ€‹โ€‹ <span class="navbar-toggler-icon"></span> โ€‹โ€‹โ€‹โ€‹ </button> โ€‹โ€‹โ€‹โ€‹ <div class="collapse navbar-collapse" id="navbarSupportedContent"> โ€‹โ€‹โ€‹โ€‹ <ul class="navbar-nav mr-auto"> โ€‹โ€‹โ€‹โ€‹ <li class="nav-item active"> โ€‹โ€‹โ€‹โ€‹ <a class="nav-link" href="http://127.0.0.1:5000/">Home<span class="sr-only">(current)</span></a> โ€‹โ€‹โ€‹โ€‹ </div> โ€‹โ€‹โ€‹โ€‹ </nav> โ€‹โ€‹โ€‹โ€‹ </div>
  2. Block with background

    jumbotron class can create a block with background, bg-(color) and text-(color) can change background and text color respectively. As for the supported color, you can check bootstrap4 tutorials on this website.

    โ€‹โ€‹โ€‹โ€‹<div style="padding-top:55px; margin-bottom:20px; padding-bottom:35px;" class="jumbotron jumbotron-fluid bg-info text-white"> โ€‹โ€‹โ€‹โ€‹ <h1 style="padding-bottom:20px;" class="text-center display-3"> NCRL Apriltag Localization </h1> โ€‹โ€‹โ€‹โ€‹ <p class="text-center display-8">This is a web control interface for NCRL Apriltag Localization Project.</p> โ€‹โ€‹โ€‹โ€‹</div>
  3. Grid Layout

    Layout can be created by setting rows and columns. The total number of columns in a single row is 12.

    โ€‹โ€‹โ€‹โ€‹<div class="col-2 jumbotron" style="padding-bottom:2rem; padding-top:1rem; padding-right:1rem; padding-left:1rem; margin-right:1rem;"> โ€‹โ€‹โ€‹โ€‹ <h3>Connection status</h3> โ€‹โ€‹โ€‹โ€‹ <p class="text-muted" v-if="!connected && !failure">Not Connected</p> โ€‹โ€‹โ€‹โ€‹ <p class="text-danger" v-if="failure">Error</p> โ€‹โ€‹โ€‹โ€‹ <p class="text-success" v-if="connected">Connected</p> โ€‹โ€‹โ€‹โ€‹ <label for="uav_server">UAV_server: </label><br/> โ€‹โ€‹โ€‹โ€‹ <input id="uav_server" type="text" v-model="ws_address"/><br/> โ€‹โ€‹โ€‹โ€‹ <button class="btn btn-danger" style="margin-top:10px; margin-bottom:10px;" @click="disconnect" v-if="connected">Disconnect</button> โ€‹โ€‹โ€‹โ€‹ <button class="btn btn-success" style="margin-top:10px; margin-bottom:10px;" @click="connect" v-if="!connected">Connect</button> โ€‹โ€‹โ€‹โ€‹</div>
    1. Common attribute for Vue.js
      • v-if="[variable name]":

        If the corresponding variable in javascriptis true, then the html line will be available. Otherwise, it'll be commented.

      • @click="[function name]":

        When the button is pressed, then the function in method in javascript will be triggered.

      • v-model="[variable name]":

        When a value is given to an input tag, the value will also be assigned to the corresponding variable in javascript.

Web Functionality

JAVASCRIPT Basic Tutorials

  1. Load main.js in GUI.html's body

    โ€‹โ€‹โ€‹โ€‹<script type="text/javascript" src="main.js"></script>
  2. Creat a vue object in main.js

    โ€‹โ€‹โ€‹โ€‹var app = new Vue({ โ€‹โ€‹โ€‹โ€‹ el:'#[id]', โ€‹โ€‹โ€‹โ€‹ data: { โ€‹โ€‹โ€‹โ€‹ test_var: 'test', โ€‹โ€‹โ€‹โ€‹ }, โ€‹โ€‹โ€‹โ€‹ methods: { โ€‹โ€‹โ€‹โ€‹ test: function(){ โ€‹โ€‹โ€‹โ€‹ console.log(this.test_var) โ€‹โ€‹โ€‹โ€‹ } โ€‹โ€‹โ€‹โ€‹ }, โ€‹โ€‹โ€‹โ€‹ updated(){ โ€‹โ€‹โ€‹โ€‹ }, โ€‹โ€‹โ€‹โ€‹})
    El correspond to the id of the division you want the vue object to link to. In our case, it is linked to the 'control_gui' div. Data is the section where you can declare class variables. In methods, you can define functions that can be triggered from the html file. In updated, the lines will be executed once the html(webpage) has any modification. For instance, to implement the function of enabling a button when the input is given, the underlying code should be written in updated. There are other built-in for Vue.js to use beside el, data, methods and updated that you can find in tutorials.
    • methods
    • updated
  3. Streaming video

showCamera: function(){ console.log('set camera method') this.cameraViewer = new MJPEGCANVAS.Viewer({ divID: 'mjpeg', host: '0.0.0.0', width: 640, height: 480, topic: '/iris1/camera_forward/color/image_raw', port: 8080, })
  1. Publishing Topic
// Create a control signal publisher: take off 1, return 2, stop 0 this.control_pub = new ROSLIB.Topic({ ros: this.ros, name: '/control_phase', messageType: 'std_msgs/Int8' }); this.control_signal = new ROSLIB.Message({ data: 0 }) this.control_pub.publish(this.control_signal)
  1. Subscribing Topic
this.location_sub = new ROSLIB.Topic({ ros: this.ros, name: '/location', messageType: 'std_msgs/Int8' }) this.location_sub.subscribe(function(message){ document.getElementById("uav_location").innerHTML = message.data; })

Function in subscribe cannot modify class variable in Vue??

Server (UAV)

  1. Install rosbridge server
sudo apt-get install ros-melodic-rosbridge-server
  1. Install web video server
sudo apt-get install ros-melodic-web-video-server
  1. Configure launch file
<launch> <include file="$(find rosbridge_server)/launch/rosbridge_websocket.launch"> <arg name="port" value="9090"/> </include> <node name="web_video_server1" pkg="web_video_server" type="web_video_server"> <param name="port" type="int" value="8080" /> <param name="address" type="string" value="0.0.0.0" /> <param name="server_threads" type="int" value="1" /> <param name="ros_threads" type="string" value="2" /> <param name="width" type="int" value="1080" /> <param name="height" type="int" value="720" /> <param name="quality" type="int" value="90" /> </node> </launch>

Topic List

Publisher

  • /control_phase
    • messageType: std_msgs/Int8
      take off: 1, return: 2, stop: 0
  • /flight_destination
    • messageType: std_msgs/Int8
      Tag ID
  • /flight_height
    • messageType: std_msgs/Int8

Subscriber

  • /id
  • /status
  • /location
  • /flight_height

Implementation Problem

  1. Cannot access http server from other device
    • Note that permission in FireWall might affect the accessability
    • Use ifconfig to check the device's public ip, that is running the http server. Make sure that the address on other address is the server's device's public ip

Demo

Github

How to Use

  • Launch

    1. roslaunch robot_gui_bridge websocket.launch on terminal 1
    2. cd single_page_gui & python -m SimpleHTTPServer on terminal 2
    3. check ip using ifconfig (inet), check websocket_port on terminal 1 and http_port on terminal 2
    4. on other device, go to ip:http_port
    5. choose GUI.html
  • Connection

    1. In web gui, enter uav port as websocket_port and uav ip as ip

    https://drive.google.com/file/d/1k9Bsl7ri-q1ngy1nkoERPu9QAObmdXtr/view?usp=sharing

  • Control Panel

    1. Unlock
      โ€ƒ After connecting to uav's websocket server and launching web_control, unlock the control panel.
      • status: 'Standby'
        Take off will be enabled
      • status: 'Hovering'
        Return & Land will be enabled
      • status: 'Flying'
        Kill will be enabled (not implemented yet)
    2. Take off
      Land will be enabled
    3. Land
      Take off will be enabled
    4. Cruise Height
      Not implemented yet, NCRL controller doesn't support height command
    5. Turning direction
      Not implemented yet
    6. Hovering Time
      Not implemented yet
    7. Select Destination
      Land & Return will be enabled
      Start will be enabled once the input destination is typed
    8. Indication light
      Green: not in the middle of mission
      Red: In the middle of a mission (Not suggested to send command(control panel is not protected))

Feature of Adding OpenStreetMap using Leaflet

Tutorial

Demo