A ROS package which can read video stream from Zenmuse-X3-Camera on M100 and publish it as sensor_msgs/Image. Must be compiled and launched on Manifold.
Two types for running this package: manully launch ROS node or server/client type. First one is simple, and second one is more convenient.
This package is based on dji_sdk_manifold_read_cam and dji-sdk/Manifold-Cam. Read their documents and codes before continuing.
Manifold will cut off video signal between gimbal camera and video transmitter, so you will NOT see the live video on the DJI GO App, until the camera driver is launched in transfer mode. But this is not convenient if you don't want to bring a laptop with the drone, and ssh to manifold, and launch the driver manually to view video in DJI GO App.
Obviously, it's better to run the driver as a background daemon at system startup than run it manually every time. However, the driver is not reentrant, which means that if a background driver instance is running, we can not run another driver instance to get the video (and show/publish to ros).
In order to solve this problem, a server which provides video acqusition functionality is provided in this package. And a manually launched driver with ros interface is also provided.
For manually launched driver, the source code is src/m100_x3_node.cpp. This file will initialize the X3 camera driver, read video data and publish the data as sensor_msgs/Image. Since the initialization need root privilege, you must excute sudo -s
to grant root privilege before rosrun/roslaunch.
For server type driver, the server source code is src/server/src/x3server.cpp. The server will be launched automatically by the upstart system in ubuntu after installation. The server will initialize the x3 camera driver, and open a TCP port at localhost:40042
, blocked at socket accept function. When a client is connected, the accept function will return, and the server will get video data from the initialized driver and send the data to the client. If the connection with client is terminated, the server will go back to accept mode for the next client. Currently, server only accpets on client at the same time.
The client source code is src/m100_x3_client_node.cpp. The client will try to connect to localhost:40042, and read data and interpret it as a predefined size-and-type image, and publish it as ros message.
Attention: after x3 gimbal camera driver is initialized, it will have a 50% usage of one cpu core. Please consider carefully if a 50%-cpu-usage-service will affect the performance of other programs
-
Install all the prerequisites in dji-sdk/Manifold-Cam (Mainly aims to install libdcam.so in the system)
-
(Optional or Necessary? I'm not sure) Disable lightdm for stability:
in
/etc/init/lightdm.conf
, line 12:Modify
runlevel [!06]
torunlevel [!026]
-
Add
xinit&
to a startup script, such as:echo -e '#!/bin/bash\nxinit&' > /home/ubuntu/pre_x3 chmod a+x /home/ubuntu/pre_x3
And add
/home/ubuntu/pre_x3
into/etc/rc.local
-
Add
export DISPLAY=:0
to your bashrc or remember to set this environment variable to THE USER WHO WILL RUN THE CODE -
(Maybe a reboot here)
-
Run
sudo -s
to grant root privilege, because the driver needs to operate many/dev
/sys
stuffs -
rosrun m100_x3 m100_x3_node
Same as 1, 6, 7 above
-
Install all the prerequisites in dji-sdk/Manifold-Cam (Mainly aims to install libdcam.so in the system)
-
cd src/server && make && sudo make install. This step will install the essential scripts and executables into the system to utilize the startup system.
-
You can use
sudo service x3server start/stop/status
to operate the x3 driver service. Useful output/log can be seen from /var/log/upstart/x3server.log -
To prevent automatic startup, edit /etc/init/x3server.conf, in start on item, change [!06] to [!0123456]
-
The dcam library uses some unusual techniques to handle SIGINT/SIGTERM to shutdown. And combined with socket, lots of efforts were devoted to handle termination of the server, but it is still not perfect. So there is a chance to fail on stopping the server. When the server is not running properly, a system reboot is recommanded.
-
Now, the server and client only support full-size grayscale image. Support of RGB and resized image should be added.
-
The port number 40042 is hardcoded in src/server/include/msgdef.h. Maybe it needs to change to other port number if this one is invalid, and the client should be able to find out the new port number.
djicdn links:
manifold_kernel_source_v1.0.tar.gz
google-drive: https://drive.google.com/open?id=0By08HNZRtOAYSFpPVWtFWnBfdmc