# xiaoqiang tutorial (10) use kinect for autonomous mobile and obstacle avoidance

Xiaoqiang Homepage

Click to watch the demo video

## principle:

The freenct_stack package provides a kinect driver, and its published point cloud is transformed into an obstacle grid distribution image by image_pipeline. After the nav_test software package starts the navigation program, it analyzes the obstacle distribution map automatically, and then moves autonomously according to the target navigation point published by the rviz.

## Steps：

### 1. Configure the hosts file of the host and the local virtual machine so that the two computer can access the corresponding ros data.

#### 1.a Configure the local virtual machine

sudo gedit /etc/hosts


Replace the ip address in the figure below with the actual value of the platform

#### 1.b Configuration Xiaoqiang Host

ssh xiaoqiang@192.168.0.101 -X
sudo gedit /etc/hosts


Replace the ip address in the following figure with the actual value of the virtual machine and change the host name to the virtual machine name

### 2. Open three windows in the local virtual machine, respectively ssh login Xiaoqiang host, start the relevant software package mentioned in the principle section

#### 2.b Start the kinect driver in the first window

For kinect v1

roslaunch freenect_launch kinect-xyz.launch


For Kinect v2

roslaunch kinect2_bridge kinect2-xyz.launch


For astrapro

roslaunch astra_launch astrapro.launch


#### 2.c Set kinect angle in the second window, this angle is not arbitrary

For kinect v1

rostopic pub /set_tilt_degree std_msgs/Int16 '{data: -19}' -1


For Kinect v2

Since the kinect v2 does not have a pitch angle motor, manually adjust the kinect v2 to the maximum depression angle

For astrapro

Since the astrapro does not have a pitch angle motor, manually adjust the astrapro to the maximum depression angle.

#### 2.e Launch the platform navigation program in the third window

roslaunch nav_test fake_move_base_blank_map.launch


### 3.Open a new window in the local virtual machine and start rviz

#### 3.a After joining ros LAN, open rviz

export ROS_MASTER_URI=http://xiaoqiang-desktop:11311
rviz


Note: If Xiaoqiang's model cannot be displayed, Xiaoqiang model package should be installed locally.

#### 3.e Xiaoqiang reaches the target point, please continue to try other positions. This tutorial ended.

Please insert the kinect data cable into the blue host USB3.0 port of xiaoqiang to ensure the normal operation of the driver. Model 1473 kinect users please refer to the preparation method in tutorial (9).

If xiaoqiang has been moving backwards, it can be seen in rviz that there is a black area in front of xiaoqiang, and the black area has been following Xiaoqiang's movement. This situation indicates that the kinect installation or kienct angle is not in right. Please check the kinect mounting bracket, remove the kienct film and re-execute the instructions in the tutorial.

### FAQ

Q: Map shows normally and the car can also be remote controlled, although published the target point vai rviz to the car , the car does not move to the target point.
A: In general, this problem is a network setup problem. This tutorial requires the hosts record to be set up between the xiaoqiang and the local machine, and to be able to access each other directly. After setting up the IP record, you can ping each other on the xiaoqiang and local computer to check the network connection. For example type following cmd on local machine

ping xiaoqiang-desktop


Enter the following cmd on xiaoqiang

ping ubuntu # Suppose your computer name is ubuntu


If we cannot ping between the two successfully, then you need check your network settings.