Skip to content

Commit 92aaa0c

Browse files
committed
Init of ROS files
1 parent 4da2f6c commit 92aaa0c

File tree

15 files changed

+1187
-0
lines changed

15 files changed

+1187
-0
lines changed

CMakeLists.txt

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

msg/RCIn.msg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
std_msgs/Header header
2+
uint16[] channels

nodes/rcinput

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
3+
from navio2_ros.navio import rcinput
4+
from navio2_ros.navio import util
5+
import rospy
6+
7+
from navio2_ros.msg import RCIn
8+
rospy.init_node('rcinput')
9+
pub = rospy.Publisher('rcinput', RCIn, queue_size=2)
10+
11+
rate = rospy.Rate(20)
12+
13+
rcin = rcinput.RCInput()
14+
15+
while not rospy.is_shutdown():
16+
rc_input = RCIn()
17+
18+
rc_input.channels = (
19+
int(rcin.read(0)),
20+
int(rcin.read(1)),
21+
int(rcin.read(2)),
22+
int(rcin.read(3)),
23+
int(rcin.read(4)),
24+
int(rcin.read(5)),
25+
int(rcin.read(6)),
26+
int(rcin.read(7)),
27+
int(rcin.read(8)))
28+
29+
rc_input.header.stamp = rospy.Time.now()
30+
pub.publish(rc_input)
31+
rate.sleep()

nodes/rcoutput

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
import rospy
4+
5+
from navio2_ros.msg import RCIn
6+
7+
from navio2_ros.navio.pwm import PWM
8+
9+
10+
def callback(msg):
11+
for ch, val in enumerate(msg.channels):
12+
pwm = PWM(ch)
13+
pwm.set_period(50)
14+
if val > 1960:
15+
val = 1960
16+
if val < 1024:
17+
val = 1024
18+
pwm.set_duty_cycle(val/1000.0)
19+
20+
rospy.init_node('rcoutput')
21+
sub = rospy.Subscriber('rcoutput', RCIn, callback)
22+
23+
rospy.spin()

package.xml

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

setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from distutils.core import setup
2+
from catkin_pkg.python_setup import generate_distutils_setup
3+
4+
d = generate_distutils_setup(
5+
packages=['navio2_ros'],
6+
package_dir={'': 'src'},
7+
requires=['rospy']
8+
)
9+
10+
setup(**d)

src/navio2_ros/__init__.py

Whitespace-only changes.

src/navio2_ros/navio/__init__.py

Whitespace-only changes.

src/navio2_ros/navio/adc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class ADC():
2+
channel_count = 6
3+
channels = []
4+
5+
def __init__(self):
6+
for i in range(0, self.channel_count):
7+
try:
8+
f = open("/sys/kernel/rcio/adc/ch%d" % i, "r")
9+
self.channels.append(f)
10+
except:
11+
print ("Can't open file /sys/kernel/rcio/adc/ch%d" % i)
12+
13+
def read(self, ch):
14+
value = self.channels[ch].read()
15+
position = self.channels[ch].seek(0, 0)
16+
return float(value[:-1])
17+

src/navio2_ros/navio/leds.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
ON = 0
2+
OFF = 1
3+
4+
class Pin():
5+
def __init__(self, folder_name):
6+
self.pin = folder_name
7+
try:
8+
open("/sys/class/leds/%s/brightness" % self.pin, "w")
9+
except:
10+
print "Can't open file 'brightness'"
11+
12+
def write(self, value):
13+
with open("/sys/class/leds/%s/brightness" % self.pin, "w") as value_file:
14+
value_file.write(str(value))
15+
16+
class Led():
17+
18+
def __init__(self):
19+
self.ledR = Pin("rgb_led0")
20+
self.ledB = Pin("rgb_led1")
21+
self.ledG = Pin("rgb_led2")
22+
23+
self.ledR.write(OFF)
24+
self.ledG.write(OFF)
25+
self.ledB.write(OFF)
26+
27+
def setColor(self, color):
28+
self.ledR.write(self.gamma[color][0])
29+
self.ledG.write(self.gamma[color][1])
30+
self.ledB.write(self.gamma[color][2])
31+
32+
gamma = {
33+
'Black': (OFF, OFF, OFF),
34+
'Red': (ON, OFF, OFF),
35+
'Green': (OFF, ON, OFF),
36+
'Blue': (OFF, OFF, ON),
37+
'Cyan': (OFF, ON, ON),
38+
'Magneta': (ON, OFF, ON),
39+
'Yellow': (ON,ON,OFF),
40+
'White': (ON, ON, ON)
41+
}

0 commit comments

Comments
 (0)