Web Interface
Back to Flexbot
Contents |
Packages added/made for ROS
- realsense added (For visual data as ROS topics)
- rosbridge added (For connecting ROS to the local network)
- syntax_pkg Made (Checks mission for syntax errors when committing)
- mission_pkg Made (Handles mission files)
Location of important files
Every package can be found in the following directory:
~/flexbot_ws/src/
The cmds and relative path for the mission file can be found in:
~/flexbot_ws/src/include/
Homepage and script related things can be found in:
~/flexbot_ws/robot/
The homepage folder has a softlink to the desired place, so adding new page content will also make it appear on the homepage.
The script autoStartRobot.sh has a link to the directory where every script starts after connecting to the network. Keep in mind that you cannot use the same environment variables since it runs in root (Can't ~). Extra measurements to ensure it doesn't start multiple times has been taken. If more launch files should be added please do so by changing one of these files
~/flexbot_ws/src/base_node_ros/full.launch #This one is preferred ~/flexbot_ws/robot/robot.sh
inside the following directors are the logs, the aaa and aab are the terminal output for the automatic startup script.
~/flexbot_ws/logs/
Usage of web-interface
Go to the robots ip address in the browser, remember to be on the same network!
http://flexbot.local/
If for some reason the robot doesn't work, one could login to the robot and run the killrobot scrip
~/flexbot_ws/robot/./killrobot.sh
followd by the script
~/flexbot_ws/robot/./robot.sh
Side bar
ROS Status
To the left we have the status panels, the top one is the status of ROS and looks like this:
It has 3 states, Checking, Closed and Connected. Remember to refresh each time the robot boots or restarts.
General Status
The next panel is the mission status and looks like this:
This indicates what it is currently doing, like receiving mission, checking for syntax and so forth.
Specific Actions
The third panel is the more in depth detail of what the robot is doing currently. It looks like this:
which says that it is moving 5 units and the command is from line 1.
Start/Stop button
The last element in the side panel is the start and stop bottom, it will automatically go back to the idle state when the mission is complete, if it is not complete and the stop button is pressed it will cancel the mission. The buttons looks like this:
Tabs
Currently there is 3 tabs:
1. The first tab, the "legs" tab, is a table with legs and IMU data
2. The second tab, the "Camera" tab, is a tab with 2 video feeds, one for color and one for depth. Keep in mind that the feed with depth is 16bit gray and thus JavaScript can't present it correctly so everything greater than 255 is getting rounded down to 255.
3. The third tab, the "Mission" tab, holds the mission text area where a new mission can be written and submitted. It can also retrieve the current mission.
Mission commands
Right now there is 3 commands, but none of them has any functionality yet. The first one is mov, which takes one values, the next is stop which takes zero values and the last is turn which takes two values.
Structure of the web-interface
The general structure of the web-interface can be seen in the picture below. The orange box is the robot server, green is the ROS server (Packages written in C++), Purple is the client (Laptop), Red is the homepage files. Most of the the blocks on the server communicate through ROS topics or actions, but some use Mavlink. In the Client side everything is done with HTML, CSS and JavaScript.
Packages in depth
realsense camera
Installing rosrealses
To start of with we run the following command to reconfigure it to ros melodic:
sudo apt install ros-melodic-ddynamic-reconfigure
After that we can follow the guide given here, but i'll write my approach below https://github.com/IntelRealSense/realsense-ros#step-3-install-intel-realsense-ros-from-sources
Here the commands used to download and install the ros package can be seen:
cd ~/flexbot_ws/src/ git clone https://github.com/IntelRealSense/realsense-ros.git cd realsense-ros/ git checkout `git tag | sort -V | grep -P "^\d+\.\d+\.\d+" | tail -1` cd ~/flexbot_ws
At last we build and source it using
catkin_make source ~/flexbot_ws/devel/setup.sh
To launch it use, remember to source or be in the right directory before launch
roslaunch realsense2_camera rs_flexbot.launch
roslibjs
Installing rosbridge
This library makes it possible to use ros commands with javascript over a chosen port. The first two lines goes to the source in the catkin workspace and creates a package for ros:
cd ~/flexbot_ws/src catkin_create_pkg robot_gui_bridge rosbridge_server
Next we install the rosbridge package
apt-get install ros-melodic-rosbridge-server
Now we create the launch file directory and the file used for launch
mkdir ~/flexbot_ws/src/robot_gui_bridge/launch touch ~/flexbot_ws/src/robot_gui_bridge/launch/websocket.launch
Now at last we write the the necessary launch commands into the file and source it so we can use it from any directory om this terminal:
echo '<launch> <include file="$(find rosbridge_server)/launch/rosbridge_websocket.launch"/></launch>' >> ~/flexbot_ws/src/robot_gui_bridge/launch/websocket.launch source ~/flexbot_ws/devel/setup.bash
To test if it works run and look for errors:
roslaunch robot_gui_bridge websocket.launch
Setting up the connection
First check if the following command gives multiple ip's if so find a way to extract the correct one:
hostname -I
Now to setup the client, which is the computer not on the robot, write the following 3 lines in your "~/.bashrc" script:
# write these inside ~/.bashrc export ROS_HOSTNAME='hostname -I' export ROS_IP="hostname -I" export ROS_MASTER_URI='http://flexbot.local:11311/'
Now to setup the server, which is the computer on the robot, write the following 2 lines in the "~/.bashrc" script:
# write these inside ~/.bashrc export ROS_IP=flexbot.local export ROS_MASTER_URI='http://flexbot.local:11311/'
finalizing the server
Install apache to be able to access remotely :
sudo apt install apache2
Now insert the desired HTML, CSS and javascript files into
/var/www/html/
At last create a script inside
/etc/network/if-up.d/
Which will be executed when connecting to a network. To ensure it not happening multiple times a flag is set when run the first time. The script can be seen in
/etc/network/if-up.d/robotAutoStart.sh
and has a hardlink file in ~/flexbot_ws to make it easily accessible
syntax package
Not much to say, the package files are located inside
~/flexbot_ws/src/syntax_pkg/
and it checks for valid syntax in the submitted code. If there is error it returns the error type and where. If successful it saves the code in
~/flexbot_ws/mission.txt
Furthermore to add new commands simply add the word and how many arguments it takes inside the struct declaration in the file:
~/flexbot_ws/src/include/cmds.h
and build the code again
Adding Commands
To add a command to the syntax checking simply go to
~/flexbot_ws/src/include/cmds.h
and add the command to the vector called cmds. It has 2 values a name of the command and how many attributes it has. After adding it simply compile the code again
mission package
The package files are located inside
~/flexbot_ws/src/mission_pkg/
This package hasn't got any specific use now since it at the moment only reads the mission, runs the corresponding function and returns what line it is running. It is possible to cancel a mission but not to pause and resume it.
Adding commands
To add a command to the mission go into the source of the mission package and add the command-check to the main while loop in the callback function and add a corresponding function. Remember to add this command to the syntax too inside cmds.h.
TODO
Add actual functionality to each command in the mission package