diff --git a/lesson_04/letter.py b/lesson_04/letter.py new file mode 100644 index 0000000000000000000000000000000000000000..16dd9ce7326611c09490bf715f41e74b2df6f9c3 --- /dev/null +++ b/lesson_04/letter.py @@ -0,0 +1,48 @@ +import rclpy +from rclpy.node import Node +from rclpy.duration import Duration + +from geometry_msgs.msg import Twist +import math + + +class RurMover(Node): + def __init__(self): + super().__init__('minimal_publisher') + self.publisher_twist = self.create_publisher(Twist, 'turtle1/cmd_vel', 10) + self.main() + + def publish_twist(self, linear, angular): + self.get_logger().info('Linear: "%d", angular: "%d"' % (linear, angular)) + msg = Twist() + msg.linear.x = float(linear) + msg.angular.z = math.radians(float(angular)) + self.publisher_twist.publish(msg) + self.get_clock().sleep_for(Duration(seconds=1.0)) + + def main(self): + self.publish_twist(0, 135.0) + self.publish_twist(1, 0.0) + self.publish_twist(0, 90.0) + self.publish_twist(1, 0.0) + self.publish_twist(0, 55.0) + self.publish_twist(1, 0.0) + self.publish_twist(0, 45.0) + self.publish_twist(1, 0.0) + self.publish_twist(0, -45.0) + self.publish_twist(1, 0.0) + self.publish_twist(0, -45.0) + self.publish_twist(1, 0.0) + +def main(args=None): + rclpy.init(args=args) + + mover = RurMover() + + rclpy.spin(mover) + + mover.destroy_node() + rclpy.shutdown() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/setup.py b/setup.py index 9e5dc57746bf472f3cb9ce74d49c8f79078942e7..20e9cc17de538b686e773a23ba9a16bc45db073e 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ setup( 'step_3 = lesson_04.step_3:main', 'square = lesson_04.square:main', 'mover = lesson_04.mover:main', + 'letter = lesson_04.letter:main', ], }, )