Skip to content

Commit

Permalink
Update quadrado.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dsoldev authored Oct 30, 2023
1 parent 387043f commit 34eb826
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions docs/modulos/04-ROS-basico/modulo4/scripts_resp/quadrado.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,34 @@ def __init__(self):
# Subscribers

# Publishers
self.cmd_vel_pub = rospy.Publisher("cmd_vel", Twist, queue_size=3)
self.dormir = 5.0
self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=3)

self.cmd_vel_pub.publish(Twist())

def forward(self, distance: float = 0.5, vel = Twist()) -> None:
vel.linear.x = distance / self.dormir
vel.linear.x = 0.5
self.cmd_vel_pub.publish(vel)
rospy.sleep(self.dormir)
delta_t = distance / vel.linear.x
rospy.sleep(delta_t)
self.cmd_vel_pub.publish(Twist())


def rotate(self, angle: float = np.pi/2, vel = Twist()) -> None:
vel.angular.z = angle / self.dormir
vel.angular.z = np.pi/2
self.cmd_vel_pub.publish(vel)
rospy.sleep(self.dormir)
delta_t = angle / vel.angular.z
rospy.sleep(delta_t)


def control(self):
'''
This function is called at least at {self.rate} Hz.
This function controls the robot.
'''
self.forward()
self.rotate()

self.forward()
self.rotate()

self.forward()
self.rotate()
for _ in range(4):
self.forward()
self.rotate()

self.forward()
self.rotate()

def main():
rospy.init_node('Controler')
Expand All @@ -58,4 +55,4 @@ def main():
control.control()

if __name__=="__main__":
main()
main()

0 comments on commit 34eb826

Please sign in to comment.