Autonomous controller - AnandaNN/M100_DTU_ROS GitHub Wiki
Autonomous Controller (dtu_controller)
ContactController (.cpp)
The contact controller is a class that will handle the control of the drone once the wall is touched. It is a class you can create in one of your other nodes (we use it in the mission node). It subscribes to the rosserial to read from the switch. Initialize it after the creation to set up all the topics. Because you create a ContactController object it is easy to start and stop it from the mission with just a function call.
As the ContactController is sending the flight control values to the DJI remember to stop any other control values before starting the controller. The controller runs until stopped or if contact is lost. In that case no more values are sent, therefore you should monitor the status of the controller while in use.
As the controller runs on callbacks it is important to remember keep ROS spinning from the node that is handling the contact controller object.
When disengaging the controller will set the reference to 0 degrees to make the transition to the regular controller smooth.
If contact is lost (switch not pressed) the controller will pitch forward to regain contact for up to 1 second. If contact is not made within 1 second the controller stops and status is changed to reflect this.
Wall estimation (RANSAC)
wallPositionEstimation.py
The wall estimation done to have autonomous flight is used to estimate the perpendicular distance to the wall and the horizontal angle to the wall. To do this a laser scanner is used to get polar distance measurements. To calculate the desired distance and angle we use ransac to estimate lines in the dataset. Then from a basic assumption that we are facing a plane the line that is closest to perpendicular is chosen.
Before the lines are estimated the data is transformed to account for the rotation of the drone (roll and pitch).
With the line estimated the line the intersection point between that line and the drone can be calculated and the distance and angle can be found.
With this calculated the transformation from wall to laserscanner and to drone center is found and published and can be view in RViz.
The loop runs at 40Hz (like the laserscanner)
Position control
Position control is handled by simple PID controllers on X, Y, Z and yaw. It uses the DJI control value topic that accepts X and Y displacements, Z-velocity and Yaw-rate.