From 34eb826457774a0fc66d983e1f1ba35fc3a4c502 Mon Sep 17 00:00:00 2001 From: Diego <47353238+dsoldev@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:48:38 -0300 Subject: [PATCH] Update quadrado.py --- .../modulo4/scripts_resp/quadrado.py | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/docs/modulos/04-ROS-basico/modulo4/scripts_resp/quadrado.py b/docs/modulos/04-ROS-basico/modulo4/scripts_resp/quadrado.py index be8b394d..b2cc4052 100644 --- a/docs/modulos/04-ROS-basico/modulo4/scripts_resp/quadrado.py +++ b/docs/modulos/04-ROS-basico/modulo4/scripts_resp/quadrado.py @@ -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') @@ -58,4 +55,4 @@ def main(): control.control() if __name__=="__main__": - main() \ No newline at end of file + main()