Skip to content

Commit

Permalink
Tweaked bin/{ros2_example.sh,ws_update.py} Added serial_agent_generat…
Browse files Browse the repository at this point in the history
…or.py.
  • Loading branch information
waynegramlich committed Jun 23, 2021
1 parent ff26a8a commit 3af660f
Show file tree
Hide file tree
Showing 5 changed files with 791 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/ros2_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,7 @@ tree "${DEV_WS}"

# [Define custom messages in python package (ROS2)](https://answers.ros.org/question/350084/define-custom-messages-in-python-package-ros2/)
# [Publishing in Python with custom message fails.](https://github.com/ros2/ros2/issues/682)

# [Serial/TCP Interconnect](https://superuser.com/questions/614494/redirect-serial-com-to-tcp-port)

# [Raspberry Pi UART](https://raspberrypi.stackexchange.com/questions/1094/how-can-i-set-the-uart-speed)
47 changes: 47 additions & 0 deletions bin/ws_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,50 @@ def python_label_entries_find(

if __name__ == "__main__":
main(tracing=" ")

# [ROS Python Launch Files](https://www.youtube.com/watch?v=RDoig5qEHRM)

# Note that PKG only occurs onece
# mkdir -p WS/PKG/launch
# cat >> WS/src/PKG/launch/launch.py <<EOF # Note it is not PKG/PKG
# from launch import LaunchDescription
# from launch_ros.actions import Node
#
# def generate_launch_description():
# return LaunchDescription([
# Node(
# package="py_pubsub",
# executable="talker",
# output="screen",
# ),
# Node(
# package="py_pubsub",
# executable="listener",
# output="screen",
# ),
# ])
# EOF

# in setyp.py
# Add: imports:
# from setuptools import setup # Already presetn
# import os # For os is for os.join() only
# from glob import glob
#
# in data_files add:
# (os.path.join('share', package_name, 'launch'), glob('launch/*.py')),

# Run `colcon build`
#
# source intall/setup.bash
# ros2 launch py_pubsub launch.py

# [https://roboticsbackend.com/ros2-launch-file-example/](https://roboticsbackend.com/ros2-launch-file-example/)

# [Writing a ROS 2 launch file](https://github.com/bponsler/ros2-support/blob/master/tutorials/ros2-launch.md)

# [ROS2 Launch File Migrator](https://github.com/aws-robotics/ros2-launch-file-migrator)
# Look at the test fixtures.

# [ROS1 roslaunch](http://wiki.ros.org/roslaunch)
# [ROS1 roslaunch XML](http://wiki.ros.org/roslaunch/XML/launch)
132 changes: 132 additions & 0 deletions software/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2401,3 +2401,135 @@ To copy an Eclipse project.
[Eclipse JLink FreeRTOS Notes](https://www.freertos.org/FreeRTOS_Support_Forum_Archive/February_2010/freertos_freeRTOS_w_Eclipse_and_JLink_3541181.html)
-->
<!--
Serial line bridge protocol.
Using the ROS2 Python interface, it is possible to dynamically access topics
(i.e publish and subscribe), services (i.e. remote procedure call), and configuration parameters.
Conceptually, the bridge protocol allows a microcontroller running an RTOS
(Real Time Operating System) to interact with the ROS2 Python Interface running on another machine
via the serial protocol.
The serial line protocol uses a serial line to bridge between two processors --
an agent processor
[Create Dynamic Types](https://www.geeksforgeeks.org/create-classes-dynamically-in-python/)
# [importlib Tutorial](https://realpython.com/python-import/)
# Equivalant to `from tutorial_interfaces.msg import Num`
import importlib
tutorial_interfaces_module = importlib.import_module("tutorial_interfaces.msg")
num_class = getattr(tutoral_interfaces_module, "Num")
assert isinstance(num_class, class)
# contructor
parent_class = ...
def constructor(self, arg):
parent_class.__init__(self, arg)
self.constructor_arg = arg
# method
def display_method(self, arg):
print arg
# class method
@classmethod
def class_method(cls, arg):
print(arg)
# create class dynamically
Geeks = type("Geeks", (object, ), {
# constrcuctor
"__init__": constructor
# data members:
"string_attr": "A string",
"int_attr: 1234,
# member functions:
"func_arg": display_method,
"class_func": class_method,
})
-->

<!--
# Copyright 2016 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import rclpy
from rclpy.node import Node
# from std_msgs.msg import String ## Imported via importlib below!
import importlib
def fred_callback(msg):
print(f"Fred callback '{msg}'")
def wilma_callback(msg):
print(f"Wilma callback '{msg}'")
class MinimalSubscriber(Node):
def __init__(self):
super().__init__('minimal_subscriber')
# Equivalant to `from tutorial_interfaces.msg import String`
tutorial_interfaces_module = importlib.import_module("std_msgs.msg")
String = getattr(tutorial_interfaces_module, "String")
self._subscriptions = []
self._subscriptions.append(self.create_subscription(
String,
'topic',
fred_callback,
10))
self._subscriptions.append(self.create_subscription(
String,
'topic',
wilma_callback,
10))
def main(args=None):
rclpy.init(args=args)
minimal_subscriber = MinimalSubscriber()
assert isinstance(minimal_subscriber, Node), f"Not a Node {type(minimal_subscriber)}"
rclpy.spin(minimal_subscriber)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_subscriber.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
-->

<!--
[Acutal rclpy API Documentation](https://docs.ros2.org/latest/api/rclpy/api/topics.html#module-rclpy.subscription)
[Example callback group](https://github.com/ros2/examples/blob/master/rclpy/executors/examples_rclpy_executors/callback_group.py)
[Redirect serial com to TCP](https://superuser.com/questions/614494/redirect-serial-com-to-tcp-port)
-->
Empty file.
Loading

0 comments on commit 3af660f

Please sign in to comment.