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
Show 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]
[Dolphin]
PreviewsShown=true
PreviewsShown=true
Timestamp=2018,12,12,15,36,33
SortRole=date
Timestamp=2018,12,13,15,55,15
Version=3
Version=3
ViewMode=1
ViewMode=1
src/init/ros2_client.py
View file @
c198abeb
...
@@ -9,7 +9,7 @@ import ros2_config
...
@@ -9,7 +9,7 @@ import ros2_config
rclpy
.
init
()
rclpy
.
init
()
node
=
rclpy
.
create_node
(
'some_client_node'
)
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
wcnt
=
0
while
not
cli
.
wait_for_service
(
timeout_sec
=
1.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
...
@@ -4,47 +4,34 @@ import os
import
re
import
re
import
xml.etree.ElementTree
as
ET
import
xml.etree.ElementTree
as
ET
def
is_unique_name
(
a
,
name
):
NODEPREFIX
=
'n'
for
i
in
a
:
if
i
[
'name'
]
==
name
:
return
False
return
True
# get function
# get function
def
get
(
f
=
"ros2_config.xml"
):
def
get
(
f
=
"ros2_config.xml"
):
cfg
=
[]
cfg
=
{}
prefix
=
"cam_"
mac
=
get_mac
(
last_three_octets
=
False
,
capitalize
=
False
)
mac
=
get_mac
(
capitalize
=
False
)
cfg
[
'self'
]
=
NODEPREFIX
+
mac
name
=
prefix
+
mac
cfg
[
'role'
]
=
None
role
=
"unknown"
if
os
.
path
.
isfile
(
f
):
if
os
.
path
.
isfile
(
f
):
e
=
ET
.
parse
(
f
)
.
getroot
()
e
=
ET
.
parse
(
f
)
.
getroot
()
tmp
=
e
.
find
(
'
prefix
'
)
tmp
=
e
.
find
(
'
self
'
)
if
tmp
!=
None
:
if
tmp
!=
None
:
name
=
tmp
.
text
+
mac
tmp
=
tmp
.
get
(
'role'
)
tmp
=
e
.
find
(
'role'
)
if
tmp
!=
None
:
if
tmp
!=
None
:
role
=
tmp
.
text
cfg
[
'role'
]
=
tmp
# self goes first
cfg
.
append
({
'name'
:
name
,
'role'
:
role
})
# drop non-unique names
cfg
[
'slaves'
]
=
{}
for
s
in
e
.
findall
(
'
nod
e'
):
for
s
in
e
.
findall
(
'
slav
e'
):
tmp_name
=
s
.
get
(
'
name
'
)
tmp_name
=
s
.
get
(
'
class
'
)
tmp_
role
=
s
.
get
(
'role
'
)
tmp_
mac
=
s
.
get
(
'id
'
)
if
is_unique_name
(
cfg
,
tmp_name
):
cfg
[
'slaves'
][
tmp_name
]
=
tmp_mac
cfg
.
append
({
'name'
:
tmp_name
,
'role'
:
tmp_role
})
# will not overwrite role for non-unique nodes
# will not overwrite role for non-unique nodes
return
cfg
return
cfg
...
...
src/init/ros2_config.xml
View file @
c198abeb
<?xml version="1.0" standalone="yes"?>
<?xml version="1.0" standalone="yes"?>
<ros2>
<ros2>
<prefix>
cam_
</prefix>
<self
role=
''
/>
<role>
not_master
</role>
</ros2>
</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
...
@@ -5,7 +5,9 @@ import ros2_config
cfg
=
ros2_config
.
get
()
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_master.py'
])
subprocess
.
Popen
([
'python3'
,
'ros2_slave.py'
])
subprocess
.
Popen
([
'python3'
,
'ros2_slave.py'
])
src/init/ros2_master.py
View file @
c198abeb
...
@@ -8,30 +8,13 @@ import ros2_config
...
@@ -8,30 +8,13 @@ import ros2_config
TIMEOUT
=
5
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 coroutine for cmdall_callback
async
def
pass_cmd
(
target
,
cmd
):
async
def
pass_cmd
(
target
,
cmd
):
node
=
rclpy
.
create_node
(
target
+
'_client'
)
#node = rclpy.create_node(target+'_client')
cli
=
node
.
create_client
(
StrReqStrRes
,
target
+
'/cmd'
)
slave
=
cfg
[
'slaves'
][
target
]
cli
=
node
.
create_client
(
StrReqStrRes
,
slave
+
'/cmd'
)
wcnt
=
0
wcnt
=
0
while
not
cli
.
wait_for_service
(
timeout_sec
=
1.0
):
while
not
cli
.
wait_for_service
(
timeout_sec
=
1.0
):
...
@@ -51,7 +34,7 @@ async def pass_cmd(target,cmd):
...
@@ -51,7 +34,7 @@ async def pass_cmd(target,cmd):
# callback for broadcast commands
# callback for broadcast commands
def
cmd
all
_callback
(
req
,
res
):
def
cmd_callback
(
req
,
res
):
cmd
=
req
.
request
cmd
=
req
.
request
tasks
=
[
pass_cmd
(
c
,
cmd
)
for
c
in
clients
]
tasks
=
[
pass_cmd
(
c
,
cmd
)
for
c
in
clients
]
...
@@ -68,21 +51,20 @@ def cmdall_callback(req,res):
...
@@ -68,21 +51,20 @@ def cmdall_callback(req,res):
clients
=
[]
clients
=
[]
cfg
=
ros2_config
.
get
()
cfg
=
ros2_config
.
get
()
nodename
=
cfg
[
0
][
'name'
]
nodename
=
cfg
[
'self'
]
+
'_master'
for
i
in
cfg
:
for
k
,
v
in
cfg
[
'slaves'
]
.
items
():
clients
.
append
(
i
[
'name'
])
print
(
k
+
' '
+
v
)
clients
.
append
(
k
)
rclpy
.
init
()
rclpy
.
init
()
node
=
rclpy
.
create_node
(
nodename
+
"_master"
)
node
=
rclpy
.
create_node
(
nodename
)
event_loop
=
asyncio
.
get_event_loop
()
event_loop
=
asyncio
.
get_event_loop
()
print
(
"Starting master services:"
)
print
(
'Starting master services:'
)
#print(" master/signup")
print
(
' '
+
nodename
+
'/cmd'
)
#s1 = node.create_service(StrReqStrRes, 'master/signup', signup_callback)
s1
=
node
.
create_service
(
StrReqStrRes
,
nodename
+
'/cmd'
,
cmd_callback
)
print
(
" master/cmd_all"
)
s2
=
node
.
create_service
(
StrReqStrRes
,
'master/cmd_all'
,
cmdall_callback
)
rclpy
.
spin
(
node
)
rclpy
.
spin
(
node
)
...
...
src/init/ros2_slave.py
View file @
c198abeb
...
@@ -25,15 +25,14 @@ def cmd_callback(req,res):
...
@@ -25,15 +25,14 @@ def cmd_callback(req,res):
# global
# global
cfg
=
ros2_config
.
get
()
cfg
=
ros2_config
.
get
()
nodename
=
cfg
[
0
][
'name
'
]
nodename
=
cfg
[
'self
'
]
rclpy
.
init
()
rclpy
.
init
()
node
=
rclpy
.
create_node
(
nodename
)
node
=
rclpy
.
create_node
(
nodename
)
# now start cmd service
print
(
'Starting slave services:'
)
print
(
"Starting slave services:"
)
print
(
' '
+
nodename
+
'/cmd'
)
print
(
" "
+
nodename
+
'/cmd'
)
s
=
node
.
create_service
(
StrReqStrRes
,
nodename
+
'/cmd'
,
cmd_callback
)
s3
=
node
.
create_service
(
StrReqStrRes
,
nodename
+
'/cmd'
,
cmd_callback
)
rclpy
.
spin
(
node
)
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