Thanks to visit codestin.com
Credit goes to github.com

Skip to content

k-macmillan/ROSwrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ROSwrapper

ROSwrapper is a wrapper for ROS2's rclpy. ROSwrapper uses object oriented programming to turn nodes into clean, self-contained objects that can be added or removed from the NodeControl class. Nodes are spun and stopped through use of a controller, as defined in the NodeControl class.

rclpy

To create a publish node with a timer in rclpy:

def timer_callback():
    msg.data = 'Hello World'
    publisher.publish(msg)


rclpy.init()
node = rclpy.create_node('publisher')
publisher = node.create_publisher(String, 'topic')

msg = String()
timer_period = 0.5  # seconds
timer = node.create_timer(timer_period, timer_callback)

rclpy.spin(node)

node.destroy_timer(timer)
node.destroy_node()
rclpy.shutdown()

You can spin up a publisher in 13 lines of code using just rclpy. Additional publishers/subscribers are several lines each.

ROSwrapper

To publish the same thing with ROSwrapper:

nc = NodeControl()
nc.addnode(RosNode(name='publisher',
                   pub_data_type=String,
                   pub_chan='topic',
                   pub_rate=2,  # in Hz
                   pub_data='Hello World'))
nc.run()

You can spin up a publisher in 3 lines of code using ROSwrapper. Additional publishers/subscribers are 1 line of code each. Nodes are added to the NodeControl so everything can be cleanly executed and cleaned up.

A RosNode

The core nodes are defined in the base class RosNode. RosNode was intended to be derived in the event the user wishes to see specific behavior.

If a user has multiple subscribers you can use a switch statement to interpret the message.

For more advanced usage you coud derive multiple classes from RosNode to handle each case. For example a robot may have IR sensors and wheels, each of which could have a custom class to deal with the information.

Looking Forward

This still has quite a bit of work to be done before it's ready.

Why this exists

I was tasked with coding a robot to navigate a course while utilizing ROS2. I prefer object-oriented programming with working with something such as nodes so I built this to wrap rclpy into a more user-friendly product.

About

OOP wrapper for ROS2's rclpy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages