Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Henrik Andreasson
harvest-automation
Commits
2527362d
Commit
2527362d
authored
Jul 21, 2020
by
Nicholas Shindler
Browse files
create launch files, update reader/writer base classes
parent
2343dc1f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
51 deletions
+63
-51
hv_bridge/libs/Resources/reader.py
hv_bridge/libs/Resources/reader.py
+23
-24
hv_bridge/libs/Resources/writer.py
hv_bridge/libs/Resources/writer.py
+29
-27
hv_launch/lauch/harvey.launch
hv_launch/lauch/harvey.launch
+4
-0
hv_launch/lauch/hv_bridge.launch
hv_launch/lauch/hv_bridge.launch
+3
-0
hv_launch/lauch/teleop.launch
hv_launch/lauch/teleop.launch
+4
-0
No files found.
hv_bridge/libs/Resources/reader.py
View file @
2527362d
class
Reader
():
# reader class for getting data from the robot and passing to ROS
def
__init__
(
self
):
pass
def
run
(
self
):
# runs a listener thread, reading in data and placing it in a queue
def
__init__
(
self
,
name
,
p
):
# constructor for settings class
self
.
probes
=
p
self
.
name
=
name
self
.
queue
=
{}
for
label
in
p
:
self
.
queue
[
label
]
=
0
def
run
(
self
,
data
):
## Publish data
self
.
pub
.
publish
(
data
)
def
add
(
name
,
val
):
# add data piece
try
:
while
True
:
# Wait for incoming data from the RCP or for the listener
# pipe to close, indicating that we are
(
r
,
w
,
x
)
=
select
.
select
((
self
.
client
.
s
,
self
.
client
.
listener_pipe
[
0
]),
(),
())
if
self
.
client
.
listener_pipe
[
0
]
in
r
:
# listener pipe signaled the thread to exit
os
.
close
(
self
.
client
.
listener_pipe
[
0
])
return
if
self
.
client
.
s
in
r
:
(
t
,
l
,
v
)
=
self
.
client
.
receive_next_message
()
if
not
self
.
client
.
do_async_message
(
t
,
l
,
v
):
self
.
q
.
put
((
t
,
l
,
v
))
try
:
if
self
.
callback
==
None
:
raise
NameError
(
"No Callback has been defined"
)
self
.
callback
(
t
,
v
)
except
NameError
:
pass
# time.sleep(0.1)
self
.
queue
[
name
]
=
val
except
Exception
as
e
:
raise
e
def
needs
(
name
):
# check if name is used by this class
return
True
if
name
in
self
.
probes
else
False
def
get_probes
():
# return an array of all probes
return
self
.
probes
hv_bridge/libs/Resources/writer.py
View file @
2527362d
class
Reader
():
# reader class for getting data from the robot and passing to ROS
def
__init__
(
self
):
pass
def
run
(
self
):
# runs a listener thread, reading in data and placing it in a queue
try
:
while
True
:
# Wait for incoming data from the RCP or for the listener
# pipe to close, indicating that we are
(
r
,
w
,
x
)
=
select
.
select
((
self
.
client
.
s
,
self
.
client
.
listener_pipe
[
0
]),
(),
())
if
self
.
client
.
listener_pipe
[
0
]
in
r
:
# listener pipe signaled the thread to exit
os
.
close
(
self
.
client
.
listener_pipe
[
0
])
return
if
self
.
client
.
s
in
r
:
(
t
,
l
,
v
)
=
self
.
client
.
receive_next_message
()
if
not
self
.
client
.
do_async_message
(
t
,
l
,
v
):
self
.
q
.
put
((
t
,
l
,
v
))
try
:
if
self
.
callback
==
None
:
raise
NameError
(
"No Callback has been defined"
)
self
.
callback
(
t
,
v
)
except
NameError
:
pass
# time.sleep(0.1)
except
Exception
as
e
:
raise
e
def
__init__
(
self
,
p
):
# constructor for settings class
self
.
probes
=
p
def
get_msgs
():
# collect the messages to send
return
self
.
msgs
def
callback
(
self
,
msg
):
# subscriber callback function
if
type
(
self
.
code
)
!=
tuple
:
# if the message is a single item value pair
self
.
msgs
=
[(
self
.
code
,
msg
)]
elif
len
(
msg
)
>
1
:
# handle an array of messages
# each message coresponds to a probe (1 to 1)
# if(msg.length != self.code.length) throw "message size missmatch"
command
=
[]
i
=
0
for
c
in
self
.
code
:
command
.
append
((
c
,
msg
[
i
]))
i
=
i
+
1
self
.
msgs
=
command
else
:
# publish the same message to each of the probes
command
=
[]
for
c
in
self
.
code
:
command
.
append
((
c
,
msg
))
self
.
msgs
=
command
hv_launch/lauch/harvey.launch
View file @
2527362d
<launch>
<node name="main_node.py" pkg="hv_bridge" type="bridge" args="--all" />
<node name="harvey_node" pkg="harvey" type="talker" />
</launch>
hv_launch/lauch/hv_bridge.launch
View file @
2527362d
<launch>
<node name="main_node.py" pkg="hv_bridge" type="bridge" args="--all" />
</launch>
hv_launch/lauch/teleop.launch
View file @
2527362d
<launch>
<node name="main_node.py" pkg="hv_bridge" type="bridge" args="--controllers" />
<node name="teleop_node.py" pkg="hv_teleop" type="talker" />
</launch>
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