Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

README.md 7.07 KB
Newer Older
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
1 2 3 4 5 6
# Semi-Autonomous Drone Pilot

This ROS package is for a semi-autonomous drone pilot for the Parrot Bebop 2 using image processing (OpenCV) and unsupervised machine learning (Clustering).

## Quick Intro

jad's avatar
jad committed
7 8 9
This project has many parts,The first one is moving the drone at a constant velocity.
The Second part is built on the first one , is used move the drone inside a hallway.
The third part, is used to detect openned doors.
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
10

jad's avatar
jad committed
11
## Use This Package
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
12 13
First Clone this repo in your catkin workspace
```
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
14
$ git clone https://gitlab.centralesupelec.fr/obeid_jad/dorne_project.git drone_project
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
15 16 17 18 19
```
Build your workspace
```
$ catkin build
```
jad's avatar
jad committed
20 21
## Moving Drone
To do this you need to launch the VelLaunch.launch 
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
22 23

```
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
24
$ roslaunch drone_project VelLaunch.launch
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
25
```
jad's avatar
jad committed
26
First start with sending a reset command to this modules by sending any integer to the topics ```/reset_cmd_x```,```/reset_cmd_y``` and ```/reset_cmd_z```.
jad's avatar
jad committed
27 28
 
And then publish to ```/vel_in_x``` , ``` /vel_in_y```  and ```/vel_in_z``` the velocities you want the drone to move with.
jad's avatar
jad committed
29

jad's avatar
jad committed
30
The frequency of sending data to the drone is equal to 5Hz.
jad's avatar
jad committed
31

jad's avatar
jad committed
32
### Example Moving at constant Velocity:
jad's avatar
jad committed
33
The ``` move_tester.py ``` file is an example of moving with a constant velocity.
jad's avatar
jad committed
34

jad's avatar
jad committed
35 36 37 38 39 40 41
## Using The Interface
To run the other parts of the project, you need to launch the file  ```Sequencer.launch```.

```
$ roslaunch drone_project Sequencer.launch
```
You will get an interface, that will let you choose the mode you want, you can click on Doors, to find opened doors and pass through them, or Hallway to launch the autonomous navigation in the Hallways.
jad's avatar
jad committed
42

jad's avatar
jad committed
43
## Customize this project
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
44

jad's avatar
jad committed
45
### Nodes
jad's avatar
jad committed
46

jad's avatar
jad committed
47
Each node in this project have a unique name, used to activate it.
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
48

jad's avatar
jad committed
49
Some of the nodes also have the ability to send back confirmation after reaching their target .
Obeid Jad Abdul Rahman's avatar
Obeid Jad Abdul Rahman committed
50

jad's avatar
jad committed
51
Like for example the node responsible of searching for openned doors, it will send a confirmation when a door is detected.
jad's avatar
jad committed
52

jad's avatar
jad committed
53
### Create your sequence
jad's avatar
jad committed
54

jad's avatar
jad committed
55
In this project, you can run your own sequence, the sequence is a python list that has a specific format.
jad's avatar
jad committed
56

jad's avatar
jad committed
57
The Format is the following 
jad's avatar
jad committed
58

jad's avatar
jad committed
59
```python
jad's avatar
jad committed
60 61
new_seq_list = ["mode_name",[["node_1","node_2"],["cond_1","cond_2"]],...]
self.new_seq = Sequencer(new_seq_list)
jad's avatar
jad committed
62
```
jad's avatar
jad committed
63

jad's avatar
jad committed
64 65
Where ```mode_name``` is the string that when we receive on the ```/mode``` topic , the sequence will run.
Where ```node_1``` and ```node_2``` are the names of nodes that will be activated in the phase 1 of this sequence, and ```cond_1``` and ```cond_2``` are the names of nodes confirmations we are waiting for to continue to the next step.
jad's avatar
jad committed
66

jad's avatar
jad committed
67
### Running the sequence 
jad's avatar
jad committed
68

jad's avatar
jad committed
69
To run the sequence, you need to add 2 lines of code to the ```Sequencer.py``` class .
jad's avatar
jad committed
70

jad's avatar
jad committed
71 72
```python
def enter_loop(self,ros_data):
jad's avatar
jad committed
73 74 75
    ####Code
    #if(self.mode == self.new_seq.get_mode()):
        #self.new_seq.seq_fun()
jad's avatar
jad committed
76
```
jad's avatar
jad committed
77
Copy and paste these 2 lines, and after that Uncomment them and change the new_seq to the name of the sequence you've defined.
jad's avatar
jad committed
78

jad's avatar
jad committed
79
And now, whenever the mode is received in the mode topic, the sequence will run.
jad's avatar
jad committed
80

jad's avatar
jad committed
81 82
And to get sure your sequence will be reset after Init,
```python
jad's avatar
jad committed
83 84 85 86 87 88 89 90 91 92 93 94
def read_mode(self,ros_data):
    self.mode = ros_data.data
    if(self.mode == "init"):
        msg = actMsg()
        msg.node_name = "reset"
        msg.activate = True
        self.actv_publisher.publish(msg)
        self.doors_seq = Sequence(self.doors_seq_list)
        self.hallways_seq = Sequence(self.hallway_seq_list)
        #self.new_seq = Sequence(self.new_seq_list)
    else:
        self.loop_pub.publish(3)
jad's avatar
jad committed
95
```
jad's avatar
jad committed
96
Copy the ```self.new_seq = Sequence(self.new_seq_list)``` line , paste it and uncomment int and replace the ```new_seq``` by the name of your sequence.
jad's avatar
jad committed
97

jad's avatar
jad committed
98
### Creating your own node
jad's avatar
jad committed
99

jad's avatar
jad committed
100
You can also create you own node in this project.
jad's avatar
jad committed
101

jad's avatar
jad committed
102 103 104 105 106 107 108 109 110
To do so , and if you want your node to be able to work properly in the sequencer, you have to inherit from the class ```NodeActivate```
```python
from activation_class import NodeActivate
class myNewNode(NodeActivate)
    def __init__(self):
        super(myNewNode,self).__init__("newNodeName")
        #Your Code
```
This means that your node has the name ```newNodeName``` and this is the name that will be used to activate it seperatly if you want (Check section)
jad's avatar
jad committed
111

jad's avatar
jad committed
112
and to check if the node is activated or not, the variable ```self.activate``` is true when node activated and false otherwise.
jad's avatar
jad committed
113

jad's avatar
jad committed
114 115 116 117 118 119 120
As mentionned above, the node may need to send confirmation after reaching the target, to do so, you have to inherit from the class ```returnResp```.

```python
from activation_class import NodeActivate,returnResp
class myNewNode(NodeActivate,returnResp)
    def __init__(self):
        super(myNewNode,self).__init__("newNodeName")
jad's avatar
jad committed
121
```
jad's avatar
jad committed
122 123 124
And to send the confirmation use the following function,
```python
self.send_conf()
jad's avatar
jad committed
125 126
```

jad's avatar
jad committed
127
## Use project outside sequencer
jad's avatar
jad committed
128

jad's avatar
jad committed
129
This project can be used obviously outside the sequencer (You can define your own launch file and run the nodes you want).
jad's avatar
jad committed
130

jad's avatar
jad committed
131
But before doing that, there is few things you need to know.
jad's avatar
jad committed
132

jad's avatar
jad committed
133
### Activation
jad's avatar
jad committed
134

jad's avatar
jad committed
135
To activate a node , you have to publish a specific type of message called ```actMsg``` on the topic ```/activations```.
jad's avatar
jad committed
136

jad's avatar
jad committed
137 138 139 140 141 142 143 144 145 146
This message contains 2 fields, a string which is the name of the node you want to activate, the second field is a boolean , which is the activation.

```python
from drone_project.msg import actMsg
import rospy
pub = rospy.Publisher("/activations",actMsg,queue_size=1)
msg = actMsg()
msg.node_name = "nodeToAct" #Name of the node to activate
msg.activate = True #False to deactivate
pub.publish(msg)
jad's avatar
jad committed
147
```
jad's avatar
jad committed
148
### Getting Response
jad's avatar
jad committed
149

jad's avatar
jad committed
150
As mentionned above also, some nodes send confirmation whenever they reach the target. A node doing this will publish its name to the topic ```/return_resp```.
jad's avatar
jad committed
151

jad's avatar
jad committed
152
## Some Useful nodes
jad's avatar
jad committed
153

jad's avatar
jad committed
154 155
### Distance Estimation using camera
This project contains a node able to estimate distances of moving objects using dense optical flow with the "Gunnar Farneback" algorithm.
jad's avatar
jad committed
156

jad's avatar
jad committed
157
```nodeName = checkDoors```
jad's avatar
jad committed
158

jad's avatar
jad committed
159
To use this module you can just run the ```testDenseOpticalFlow.py``` node and activate it.
jad's avatar
jad committed
160

jad's avatar
jad committed
161 162 163 164 165
To view the histogram showing distances, run the rqt_image_view and choose the topic ```/image_graph```
```
$ rqt_image_view
```
Whenever an opened door is detected, this node will publish to the ```/return_resp``` Topic.
jad's avatar
jad committed
166

jad's avatar
jad committed
167
### Vanishing point detection
jad's avatar
jad committed
168

jad's avatar
jad committed
169
This project contains a node able to detect the vanishing point in a Hallway using DBSCAN clustering algorithm.
jad's avatar
jad committed
170

jad's avatar
jad committed
171
```nodeName = detectVanish```
jad's avatar
jad committed
172

jad's avatar
jad committed
173
To use this you need to run the ```image_proc.py``` node and activate it.
jad's avatar
jad committed
174

jad's avatar
jad committed
175
This node does not publish on ```/return_resp``` but it will publish the x of this point to the topic ```/centroids```.
jad's avatar
jad committed
176

jad's avatar
jad committed
177
### Turn to a specified angle
jad's avatar
jad committed
178

jad's avatar
jad committed
179
This project contains a node able to turn the drone to a specific angle.
jad's avatar
jad committed
180

jad's avatar
jad committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
```nodeName = turnAng```

To use this you need to import the ```TurnAngClass``` class and do like the following exemple :
```python
#!/usr/bin/env python
from TurnAngClass import TurnDrone
      
def main(args):
    rospy.init_node('TurnDrone', anonymous=True)
    sc = TurnDrone(90) ## the angle you want .
    #rospy.init_node('send_command', anonymous=True)
    rospy.spin()
if __name__ == '__main__':
    main(sys.argv)
```
Whenever the turn is done, this node will publish to the ```/return_resp``` Topic.