Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
larm-astro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Inès EL HADRI
larm-astro
Commits
4d3b175e
Commit
4d3b175e
authored
Jan 22, 2024
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add auto discovery map
parent
777efb1b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
auto_discovery
grp_astro/src/auto_discovery
+87
-0
No files found.
grp_astro/src/auto_discovery
0 → 100644
View file @
4d3b175e
#!/usr/bin/python3
# Imports
import
rclpy
from
rclpy.node
import
Node
from
geometry_msgs.msg
import
PoseStamped
,
Twist
from
nav_msgs.msg
import
OccupancyGrid
from
random
import
random
,
sample
# Class
class
AutoDisco
(
Node
):
def
__init__
(
self
,
name
=
"auto_disco"
,
timerFreq
=
1.0
/
60
):
super
()
.
__init__
(
name
)
self
.
init_publishers
(
timerFreq
)
self
.
init_subscribers
()
self
.
_robot_speed
=
Twist
()
self
.
_map
=
None
def
init_publishers
(
self
,
timerFreq
):
self
.
_goal_publisher
=
self
.
create_publisher
(
PoseStamped
,
'goal_pose'
,
10
)
self
.
create_timer
(
timerFreq
,
self
.
loop
)
def
init_subscribers
(
self
):
self
.
create_subscription
(
Twist
,
'/cmd_vel'
,
self
.
scan_callback
,
10
)
self
.
create_subscription
(
OccupancyGrid
,
'/map'
,
self
.
map_callback
,
10
)
def
scan_callback
(
self
,
msg
):
self
.
_robot_speed
=
msg
def
map_callback
(
self
,
msg
):
self
.
_map
=
msg
def
loop
(
self
):
print
(
f
'{self._robot_speed.linear.x=}'
)
if
self
.
_robot_speed
==
Twist
():
rdx
,
rdy
=
random
(),
random
()
pose
=
PoseStamped
()
# Map view
if
self
.
_map
is
None
:
return
resolution
=
self
.
_map
.
info
.
resolution
width
=
self
.
_map
.
info
.
width
height
=
self
.
_map
.
info
.
height
pose_origin
=
self
.
_map
.
info
.
origin
data
=
self
.
_map
.
data
print
(
type
(
data
))
values
=
[]
for
x
in
range
(
width
):
for
y
in
range
(
height
):
if
data
[
x
+
y
*
width
]
==
-
1
:
values
.
append
((
x
,
y
))
values
=
sample
(
values
,
1
)
pose
.
pose
.
position
.
x
=
values
[
0
][
0
]
*
resolution
pose
.
pose
.
position
.
y
=
values
[
0
][
1
]
*
resolution
print
(
f
'{pose.pose.position.x=}
\n
{pose.pose.position.y=}'
)
pose
.
header
.
frame_id
=
"map"
pose
.
header
.
stamp
=
self
.
get_clock
()
.
now
()
.
to_msg
()
self
.
_goal_publisher
.
publish
(
pose
)
def
main
():
"""
Main loop
"""
rclpy
.
init
()
rosNode
=
AutoDisco
()
rclpy
.
spin
(
rosNode
)
rosNode
.
destroy_node
()
rclpy
.
shutdown
()
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
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