ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

AndrewJSchoen's profile - activity

2023-01-23 11:10:14 -0500 received badge  Taxonomist
2021-06-14 03:41:18 -0500 received badge  Famous Question (source)
2021-02-10 08:56:11 -0500 received badge  Notable Question (source)
2021-01-03 19:17:42 -0500 commented answer ROS2 Flask Threading issue

assert_liveliness is a method that Node objects have. Since MyNode inherits from it, I use it there.

2020-12-28 09:37:49 -0500 marked best answer colcon python package build error with rust extension

Info:

ROS 2 Version: Foxy

OS: macOS Big Sur

Python: 3.9

colcon_python_setup_py: 0.2.7

I have been looking for ways to get some rust-based code to play nicely with a bunch of python-based ROS 2 code. Given that the last I checked, official ROS2 bindings were not quite working for rust, I thought I might be able to wrap up the rust code (which is really standalone) I had into a single module, and then create bindings for it with PyO3. That way, after building, I could simply import the rust library within python and use ROS 2 at that point.

I created a super-simple test package. I have gotten it to work when cd-ing into the package and running python3 setup.py bdist_wheel, and it does indeed generate the required .so files, which work correctly from within python.

For ease, here is the setup.py file that does that:

from setuptools import setup
from setuptools_rust import Binding, RustExtension

package_name = 'rust_test'

setup(
    name=package_name,
    version='0.1.0',
    packages=[package_name],
    rust_extensions=[RustExtension("rust_test.rust_test", binding=Binding.PyO3)],
    data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
    ],
    install_requires=['setuptools','wheel','setuptools_rust'],
    include_package_data=True,
    zip_safe=False,
    maintainer='schoen',
    maintainer_email='schoen@todo.todo',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
        ],
    },
)

However, when I execute colcon build --symlink-install --packages-select rust_test, it fails with the following error:

Starting >>> rust_test
--- stderr: rust_test                   
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/colcon_core/executor/__init__.py", line 91, in __call__
    rc = await self.task(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/colcon_core/task/__init__.py", line 93, in __call__
    return await task_method(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/colcon_ros/task/ament_python/build.py", line 51, in build
    setup_py_data = get_setup_data(self.context.pkg, env)
  File "/usr/local/lib/python3.9/site-packages/colcon_core/task/python/__init__.py", line 20, in get_setup_data
    return dict(pkg.metadata[key](env))
  File "/usr/local/lib/python3.9/site-packages/colcon_ros/package_identification/ros.py", line 129, in getter
    return get_setup_information(
  File "/usr/local/lib/python3.9/site-packages/colcon_python_setup_py/package_identification/python_setup_py.py", line 241, in get_setup_information
    _setup_information_cache[hashable_env] = _get_setup_information(
  File "/usr/local/lib/python3.9/site-packages/colcon_python_setup_py/package_identification/python_setup_py.py", line 286, in _get_setup_information
    return ast.literal_eval(output)
  File "/usr/local/Cellar/python@3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ast.py", line 62, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/local/Cellar/python@3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    {'package_data': {}, 'dist_files': [], 'src_root': None, 'dependency_links': [], 'setup_requires': [], 'convert_2to3_doctests': [], 'eager_resources': None, 'entry_points': {'console_scripts': []}, 'exclude_package_data': None, 'extras_require': {}, 'include_package_data': True, 'install_requires': ['setuptools', 'wheel', 'setuptools_rust'], 'namespace_packages': None, 'packages': ['rust_test'], 'python_requires': None, 'test_loader': None, 'test_runner': None, 'test_suite': None, 'tests_require': ['pytest'], 'use_2to3': None, 'use_2to3_exclude_fixers': None, 'use_2to3_fixers': None, 'zip_safe': False, 'rust_extensions': [<setuptools_rust.extension.RustExtension object at 0x104bb6e20>], 'cffi_modules': None, 'verbose': 1, 'dry_run ...
(more)
2020-12-18 15:18:37 -0500 received badge  Popular Question (source)
2020-12-15 15:11:58 -0500 received badge  Organizer (source)
2020-12-15 15:11:21 -0500 edited question colcon python package build error with rust extension

colcon python package build error with rust extension Info: ROS 2 Version: Foxy OS: macOS Big Sur Python: 3.9 colcon

2020-12-15 15:11:01 -0500 edited question colcon python package build error with rust extension

colcon python package build error with rust extension Info: ROS 2 Version: Foxy OS: macOS Big Sur Python: 3.9 colcon_py

2020-12-15 15:03:30 -0500 asked a question colcon python package build error with rust extension

colcon python package build error with rust extension Info: [OS] macOS Big Sur [Python] 3.9 I have been looking for wa

2020-07-18 01:38:34 -0500 received badge  Teacher (source)
2020-07-18 01:38:34 -0500 received badge  Self-Learner (source)
2020-06-22 12:14:16 -0500 received badge  Famous Question (source)
2020-03-06 01:07:05 -0500 marked best answer ROS2 Flask Threading issue

Hi all,

I am trying to set up a ROS2 rclpy node that functions as a Flask socket server. This node needs to have a thread or timer-based process running (which handles a socket broadcast). The issue I am running into is that when I create a ROS2 timer, it seems that it never executes, and when I use a python thread, it seems to block the main process. The minimal code samples are below:

ROS2 Timer:

class MyNode(Node):

    def __init__(self):
        super(MyNode,self).__init__('my_node')
        self.get_logger().info('Initializing My Node!') # Works fine
        self.app = Flask(__name__) # Flask Stuff
        self.my_ns = NS(self)     # Custom Flask Socket Namespace
        self.socketio = SocketIO(self.app, cors_allowed_origins="*") # Create Socket
        self.socketio.on_namespace(self.my_ns) # Pair the namespace
        self.process_timer = self.create_timer(.1,self.process)
        self.get_logger().info('Initialized!') # Executes

    def process(self):
        self.get_logger().info('Running!') # Never Executes

def main(args=None):
    rclpy.init(args=args)
    node = MyNode()
    node.socketio.run(node.app)

if __name__ == '__main__':
    main()

Python Thread:

class MyNode(Node):

    def __init__(self):
        super(MyNode,self).__init__('my_node')
        self.get_logger().info('Initializing My Node!') # Works fine
        self.app = Flask(__name__) # Flask Stuff
        self.my_ns = NS(self)     # Custom Flask Socket Namespace
        self.socketio = SocketIO(self.app, cors_allowed_origins="*") # Create Socket
        self.socketio.on_namespace(self.my_ns) # Pair the namespace
        self.process_thread = Thread(target=self.process,daemon=True)
        self.process_thread.start()
        self.get_logger().info('Initialized!') # Never Executes

    def process(self):
        alive = True
        while alive:
           try:
              self.assert_liveliness()
              self.get_logger().info('Running!') # Executes
            except:
              alive = False


def main(args=None):
    rclpy.init(args=args)
    node = MyNode()
    node.socketio.run(node.app)

if __name__ == '__main__':
    main()

Thanks for the suggestions, and I will try out those changes. I should share the original code I had, which is the following:

class WizardNode(Node):

    def __init__(self):
        super(WizardNode,self).__init__('wizard')
        self.get_logger().info('Initializing Wizard Node!')
        self.app = Flask(__name__)
        self.cors = CORS(self.app)
        self.wizard = Wizard(self)
        self.socketio = SocketIO(self.app, cors_allowed_origins="*")
        self.socketio.on_namespace(self.wizard)
        self.socket_thread = Thread(target=lambda:self.socketio.run(self.app),daemon=True)
        self.socket_thread.start()
        self.process_timer = self.create_timer(.1,self.process)
        self.get_logger().info('Initialized!')
        self.printer = PrettyPrinter()

    def process(self):
        time = self.get_clock().now()
        self.wizard.timestep()



def main(args=None):
    rclpy.init(args=args)

    node = WizardNode()
    try:
        rclpy.spin(node)
    except KeyboardInterrupt:
        pass

    node.destroy_node()
    rclpy.shutdown() 

In this version, it seems that the socket.io thread fails to do any sort of broadcasting/emitting, which was why I tried restructuring in the ways above. I should also say that in this example, using eventlet's monkey_patch() basically broke everything.

2020-03-05 19:47:28 -0500 commented answer ROS2 Flask Threading issue

The flask app was being executed as a thread within the MyNode __init__ function. The actual issue was that there was an

2020-03-05 19:44:35 -0500 answered a question ROS2 Flask Threading issue

This turned out to be a bit of a fun puzzle to get ROS2 and Eventlet working together. In the end, the solution makes a

2020-03-05 19:30:18 -0500 edited question ROS2 Flask Threading issue

ROS2 Flask Threading issue Hi all, I am trying to set up a ROS2 rclpy node that functions as a Flask socket server. Thi

2020-03-05 16:21:38 -0500 received badge  Notable Question (source)
2020-02-28 15:22:27 -0500 received badge  Popular Question (source)
2020-02-28 09:53:24 -0500 received badge  Enthusiast
2020-02-27 14:48:21 -0500 edited question ROS2 Flask Threading issue

ROS2 Flask Threading issue Hi all, I am trying to set up a ROS2 rclpy node that functions as a Flask socket server. Thi

2020-02-27 14:48:21 -0500 received badge  Editor (source)
2020-02-27 12:59:01 -0500 marked best answer ROSLIB.Param.get() callback not executing

Hey all,

Not sure if something is broken, or if I am doing something wrong. I have started the bridge, and got to the point where when I load the page:

var ros = new ROSLIB.Ros({
        url: 'ws://localhost:9090'
    });
ros.on('connection', function() {
        console.log('Connected to websocket server.');
    });

Result:

"Connected to websocket server."

However, I have some parameters already on the server under the namespace /lookup. These were loaded in from a yaml file with rosparam load. When I attempt to load these values, I get no callback behavior:

var ros = new ROSLIB.Ros({
        url: 'ws://localhost:9090'
    });

var lookup = new ROSLIB.Param({
        ros : ros,
        name : '/lookup'
    });

ros.on('connection', function() {
        console.log('Connected to websocket server.');
        lookup.get(function(value){
            console.log("Lookup: "+value);
        });
        console.log('Ended connection sequence');
    });

Result:

"Connected to websocket server." "Ended connection sequence"

No errors, but no printing of my info.

I also verified that I am able to use the set command, and these parameters get set and are visible when running rosparam get <parameter>. When I tried to get this parameter with the above logic, however, it never executed the callback, as with the others.

I also tried with ros.getParams, but that didn't work either. Am I doing something incorrectly? Also, using ros-kinetic, if that helps.

2020-02-27 12:59:01 -0500 received badge  Scholar (source)
2020-02-27 12:57:17 -0500 asked a question ROS2 Flask Threading issue

ROS2 Flask Threading issue Hi all, I am trying to set up a ROS2 rclpy node that functions as a Flask socket server. Thi

2020-02-27 12:55:16 -0500 asked a question ROS2 Flask Threading issue

ROS2 Flask Threading issue Hi all, I am trying to set up a ROS2 rclpy node that functions as a Flask socket server. Thi

2020-02-27 12:55:15 -0500 asked a question ROS2 Flask Threading blocked

ROS2 Flask Threading blocked Hi all, I am trying to set up a ROS2 rclpy node that functions as a Flask socket server. T

2019-09-23 11:12:17 -0500 received badge  Famous Question (source)
2019-04-08 13:45:14 -0500 received badge  Famous Question (source)
2018-11-07 15:07:52 -0500 received badge  Notable Question (source)
2018-11-07 13:02:37 -0500 received badge  Student (source)
2018-11-07 13:02:22 -0500 received badge  Popular Question (source)
2018-09-23 18:38:17 -0500 received badge  Notable Question (source)
2018-09-22 22:18:51 -0500 received badge  Popular Question (source)
2018-09-22 19:20:51 -0500 asked a question Warning: error when crawling, Input/output error

Warning: error when crawling, Input/output error Hey all, I am getting an interesting error with ROS Kinetic 1.12.14,

2018-07-16 11:58:01 -0500 edited question ROSLIB.Param.get() callback not executing

ROSLIB.Param.get() callback not executing Hey all, Not sure if something is broken, or if I am doing something wrong.

2018-07-16 11:21:16 -0500 asked a question ROSLIB.Param.get() callback not executing

ROSLIB.Param.get() callback not executing Hey all, Not sure if something is broken, or if I am doing something wrong.