updated package
This commit is contained in:
parent
30995c709a
commit
979eb7342f
51
.gitignore
vendored
Normal file
51
.gitignore
vendored
Normal file
@ -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
|
@ -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.
|
||||
|
@ -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()
|
@ -9,8 +9,6 @@
|
||||
|
||||
<depend>rclpy</depend>
|
||||
<depend>example_interfaces</depend>
|
||||
<depend>pygame</depend>
|
||||
<depend>time</depend>
|
||||
<depend>geometry_msgs</depend>
|
||||
<depend>functools</depend>
|
||||
<depend>my_robot_interfaces</depend>
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user