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
2a2c8860
Commit
2a2c8860
authored
Jan 16, 2024
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Arrêt du robot quand les roues ne touchent pas le sol
parent
3c94bc14
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
reactive_move
grp_astro/src/reactive_move
+22
-3
No files found.
grp_astro/src/reactive_move
View file @
2a2c8860
...
...
@@ -6,6 +6,7 @@ import rclpy
import
math
as
m
from
rclpy.node
import
Node
from
sensor_msgs.msg
import
PointCloud2
from
kobuki_ros_interfaces.msg
import
WheelDropEvent
from
geometry_msgs.msg
import
Twist
import
sensor_msgs_py.point_cloud2
import
time
...
...
@@ -30,8 +31,9 @@ class ReactiveMove(Node):
""" constructor """
super
()
.
__init__
(
name
)
# Create the node
# Initialize a subscriber
self
.
create_subscription
(
PointCloud2
,
'scan_points'
,
self
.
scan_callback
,
10
)
# Initialize subscribers
self
.
create_subscription
(
PointCloud2
,
'/scan_points'
,
self
.
scan_callback
,
10
)
self
.
create_subscription
(
WheelDropEvent
,
'/events/wheel_drop'
,
self
.
wheel_callback
,
10
)
# Initialize a publisher
self
.
_velocity_publisher
=
self
.
create_publisher
(
Twist
,
'cmd_vel'
,
10
)
...
...
@@ -44,6 +46,8 @@ class ReactiveMove(Node):
self
.
_previousScanTime
=
None
self
.
_points
=
[]
self
.
_firstPointSeen
=
None
self
.
_leftWheelDropped
=
False
self
.
_rightWheelDropped
=
False
...
...
@@ -55,6 +59,15 @@ class ReactiveMove(Node):
self
.
_previousScanTime
=
time
.
time
()
def
wheel_callback
(
self
,
msg
):
"""
Save received wheel state informations (dropped)
"""
if
(
msg
.
wheel
==
msg
.
LEFT
):
self
.
_leftWheelDropped
=
msg
.
state
==
msg
.
DROPPED
else
:
self
.
_rightWheelDropped
=
msg
.
state
==
msg
.
DROPPED
def
calcul_velo
(
self
):
"""
...
...
@@ -69,6 +82,12 @@ class ReactiveMove(Node):
print
(
"No data received for more than 1s"
)
return
Twist
()
# Return a zero velocity
# If both robot wheels are dropped (i.e. the robot is not on the floor), stop the robot movement
if
self
.
_leftWheelDropped
and
self
.
_rightWheelDropped
:
print
(
"The robot is not on the floor"
)
return
Twist
()
# Return a zero velocity
# Default case
x
,
y
=
firstPointInFront
(
self
.
_points
,
self
.
RECT_LENGTH
,
self
.
RECT_WIDTH
/
2.0
)
...
...
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