Skip to content

Commit 09e94dd

Browse files
committed
initial commit
1 parent 91c5ff6 commit 09e94dd

7 files changed

+668
-0
lines changed

CMakeLists.txt

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
cmake_minimum_required(VERSION 2.8.3)
2+
project(m100_x3)
3+
4+
set(CMAKE_VERBOSE_MAKEFILE "true")
5+
6+
include(CheckCXXCompilerFlag)
7+
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
8+
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
9+
if(COMPILER_SUPPORTS_CXX11)
10+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
11+
elseif(COMPILER_SUPPORTS_CXX0X)
12+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
13+
else()
14+
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
15+
endif()
16+
17+
set(ADDITIONAL_CXX_FLAG "-Wall -O3")
18+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAG}")
19+
20+
## Find catkin macros and libraries
21+
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
22+
## is used, also find other catkin packages
23+
find_package(catkin REQUIRED COMPONENTS
24+
cv_bridge
25+
image_transport
26+
roscpp
27+
sensor_msgs
28+
)
29+
30+
## System dependencies are found with CMake's conventions
31+
# find_package(Boost REQUIRED COMPONENTS system)
32+
33+
34+
## Uncomment this if the package has a setup.py. This macro ensures
35+
## modules and global scripts declared therein get installed
36+
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
37+
# catkin_python_setup()
38+
39+
################################################
40+
## Declare ROS messages, services and actions ##
41+
################################################
42+
43+
## To declare and build messages, services or actions from within this
44+
## package, follow these steps:
45+
## * Let MSG_DEP_SET be the set of packages whose message types you use in
46+
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
47+
## * In the file package.xml:
48+
## * add a build_depend tag for "message_generation"
49+
## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
50+
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
51+
## but can be declared for certainty nonetheless:
52+
## * add a run_depend tag for "message_runtime"
53+
## * In this file (CMakeLists.txt):
54+
## * add "message_generation" and every package in MSG_DEP_SET to
55+
## find_package(catkin REQUIRED COMPONENTS ...)
56+
## * add "message_runtime" and every package in MSG_DEP_SET to
57+
## catkin_package(CATKIN_DEPENDS ...)
58+
## * uncomment the add_*_files sections below as needed
59+
## and list every .msg/.srv/.action file to be processed
60+
## * uncomment the generate_messages entry below
61+
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
62+
63+
## Generate messages in the 'msg' folder
64+
# add_message_files(
65+
# FILES
66+
# Message1.msg
67+
# Message2.msg
68+
# )
69+
70+
## Generate services in the 'srv' folder
71+
# add_service_files(
72+
# FILES
73+
# Service1.srv
74+
# Service2.srv
75+
# )
76+
77+
## Generate actions in the 'action' folder
78+
# add_action_files(
79+
# FILES
80+
# Action1.action
81+
# Action2.action
82+
# )
83+
84+
## Generate added messages and services with any dependencies listed here
85+
# generate_messages(
86+
# DEPENDENCIES
87+
# sensor_msgs
88+
# )
89+
90+
################################################
91+
## Declare ROS dynamic reconfigure parameters ##
92+
################################################
93+
94+
## To declare and build dynamic reconfigure parameters within this
95+
## package, follow these steps:
96+
## * In the file package.xml:
97+
## * add a build_depend and a run_depend tag for "dynamic_reconfigure"
98+
## * In this file (CMakeLists.txt):
99+
## * add "dynamic_reconfigure" to
100+
## find_package(catkin REQUIRED COMPONENTS ...)
101+
## * uncomment the "generate_dynamic_reconfigure_options" section below
102+
## and list every .cfg file to be processed
103+
104+
## Generate dynamic reconfigure parameters in the 'cfg' folder
105+
# generate_dynamic_reconfigure_options(
106+
# cfg/DynReconf1.cfg
107+
# cfg/DynReconf2.cfg
108+
# )
109+
110+
###################################
111+
## catkin specific configuration ##
112+
###################################
113+
## The catkin_package macro generates cmake config files for your package
114+
## Declare things to be passed to dependent projects
115+
## INCLUDE_DIRS: uncomment this if you package contains header files
116+
## LIBRARIES: libraries you create in this project that dependent projects also need
117+
## CATKIN_DEPENDS: catkin_packages dependent projects also need
118+
## DEPENDS: system dependencies of this project that dependent projects also need
119+
catkin_package(
120+
# INCLUDE_DIRS include
121+
# LIBRARIES m100_x3
122+
# CATKIN_DEPENDS cv_bridge roscpp sensor_msgs
123+
# DEPENDS system_lib
124+
)
125+
126+
###########
127+
## Build ##
128+
###########
129+
130+
## Specify additional locations of header files
131+
## Your package locations should be listed before other locations
132+
# include_directories(include)
133+
include_directories(
134+
${catkin_INCLUDE_DIRS}
135+
)
136+
137+
## Declare a C++ library
138+
# add_library(m100_x3
139+
# src/${PROJECT_NAME}/m100_x3.cpp
140+
# )
141+
142+
## Add cmake target dependencies of the library
143+
## as an example, code may need to be generated before libraries
144+
## either from message generation or dynamic reconfigure
145+
# add_dependencies(m100_x3 ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
146+
147+
## Declare a C++ executable
148+
add_executable(m100_x3_node
149+
src/m100_x3_node.cpp
150+
src/djicam_utils.cpp
151+
)
152+
153+
## Add cmake target dependencies of the executable
154+
## same as for the library above
155+
# add_dependencies(m100_x3_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
156+
157+
## Specify libraries to link a library or executable target against
158+
target_link_libraries(m100_x3_node
159+
dcam
160+
${catkin_LIBRARIES}
161+
)
162+
163+
#############
164+
## Install ##
165+
#############
166+
167+
# all install targets should use catkin DESTINATION variables
168+
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
169+
170+
## Mark executable scripts (Python etc.) for installation
171+
## in contrast to setup.py, you can choose the destination
172+
# install(PROGRAMS
173+
# scripts/my_python_script
174+
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
175+
# )
176+
177+
## Mark executables and/or libraries for installation
178+
# install(TARGETS m100_x3 m100_x3_node
179+
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
180+
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
181+
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
182+
# )
183+
184+
## Mark cpp header files for installation
185+
# install(DIRECTORY include/${PROJECT_NAME}/
186+
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
187+
# FILES_MATCHING PATTERN "*.h"
188+
# PATTERN ".svn" EXCLUDE
189+
# )
190+
191+
## Mark other files for installation (e.g. launch and bag files, etc.)
192+
# install(FILES
193+
# # myfile1
194+
# # myfile2
195+
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
196+
# )
197+
198+
#############
199+
## Testing ##
200+
#############
201+
202+
## Add gtest based cpp test target and link libraries
203+
# catkin_add_gtest(${PROJECT_NAME}-test test/test_m100_x3.cpp)
204+
# if(TARGET ${PROJECT_NAME}-test)
205+
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
206+
# endif()
207+
208+
## Add folders to be run by python nosetests
209+
# catkin_add_nosetests(test)

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# M100 X3 ROS Driver
2+
3+
A ROS package which can read video stream from Zenmuse-X3-Camera on M100 and publish it as [sensor_msgs/Image](http://docs.ros.org/api/sensor_msgs/html/msg/Image.html). Must be compiled and launched on Manifold.
4+
5+
This package is based on [dji_sdk_manifold_read_cam](https://github.com/dji-sdk/Onboard-SDK-ROS/tree/2.3/dji_sdk_manifold_read_cam) and dji-sdk/Manifold-Cam. Refer to them for more infomation.
6+
7+
### Steps for streaming video from X3 to Manifold, through SSH, without a hdmi-screen
8+
9+
1. Install all the prerequisites in dji-sdk/Manifold-Cam
10+
11+
2. (Optinal) Disable lightdm for stability:
12+
13+
in `/etc/init/lightdm.conf`, line 12:
14+
Modify ```runlevel [!06]``` to ```runlevel [!026]```
15+
16+
3. Add ```xinit&``` to a startup script, such as:
17+
18+
```
19+
echo -e '#!/bin/bash\nxinit&' > /home/ubuntu/pre_x3
20+
chmod a+x /home/ubuntu/pre_x3
21+
```
22+
And add `/home/ubuntu/pre_x3` into `/etc/rc.local`
23+
24+
4. Add ```export DISPLAY=:0``` to your bashrc or remember to set this environment variable to THE USER WHO WILL RUN THE CODE
25+
26+
5. Run ```sudo -s``` to grant root privilege, because the driver need to operate many `/dev` `/sys` stuffs
27+
28+
6. rosrun m100_x3 m100_x3_node
29+
30+
31+
### Steps for streaming video from X3 to Manifold with a hdmi-screen
32+
33+
Same as 1, 2, 6 above
34+

package.xml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0"?>
2+
<package>
3+
<name>m100_x3</name>
4+
<version>1.0.0</version>
5+
<description>The m100_x3 package</description>
6+
7+
<!-- One maintainer tag required, multiple allowed, one person per tag -->
8+
<!-- Example: -->
9+
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
10+
<maintainer email="LIUTianbo@todo.todo">LIUTianbo</maintainer>
11+
12+
13+
<!-- One license tag required, multiple allowed, one license per tag -->
14+
<!-- Commonly used license strings: -->
15+
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
16+
<license>BSD</license>
17+
18+
19+
<!-- Url tags are optional, but mutiple are allowed, one per tag -->
20+
<!-- Optional attribute type can be: website, bugtracker, or repository -->
21+
<!-- Example: -->
22+
<!-- <url type="website">http://wiki.ros.org/m100_x3</url> -->
23+
24+
25+
<!-- Author tags are optional, mutiple are allowed, one per tag -->
26+
<!-- Authors do not have to be maintianers, but could be -->
27+
<!-- Example: -->
28+
<!-- <author email="jane.doe@example.com">Jane Doe</author> -->
29+
<author>LIUTianbo</author>
30+
31+
32+
<!-- The *_depend tags are used to specify dependencies -->
33+
<!-- Dependencies can be catkin packages or system dependencies -->
34+
<!-- Examples: -->
35+
<!-- Use build_depend for packages you need at compile time: -->
36+
<!-- <build_depend>message_generation</build_depend> -->
37+
<!-- Use buildtool_depend for build tool packages: -->
38+
<!-- <buildtool_depend>catkin</buildtool_depend> -->
39+
<!-- Use run_depend for packages you need at runtime: -->
40+
<!-- <run_depend>message_runtime</run_depend> -->
41+
<!-- Use test_depend for packages you need only for testing: -->
42+
<!-- <test_depend>gtest</test_depend> -->
43+
<buildtool_depend>catkin</buildtool_depend>
44+
<build_depend>cv_bridge</build_depend>
45+
<build_depend>roscpp</build_depend>
46+
<build_depend>sensor_msgs</build_depend>
47+
<build_depend>image_transport</build_depend>
48+
<run_depend>cv_bridge</run_depend>
49+
<run_depend>roscpp</run_depend>
50+
<run_depend>sensor_msgs</run_depend>
51+
<run_depend>image_transport</run_depend>
52+
53+
54+
<!-- The export tag contains other, unspecified, tags -->
55+
<export>
56+
<!-- Other tools can request additional information be placed here -->
57+
58+
</export>
59+
</package>

src/djicam.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
*Copyright (C) 2015, DJI Innovations, Inc. All rights reserved.
3+
*
4+
*/
5+
6+
7+
#ifndef __DJICAM_H
8+
#define __DJICAM_H
9+
10+
#define DISPLAY_MODE (1 << 0)
11+
#define GETBUFFER_MODE (1 << 1)
12+
#define TRANSFER_MODE (1 << 2)
13+
14+
#define CAM_BLOCK 1
15+
#define CAM_NON_BLOCK 0
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
/**
22+
* @brief used for initialization
23+
* @param mode set mode as DISPLAY_MODE, GETBUFFER_MODE, TRANSFER_MODE
24+
* @return 0 on sucess, -1 on error
25+
*/
26+
int manifold_cam_init(int mode);
27+
28+
/**
29+
* @brief get the datas of a frame decoded
30+
* @param buffer store datas of a frame, format NV12
31+
* @param nframe count the number of frames get
32+
* @param block CAM_BLOCK will wait until data available, CAM_NON_BLOCK will always return immediately
33+
* @return CAM_BLOCK mode: >0 on frame size, <0 on break or error
34+
* CAM_NON_BLOCK mode: >0 on frame size, 0 on no new frame, <0 on break or error
35+
*/
36+
int manifold_cam_read(unsigned char *buffer, unsigned int *nframe, unsigned int block);
37+
38+
/**
39+
* @brief to check if exit ok
40+
* @return 1 on sucess, 0 if not ok
41+
*/
42+
int manifold_cam_exit();
43+
44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
48+
#endif

0 commit comments

Comments
 (0)