From 979eb7342f733bfeae4ebf81856ee3af30d69cae Mon Sep 17 00:00:00 2001 From: locker98 Date: Wed, 18 Dec 2024 19:35:50 -0500 Subject: [PATCH] updated package --- .gitignore | 51 +++++++++++++++++++++++++++ README.md | 3 +- my_py_pkg/my_py_pkg/joy_move.py | 62 --------------------------------- my_py_pkg/package.xml | 2 -- my_py_pkg/setup.py | 1 - 5 files changed, 53 insertions(+), 66 deletions(-) create mode 100644 .gitignore delete mode 100755 my_py_pkg/my_py_pkg/joy_move.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35d74bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,51 @@ +devel/ +logs/ +build/ +bin/ +lib/ +msg_gen/ +srv_gen/ +msg/*Action.msg +msg/*ActionFeedback.msg +msg/*ActionGoal.msg +msg/*ActionResult.msg +msg/*Feedback.msg +msg/*Goal.msg +msg/*Result.msg +msg/_*.py +build_isolated/ +devel_isolated/ + +# Generated by dynamic reconfigure +*.cfgc +/cfg/cpp/ +/cfg/*.py + +# Ignore generated docs +*.dox +*.wikidoc + +# eclipse stuff +.project +.cproject + +# qcreator stuff +CMakeLists.txt.user + +srv/_*.py +*.pcd +*.pyc +qtcreator-* +*.user + +/planning/cfg +/planning/docs +/planning/src + +*~ + +# Emacs +.#* + +# Catkin custom files +CATKIN_IGNORE diff --git a/README.md b/README.md index b8acd1c..feb43a7 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# ros2-example +# Udemy Course 1 +This is my code and scripts from the udemy course I took [here](https://www.udemy.com/course/ros2-for-beginners/?couponCode=ST21MT121624). I was an amazing course and I would highly recommend it for getting an basic introduction to ROS 2. diff --git a/my_py_pkg/my_py_pkg/joy_move.py b/my_py_pkg/my_py_pkg/joy_move.py deleted file mode 100755 index 930f8fe..0000000 --- a/my_py_pkg/my_py_pkg/joy_move.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python -import rclpy -from rclpy.node import Node -import pygame -import time -from geometry_msgs.msg import Twist - - - - - -class JoyMoveNode(Node): - def __init__(self, joystick): - super().__init__("joy_move") - self.joystick = joystick - self.publisher_ = self.create_publisher(Twist, "/cmd_vel", 10) - self.timer_ = self.create_timer(0.1, self.publish_news) - self.get_logger().info("Starting the robot news station") - - def publish_news(self): - r, move = self.get_joystick_right_stick() - - msg = Twist() - msg.linear.x = move*2 - msg.angular.z = r*2 - self.publisher_.publish(msg) - - def get_joystick_right_stick(self): - # Pump the event queue to prevent freezing - pygame.event.pump() - # Get right joystick axis values - right_x = round(self.joystick.get_axis(3), 2)/4 # Adjust index if not correct - right_y = round(self.joystick.get_axis(4), 2)/4 # Adjust index if not correct - if right_x < 0.02 and right_x > -0.02: - right_x = 0.0 - if right_y < 0.02 and right_y > -0.02: - right_y = 0.0 - return right_x, -right_y - - - -def main (args=None): - # Initialize pygame - pygame.init() - pygame.joystick.init() - # Find Controller - if pygame.joystick.get_count() == 0: - print("No joystick detected.") - exit(0) - - # Open the first joystick - joystick = pygame.joystick.Joystick(0) - joystick.init() - - # Start ROS 2 Node - rclpy.init(args=args) - node = JoyMoveNode(joystick) - rclpy.spin(node) - rclpy.shutdown() - -if __name__ == '__main__': - main() diff --git a/my_py_pkg/package.xml b/my_py_pkg/package.xml index d7a722a..603c933 100644 --- a/my_py_pkg/package.xml +++ b/my_py_pkg/package.xml @@ -9,8 +9,6 @@ rclpy example_interfaces - pygame - time geometry_msgs functools my_robot_interfaces diff --git a/my_py_pkg/setup.py b/my_py_pkg/setup.py index f9cfb2e..ffdd7ce 100644 --- a/my_py_pkg/setup.py +++ b/my_py_pkg/setup.py @@ -24,7 +24,6 @@ setup( "py_node = my_py_pkg.my_first_node:main", "smartphone = my_py_pkg.smartphone:main", "add_two_ints_server = my_py_pkg.add_two_ints_server:main", - "joy_move = my_py_pkg.joy_move:main", "add_two_ints_client_no_oop = my_py_pkg.add_two_ints_client_no_oop:main", "add_two_ints_client = my_py_pkg.add_two_ints_client:main", "hardware_status_publisher = my_py_pkg.hw_status_publisher:main",