-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_0.py
152 lines (119 loc) · 3.94 KB
/
task_0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
'''
*****************************************************************************************
*
* ===============================================
* HolA Bot (HB) Theme (eYRC 2022-23)
* ===============================================
*
* This script should be used to implement Task 0 of HolA Bot (KB) Theme (eYRC 2022-23).
*
* This software is made available on an "AS IS WHERE IS BASIS".
* Licensee/end user indemnifies and will keep e-Yantra indemnified from
* any and all claim(s) that emanate from the use of the Software or
* breach of the terms of this agreement.
*
*****************************************************************************************
'''
# Team ID:1776 [ Team-ID ]
# Author List:Dhanvantraj.M,Vinoth.B,Winston Doss,Madhusudhanan.K [ Names of team members worked on this file separated by Comma: Name1, Name2, ... ]
# Filename:HB_1776.py
# Functions:main,callback
# [ Comma separated list of functions in this file ]
# Nodes:pub,sub Add your publishing and subscribing node
####################### IMPORT MODULES #######################
import sys
import traceback
import rospy
from geometry_msgs.msg import Twist
from turtlesim.msg import Pose
import math
##############################################################
def callback(data):
"""
Purpose:
---
This function should be used as a callback. Refer Example #1: Pub-Sub with Custom Message in the Learning Resources Section of the Learning Resources.
You can write your logic here.
NOTE: Radius value should be 1. Refer expected output in document and make sure that the turtle traces "same" path.
Input Arguments:
---
`data` : []
data received by the call back function
Returns:
---
May vary depending on your logic.
Example call:
---
Depends on the usage of the function.
"""
global angle
global ypos
angle=data.theta
ypos=data.y
def main():
"""
Purpose:
---
This function will be called by the default main function given below.
You can write your logic here.
Input Arguments:
---
None
Returns:
---
None
Example call:
---
main()
"""
rospy.init_node('move_turtle')
pub=rospy.Publisher('/turtle1/cmd_vel',Twist,queue_size=10)
sub=rospy.Subscriber('/turtle1/pose',Pose,callback)
rate=rospy.Rate(160) #10hz
vel=Twist() #twist variable created
while not rospy.is_shutdown():
if(angle>=0):
vel.linear.x=1
vel.angular.z=1
rospy.loginfo(angle)
rospy.loginfo("My TurtleBot moving in circle")
elif(angle<=-(math.pi/2)):
vel.linear.x=0
rospy.loginfo(angle)
rospy.loginfo("My TurtleBot is rotating")
elif(round(angle,0)>=round(-(math.pi/2),0) and angle<0 ):
vel.linear.x=1
vel.angular.z=0
rospy.loginfo(angle)
rospy.loginfo("My TurtleBot moving in straight line")
if(ypos<5.4 and angle<0):
vel.linear.x=0
pub.publish(vel)
rospy.loginfo(angle)
rospy.loginfo("DONE")
rospy.signal_shutdown("DONE")
pub.publish(vel)
rate.sleep()
################# ADD GLOBAL VARIABLES HERE #################
angle=0
ypos=5.4
##############################################################
################# ADD UTILITY FUNCTIONS HERE #################
##############################################################
######### YOU ARE NOT ALLOWED TO MAKE CHANGES TO THIS PART #########
if __name__ == "__main__":
try:
print("------------------------------------------")
print(" Python Script Started!! ")
print("------------------------------------------")
main()
except:
print("------------------------------------------")
traceback.print_exc(file=sys.stdout)
print("------------------------------------------")
sys.exit()
finally:
print("------------------------------------------")
print(" Python Script Executed Successfully ")
print("------------------------------------------")