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
95ef1cff
Commit
95ef1cff
authored
Dec 22, 2023
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reactive_move script that moves and avoids obstacles
parent
3fdca3c9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
CMakeLists.txt
tuto_kickoff/CMakeLists.txt
+1
-0
reactive_move
tuto_kickoff/scripts/reactive_move
+62
-0
No files found.
tuto_kickoff/CMakeLists.txt
View file @
95ef1cff
...
@@ -36,5 +36,6 @@ install( PROGRAMS
...
@@ -36,5 +36,6 @@ install( PROGRAMS
scripts/myNode
scripts/myNode
scripts/tuto_move
scripts/tuto_move
scripts/tuto_scan_echo
scripts/tuto_scan_echo
scripts/reactive_move
DESTINATION lib/
${
PROJECT_NAME
}
DESTINATION lib/
${
PROJECT_NAME
}
)
)
\ No newline at end of file
tuto_kickoff/scripts/reactive_move
0 → 100644
View file @
95ef1cff
#!/usr/bin/python3
import
rclpy
import
math
from
rclpy.node
import
Node
from
sensor_msgs.msg
import
PointCloud2
from
geometry_msgs.msg
import
Twist
import
sensor_msgs_py.point_cloud2
from
std_msgs.msg
import
Header
rosNode
=
None
velocity_publisher
=
None
def
scan_callback
(
scanMsg
):
global
rosNode
global
velocity_publisher
points
=
sensor_msgs_py
.
point_cloud2
.
read_points
(
scanMsg
)
x
,
y
=
firstPointInFront
(
points
,
0.5
,
0.25
)
velocity
=
Twist
()
if
x
and
y
:
if
y
>=
0
:
# Point is in the left part of the rectangle -> Turn right
velocity
.
angular
.
z
=
-
1.0
else
:
# Point is in the right part of the rectangle -> Turn left
velocity
.
angular
.
z
=
1.0
else
:
# If there's not point in front, go straight
velocity
.
linear
.
x
=
0.2
velocity_publisher
.
publish
(
velocity
)
def
firstPointInFront
(
points
:
list
,
maxX
,
maxY
):
for
(
x
,
y
,
_
)
in
points
:
if
(
x
>
0
and
x
<
maxX
and
abs
(
y
)
<
maxY
):
return
(
x
,
y
)
return
(
None
,
None
)
def
main
():
global
velocity_publisher
rclpy
.
init
()
rosNode
=
Node
(
'reactive_move'
)
# Initialize a subscriber:
rosNode
.
create_subscription
(
PointCloud2
,
'scan_points'
,
scan_callback
,
10
)
# Initialize a publisher:
velocity_publisher
=
rosNode
.
create_publisher
(
Twist
,
'/cmd_vel'
,
10
)
while
True
:
rclpy
.
spin_once
(
rosNode
)
scanInterpret
.
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