Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn function #953

Open
wants to merge 76 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
806a60e
samplesview9
jacobrask15 Mar 27, 2023
9348a5f
samplesview3
jacobrask15 Mar 27, 2023
53acd79
samplesview90
jacobrask15 Mar 27, 2023
4e42a18
samplesview3
jacobrask15 Mar 27, 2023
d68c271
V0.1
AskjaerJ Mar 27, 2023
c63832b
Merge branch 'master' of https://github.com/AskjaerJ/turtlebot3
AskjaerJ Mar 27, 2023
fb41aa4
v0.1
AskjaerJ Mar 27, 2023
352b1bc
v0.2
AskjaerJ Mar 27, 2023
acd66a3
imported
jacobrask15 Mar 27, 2023
a38716d
reset
jacobrask15 Mar 27, 2023
0f9df8a
cone, revers, turn
jacobrask15 Mar 28, 2023
3a93cbe
Add files via upload
jacobrask15 Mar 28, 2023
83010fb
.
jacobrask15 Mar 28, 2023
d18815c
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
f80d521
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
e1c1a11
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
40fb8d7
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
c749ae0
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
2c34ea0
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
4970fc8
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
f3b5812
min function print lidar distances
jacobrask15 Apr 17, 2023
ace5d8e
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
191bd4b
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
743263e
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
af4c9ef
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
6421a9b
Update turtlebot3_obstacle
jacobrask15 Apr 17, 2023
154c7f2
cone, reverse turn
jacobrask15 Apr 17, 2023
5bc52bd
decreased speed
jacobrask15 Apr 17, 2023
689b928
reversed speed
jacobrask15 Apr 17, 2023
32953b8
fix
jacobrask15 Apr 17, 2023
06714ac
bip
jacobrask15 Apr 17, 2023
ed458c6
fix
jacobrask15 Apr 17, 2023
1cce494
better turn
jacobrask15 Apr 17, 2023
b923d14
fix
jacobrask15 Apr 17, 2023
c51f859
fix
jacobrask15 Apr 17, 2023
0106f90
fix
jacobrask15 Apr 17, 2023
beb4ef0
fix
jacobrask15 Apr 17, 2023
6b6fc93
attempt at av_lin_speed
jacobrask15 Apr 24, 2023
02bf70d
average speed
jacobrask15 Apr 24, 2023
bd5cb6a
fix
jacobrask15 Apr 24, 2023
febd8de
fix
jacobrask15 Apr 24, 2023
5978fee
fix
jacobrask15 Apr 24, 2023
0d6efc6
fix
jacobrask15 Apr 24, 2023
1d2f076
fix
jacobrask15 Apr 24, 2023
ca7ad13
fix
jacobrask15 Apr 24, 2023
83a7e1d
fix
jacobrask15 Apr 24, 2023
d0f4851
fix
jacobrask15 Apr 24, 2023
c694671
no time
jacobrask15 Apr 24, 2023
01ad907
no time
jacobrask15 Apr 24, 2023
28ec605
fix
jacobrask15 Apr 24, 2023
a25ed99
time
jacobrask15 Apr 24, 2023
eadfe5d
fix
jacobrask15 Apr 24, 2023
aa1ebd8
fix
jacobrask15 Apr 24, 2023
e7079f1
fix
jacobrask15 Apr 24, 2023
29a4cd7
average speed
jacobrask15 Apr 24, 2023
20f399d
fix
jacobrask15 Apr 24, 2023
3a91440
fix
jacobrask15 Apr 24, 2023
66bba3b
done for the day
jacobrask15 Apr 24, 2023
4269f04
3 cones
jacobrask15 May 1, 2023
b25edfb
fixwa
jacobrask15 May 1, 2023
efd2558
60secs
jacobrask15 May 1, 2023
fe8adfe
0.1 0.22
jacobrask15 May 1, 2023
881e50d
bip
jacobrask15 May 1, 2023
c47a4cc
bip
jacobrask15 May 1, 2023
124404a
cum
jacobrask15 May 1, 2023
dec44f8
cum
jacobrask15 May 1, 2023
aef7b2e
center
jacobrask15 May 1, 2023
b62026b
pi
jacobrask15 May 1, 2023
61f342f
bip
jacobrask15 May 1, 2023
bced7e8
fixes
jacobrask15 May 1, 2023
395a4f1
hej
jacobrask15 May 1, 2023
18d2a96
no linear
jacobrask15 May 1, 2023
905e130
git pull
jacobrask15 May 1, 2023
866e74c
bip
jacobrask15 May 1, 2023
dc4fab9
function
jacobrask15 May 1, 2023
a5864a4
lort
jacobrask15 May 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.sourceDirectory": "C:/KODE/2_semester_kode/Computer_teknologi_projekt/askjaer_turtlebot3/turtlebot3/turtlebot3"
}
97 changes: 78 additions & 19 deletions turtlebot3_example/nodes/turtlebot3_obstacle
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,31 @@ import rospy
import math
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist
import time # time module

LINEAR_VEL = 0.22
STOP_DISTANCE = 0.2
STOP_DISTANCE = 0.50
LIDAR_ERROR = 0.05
ANGLE = 90
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


samples = len(scan.ranges) # The number of samples is defined in
# turtlebot3_<model>.gazebo.xacro file,
# the default is 360.

samples_view = ANGLE # 1 <= samples_view <= samples

if samples_view > samples:
samples_view = samples

Expand All @@ -50,40 +55,93 @@ class Obstacle():
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):
# set value to 3.5 in case of a faulty reading and hope we don't get all 0 readings
if scan_filter[i] == float('Inf'):
scan_filter[i] = 3.5
elif math.isnan(scan_filter[i]):
scan_filter[i] = 0

scan_filter[i] = 3.5
elif scan_filter[i] == 0:
scan_filter[i] = 3.5

return scan_filter



def obstacle(self):
twist = Twist()
turtlebot_moving = True
t_end = time.time() + 60 # time_time returns time since 1st jan 1970
speed_updates = 0 # for average speed
speed_accumulation = 0 # for average speed
collision_count = 0 # collision counter

#function for turning
def turn(min_left, min_right, turn_value):
if min_right < min_left:
twist.angular.z = turn_value # left
self._cmd_pub.publish(twist)
rospy.loginfo('Turn left!')
else: # min_distance_left < min_distance_right
twist.angular.z = -turn_value # right
self._cmd_pub.publish(twist)
rospy.loginfo('Turn right!')

while not rospy.is_shutdown():
#runtime loopet
while time.time() < t_end: # runs for 60 secs
lidar_distances = self.get_scan()
min_distance = min(lidar_distances)
min_distance_right = min(lidar_distances[0:29])
min_distance_center = min(lidar_distances[30:59])
min_distance_left = min(lidar_distances[60:89])

if min_distance < SAFE_STOP_DISTANCE:
if turtlebot_moving:
twist.linear.x = 0.0
twist.angular.z = 0.0
if min_distance_center < SAFE_STOP_DISTANCE: # something need to be happen
if min_distance_center > 0.40: # dist between 55 and 35
rospy.loginfo('Between 55 and 40')
turn(min_distance_left, min_distance_right, 1)

elif min_distance_center > 0.25: # dist between 35 and 20
rospy.loginfo('Between 40 and 25')
if min_distance_right < min_distance_left:
# twist.linear.x *= 0.5
twist.angular.z = 2 # left
self._cmd_pub.publish(twist)
rospy.loginfo('Turn left!')
else: # min_distance_left < min_distance_right
# twist.linear.x *= 0.5
twist.angular.z = -2 # right
self._cmd_pub.publish(twist)
rospy.loginfo('Turn right!')
else:
rospy.loginfo('Below 20')
twist.linear.x = 0
twist.angular.z = 5 # left
self._cmd_pub.publish(twist)
turtlebot_moving = False
rospy.loginfo('Stop!')
rospy.loginfo('Turn left!')

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)
rospy.loginfo('Distance of the obstacle : %f',
min_distance_center)

# collision
if min_distance_center < 0.15 or min_distance_left < 0.15 or min_distance_right < 0.15:
collision_count = collision_count + 1

speed_updates = speed_updates + 1
speed_accumulation = speed_accumulation + twist.linear.x

rospy.loginfo('average speed : %f', speed_accumulation / speed_updates)
rospy.loginfo('collision count : %f', collision_count)


def main():
rospy.init_node('turtlebot3_obstacle')
Expand All @@ -92,5 +150,6 @@ def main():
except rospy.ROSInterruptException:
pass


if __name__ == '__main__':
main()