Introduction
Hi! I am currently developing a game project with my group in my university that will integrate a joystick, ESP8266, an FPGA board and will have a Gazebo as a graphical interface! I am responsible for the ESP8266 and PC integration via MQTT and the motion of a virtual drone in Gazebo with ROS 1. The idea is to allow movement of the drone with the joystick, which will be connected to the FPGA board. The board will use the the ESP to communicate with the PC. I would like to document the progress here
The game is based on avoiding obstacles on the map in Gazebo. Gazebo will detect collisions and send the signal back to the FPGA. The FPGA will handle these signals, have the game state machine and transform analog signals to digital. We are using FPGA because it is a mandatory project requirement for the subject.
First part: MQTT to ROS
The first part of the project was to allow the movement of the drone via MQTT. I started using Mosquitto to have a local broker in my PC and allow communication with the ESP8266. Then, I used the Paho Client library to get the messages from the ESP and resend them to a MAVROS topic, all that in a Python script. I used the Ardupilot simulation (SITL) to control my virtual drone. I was able to send
PoseStamped
messages to the topic /mavros/setpoint_position/local
when the ESP sent a message in an /out
topic via MQTT. Basically, I was only reading the state of the BUILT IN LED
and if it was off, the drone moved, otherwise it did nothing. Later, I will read the actual PINS
of the ESP, instead of the LED (only did that because I had nothing connected to the ESP). I did the same for the topic /mavros/setpoint_velocity/cmd_vel
. It worked okay, but now I need to do that for velocity in other axis too!
Second part: Detecting collisions in Gazebo
To detect collisions in Gazebo, I started following this tutorial that teaches how to use the Contact Sensor. I changed the iris_base
model of the copter to have a contact sensor and a collision the size of a box (may change in the future). I am a beginner, so I will take any suggestions.
<collision name="drone_collision">
<geometry>
<box>
<size>0.4 0.4 0.4</size>
</box>
</geometry>
</collision>
<sensor name='my_contact' type='contact'>
<plugin name="my_plugin" filename="libcontact.so"/>
<contact>
<collision>drone_collision</collision>
</contact>
</sensor>
I thought about every obstacle having a sensor, but I decided that it was simpler to just add a sensor to the drone.
Then I did a test. I modified a world and added a static box. After that I made the drone move towards the box, looking for a collision. I monitored it through the topic /gazebo/default/iris/drone_with_camera/iris/base_link/my_contact
and got the expected results when the drone touched the box.
Next steps
I need to find a way to turn the contact message into a signal of 1 or 0 to send back to the ESP and also try to control other axis with the pins of the ESP (and in the future, using the joytstick). The scripts, worlds and models used are here.