Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Semesterprojekt Modulbasiertes Testen
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Trappe
Semesterprojekt Modulbasiertes Testen
Commits
9f61abf9
Commit
9f61abf9
authored
5 years ago
by
Christopher Klaus Lazik
Browse files
Options
Downloads
Patches
Plain Diff
New obstacle detection
parent
698372c1
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ROS/turtlebot3_obstacle
+97
-0
97 additions, 0 deletions
ROS/turtlebot3_obstacle
with
97 additions
and
0 deletions
ROS/turtlebot3_obstacle
0 → 100755
+
97
−
0
View file @
9f61abf9
#!/usr/bin/env python
#################################################################################
# Copyright 2018 ROBOTIS CO., LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#################################################################################
# Authors: Gilbert #
import
rospy
import
math
from
sensor_msgs.msg
import
LaserScan
from
geometry_msgs.msg
import
Twist
LINEAR_VEL
=
0.22
STOP_DISTANCE
=
0.2
LIDAR_ERROR
=
0.05
SAFE_STOP_DISTANCE
=
STOP_DISTANCE
+
LIDAR_ERROR
class
Obstacle
():
def
__init__
(
self
):
self
.
_cmd_pub
=
rospy
.
Publisher
(
'
cmd_vel
'
,
Twist
,
queue_size
=
1
)
self
.
obstacle
()
def
get_scan
(
self
):
scan
=
rospy
.
wait_for_message
(
'
scan
'
,
LaserScan
)
scan_filter
=
[]
samples
=
len
(
scan
.
ranges
)
# The number of samples is defined in
# turtlebot3_<model>.gazebo.xacro file,
# the default is 360.
samples_view
=
1
# 1 <= samples_view <= samples
if
samples_view
>
samples
:
samples_view
=
samples
if
samples_view
is
1
:
scan_filter
.
append
(
scan
.
ranges
[
0
])
else
:
left_lidar_samples_ranges
=
-
(
samples_view
//
2
+
samples_view
%
2
)
right_lidar_samples_ranges
=
samples_view
//
2
left_lidar_samples
=
scan
.
ranges
[
left_lidar_samples_ranges
:]
right_lidar_samples
=
scan
.
ranges
[:
right_lidar_samples_ranges
]
scan_filter
.
extend
(
left_lidar_samples
+
right_lidar_samples
)
for
i
in
range
(
samples_view
):
if
scan_filter
[
i
]
==
float
(
'
Inf
'
):
scan_filter
[
i
]
=
float
(
'
Inf
'
)
elif
math
.
isnan
(
scan_filter
[
i
]):
scan_filter
[
i
]
=
-
1
return
scan_filter
def
obstacle
(
self
):
twist
=
Twist
()
turtlebot_moving
=
True
while
not
rospy
.
is_shutdown
():
lidar_distances
=
self
.
get_scan
()
min_distance
=
min
(
lidar_distances
)
if
min_distance
<
SAFE_STOP_DISTANCE
:
if
turtlebot_moving
:
twist
.
linear
.
x
=
0.0
twist
.
angular
.
z
=
0.0
self
.
_cmd_pub
.
publish
(
twist
)
turtlebot_moving
=
False
rospy
.
loginfo
(
'
Distance of the obstacle : %f
'
,
min_distance
)
rospy
.
loginfo
(
'
Stop!
'
)
else
:
twist
.
linear
.
x
=
LINEAR_VEL
twist
.
angular
.
z
=
0.0
self
.
_cmd_pub
.
publish
(
twist
)
turtlebot_moving
=
True
rospy
.
loginfo
(
'
Distance of the obstacle : %f
'
,
min_distance
)
def
main
():
rospy
.
init_node
(
'
turtlebot3_obstacle
'
)
try
:
obstacle
=
Obstacle
()
except
rospy
.
ROSInterruptException
:
pass
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment