Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
ros2-scripts
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
ros2-scripts
Commits
c198abeb
Commit
c198abeb
authored
Dec 13, 2018
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some changes
parent
71134888
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
69 deletions
+64
-69
.directory
src/init/.directory
+2
-1
ros2_client.py
src/init/ros2_client.py
+1
-1
ros2_config.py
src/init/ros2_config.py
+15
-28
ros2_config.xml
src/init/ros2_config.xml
+26
-2
ros2_init.py
src/init/ros2_init.py
+3
-1
ros2_master.py
src/init/ros2_master.py
+13
-31
ros2_slave.py
src/init/ros2_slave.py
+4
-5
No files found.
src/init/.directory
View file @
c198abeb
[Dolphin]
PreviewsShown=true
Timestamp=2018,12,12,15,36,33
SortRole=date
Timestamp=2018,12,13,15,55,15
Version=3
ViewMode=1
src/init/ros2_client.py
View file @
c198abeb
...
...
@@ -9,7 +9,7 @@ import ros2_config
rclpy
.
init
()
node
=
rclpy
.
create_node
(
'some_client_node'
)
cli
=
node
.
create_client
(
StrReqStrRes
,
'
master/cmd_all
'
)
cli
=
node
.
create_client
(
StrReqStrRes
,
'
n000e64101698_master/cmd
'
)
wcnt
=
0
while
not
cli
.
wait_for_service
(
timeout_sec
=
1.0
):
...
...
src/init/ros2_config.py
View file @
c198abeb
...
...
@@ -4,47 +4,34 @@ import os
import
re
import
xml.etree.ElementTree
as
ET
def
is_unique_name
(
a
,
name
):
for
i
in
a
:
if
i
[
'name'
]
==
name
:
return
False
return
True
NODEPREFIX
=
'n'
# get function
def
get
(
f
=
"ros2_config.xml"
):
cfg
=
[]
cfg
=
{}
prefix
=
"cam_"
mac
=
get_mac
(
capitalize
=
False
)
name
=
prefix
+
mac
role
=
"unknown"
mac
=
get_mac
(
last_three_octets
=
False
,
capitalize
=
False
)
cfg
[
'self'
]
=
NODEPREFIX
+
mac
cfg
[
'role'
]
=
None
if
os
.
path
.
isfile
(
f
):
e
=
ET
.
parse
(
f
)
.
getroot
()
tmp
=
e
.
find
(
'prefix'
)
if
tmp
!=
None
:
name
=
tmp
.
text
+
mac
e
=
ET
.
parse
(
f
)
.
getroot
()
tmp
=
e
.
find
(
'
role
'
)
tmp
=
e
.
find
(
'
self
'
)
if
tmp
!=
None
:
role
=
tmp
.
text
# self goes first
cfg
.
append
({
'name'
:
name
,
'role'
:
role
})
tmp
=
tmp
.
get
(
'role'
)
if
tmp
!=
None
:
cfg
[
'role'
]
=
tmp
# drop non-unique names
for
s
in
e
.
findall
(
'
nod
e'
):
cfg
[
'slaves'
]
=
{}
for
s
in
e
.
findall
(
'
slav
e'
):
tmp_name
=
s
.
get
(
'
name
'
)
tmp_
role
=
s
.
get
(
'role
'
)
tmp_name
=
s
.
get
(
'
class
'
)
tmp_
mac
=
s
.
get
(
'id
'
)
if
is_unique_name
(
cfg
,
tmp_name
):
cfg
.
append
({
'name'
:
tmp_name
,
'role'
:
tmp_role
})
cfg
[
'slaves'
][
tmp_name
]
=
tmp_mac
# will not overwrite role for non-unique nodes
return
cfg
...
...
src/init/ros2_config.xml
View file @
c198abeb
<?xml version="1.0" standalone="yes"?>
<ros2>
<prefix>
cam_
</prefix>
<role>
not_master
</role>
<self
role=
''
/>
</ros2>
<!--
<self> - info for this camera's node
attrs:
'role' - master or any string for not master
'system' - not used, TBA
example:
<self role='' />
<node> - info of other nodes, so this node will know other nodes 'by name'
attrs:
'class' - class TODO: allow multiple classes separated by comma or space
'id' - other node id - when composing - have to know prefix and mac
example:
<node class='left' id='n000e64101698'/>
prefixes are used because nodes names must start from a letter.
-->
\ No newline at end of file
src/init/ros2_init.py
View file @
c198abeb
...
...
@@ -5,7 +5,9 @@ import ros2_config
cfg
=
ros2_config
.
get
()
if
cfg
[
0
][
'role'
]
==
'master'
:
print
(
cfg
)
if
cfg
[
'role'
]
==
'master'
:
subprocess
.
Popen
([
'python3'
,
'ros2_master.py'
])
subprocess
.
Popen
([
'python3'
,
'ros2_slave.py'
])
src/init/ros2_master.py
View file @
c198abeb
...
...
@@ -8,30 +8,13 @@ import ros2_config
TIMEOUT
=
5
# master callbacks
def
signup_callback
(
req
,
res
):
name
=
req
.
request
print
(
'Sign up from '
+
name
)
if
name
in
clients
:
print
(
'Slave name is not unique. So sad.'
)
else
:
clients
.
append
(
name
)
print
(
'List of registered slaves: '
+
str
(
clients
))
res
.
response
=
name
return
res
# async coroutine for cmdall_callback
async
def
pass_cmd
(
target
,
cmd
):
node
=
rclpy
.
create_node
(
target
+
'_client'
)
cli
=
node
.
create_client
(
StrReqStrRes
,
target
+
'/cmd'
)
#node = rclpy.create_node(target+'_client')
slave
=
cfg
[
'slaves'
][
target
]
cli
=
node
.
create_client
(
StrReqStrRes
,
slave
+
'/cmd'
)
wcnt
=
0
while
not
cli
.
wait_for_service
(
timeout_sec
=
1.0
):
...
...
@@ -51,7 +34,7 @@ async def pass_cmd(target,cmd):
# callback for broadcast commands
def
cmd
all
_callback
(
req
,
res
):
def
cmd_callback
(
req
,
res
):
cmd
=
req
.
request
tasks
=
[
pass_cmd
(
c
,
cmd
)
for
c
in
clients
]
...
...
@@ -68,21 +51,20 @@ def cmdall_callback(req,res):
clients
=
[]
cfg
=
ros2_config
.
get
()
nodename
=
cfg
[
0
][
'name'
]
nodename
=
cfg
[
'self'
]
+
'_master'
for
i
in
cfg
:
clients
.
append
(
i
[
'name'
])
for
k
,
v
in
cfg
[
'slaves'
]
.
items
():
print
(
k
+
' '
+
v
)
clients
.
append
(
k
)
rclpy
.
init
()
node
=
rclpy
.
create_node
(
nodename
+
"_master"
)
node
=
rclpy
.
create_node
(
nodename
)
event_loop
=
asyncio
.
get_event_loop
()
print
(
"Starting master services:"
)
#print(" master/signup")
#s1 = node.create_service(StrReqStrRes, 'master/signup', signup_callback)
print
(
" master/cmd_all"
)
s2
=
node
.
create_service
(
StrReqStrRes
,
'master/cmd_all'
,
cmdall_callback
)
print
(
'Starting master services:'
)
print
(
' '
+
nodename
+
'/cmd'
)
s1
=
node
.
create_service
(
StrReqStrRes
,
nodename
+
'/cmd'
,
cmd_callback
)
rclpy
.
spin
(
node
)
...
...
src/init/ros2_slave.py
View file @
c198abeb
...
...
@@ -25,15 +25,14 @@ def cmd_callback(req,res):
# global
cfg
=
ros2_config
.
get
()
nodename
=
cfg
[
0
][
'name
'
]
nodename
=
cfg
[
'self
'
]
rclpy
.
init
()
node
=
rclpy
.
create_node
(
nodename
)
# now start cmd service
print
(
"Starting slave services:"
)
print
(
" "
+
nodename
+
'/cmd'
)
s3
=
node
.
create_service
(
StrReqStrRes
,
nodename
+
'/cmd'
,
cmd_callback
)
print
(
'Starting slave services:'
)
print
(
' '
+
nodename
+
'/cmd'
)
s
=
node
.
create_service
(
StrReqStrRes
,
nodename
+
'/cmd'
,
cmd_callback
)
rclpy
.
spin
(
node
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment