Is the new Raspberry Pi AI Kit better than Google Coral?
128827 Views
Build Your Own AI Assistant Part 1 - Creating the Assistant
120382 Views
Control Arduino with Python using Firmata / PyFirmata
88230 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
62460 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
58121 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
53235 Views
Pico Plotter
LEGO Gets Lights & Sound with Tiny FX
Thinkman
Podman vs Docker
MicroPython Robotics
Bottango and Isaaca
Getting Started with C on the Raspberry Pi Pico
0h 20m
Running K3s on Raspberry Pi
0h 36m
From Docker to Podman
0h 28m
MicroPython Robotics Projects with the Raspberry Pi Pico
0h 24m
Bottango Basics
0h 22m
Mini-Rack 3D Design Tutorial
Learn how to Program in Python, C, Rust, and more.
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
70% Percent Complete
By Kevin McAleer, 2 Minutes
touch my_py_pkg/sub.py chmod -R 777 my_py_pkg
This will create the new empty file, and fix the permissions so we can write to it from VS Code.
Cut and paste the following code into the new file:
import rclpy from rclpy.node import Node from std_msgs.msg import String class Listener(Node): def __init__(self): super().__init__("node_test") self.counter_ = 0 # create_subscriber needs 3 parameters: Msg Type, topic name, the callback, and queue size buffer self.subscriber = self.create_subscription(String, "Hello", self.callback_hello, 10) self.get_logger().info("Subscribed to Hello topic") def callback_hello(self, message): self.get_logger().info(message.data) def main(args=None): rclpy.init(args=args) node = Listener() rclpy.spin(node) rclpy.shutdown() if __name__ == "__main__": main()
We now need to update setup.py to include the entry_point for our code. An entry point is the name of the python scripts that are available to run from with the package, and are shown in the list when you type ros2 run my_py_pkg.
setup.py
entry point
ros2 run my_py_pkg
my_py_pkg
entry_points={ 'console_scripts' : [ "pub = my_py_pkg.pub:main", "talker = my_py_pkg.talker:main", "listener = my_py_pkg.sub:main" ], },
We can now build out package using colcon build. Do this from the root of the workspace (in this case /ros2/my_py_pkg):
colcon build
/ros2/my_py_pkg
cd /ros2/my_py_pkg
colcon build source install/setup.bash
< Previous Next >
You can use the arrows ← → on your keyboard to navigate between lessons.
← →