All Projects → FunPythonEC → uPy-rosserial

FunPythonEC / uPy-rosserial

Licence: MIT license
An implementation of rosserial for uPy.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to uPy-rosserial

SerialTransfer
Arduino library to transfer dynamic, packetized data fast and reliably via Serial, I2C, or SPI
Stars: ✭ 273 (+1336.84%)
Mutual labels:  serial, uart
Quad-Serial
Quad serial project with FTDI CI's, Isolation and 1.8~5.5v UART port.
Stars: ✭ 17 (-10.53%)
Mutual labels:  serial, uart
stm8s-sdcc-examples
Example codes using sdcc to target STM8S MCUs.
Stars: ✭ 31 (+63.16%)
Mutual labels:  serial, uart
pySerialTransfer
Python package to transfer data in a fast, reliable, and packetized form
Stars: ✭ 78 (+310.53%)
Mutual labels:  serial, uart
SwiftyXBee
⚡️ A Swift library for communicating with XBee radios in API mode
Stars: ✭ 22 (+15.79%)
Mutual labels:  uart
LibSerialPort.jl
Julia wrapper for the libserialport c library
Stars: ✭ 54 (+184.21%)
Mutual labels:  serial
Saxi
Tools & library for driving the AxiDraw pen plotter
Stars: ✭ 234 (+1131.58%)
Mutual labels:  serial
Ohsce
PHP HI-REL SOCKET TCP/UDP/ICMP/Serial .高可靠性PHP通信&控制框架SOCKET-TCP/UDP/ICMP/硬件Serial-RS232/RS422/RS485 AND MORE!
Stars: ✭ 206 (+984.21%)
Mutual labels:  serial
EspBuddy
Wrapper to easily upload (OTA or Serial), backup, batch query, monitor ESP8266 boards using Esptool.py, Espota.py and Platformio
Stars: ✭ 47 (+147.37%)
Mutual labels:  serial
libcssl
Columbo Simple Serial Library is an easy to use, event driven serial port communication library for Linux.
Stars: ✭ 38 (+100%)
Mutual labels:  uart
rpi boat utils
Utilities for Raspberry Pi, mostly for usage on a boat. Includes UART control scripts, traffic measurement tools for Mikrotik (RouterOS) and OpenWrt, AIS wireless daemon, AIS decoder and an extensible boat & IoT sensor daemon for Signal K.
Stars: ✭ 71 (+273.68%)
Mutual labels:  uart
bluetooth-terminal
ES6 class for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 43 (+126.32%)
Mutual labels:  serial
convey
Communication through a serial port or named pipe
Stars: ✭ 46 (+142.11%)
Mutual labels:  serial
Nodemcu Tool
🔧 Upload + Manage Lua files on NodeMCU
Stars: ✭ 248 (+1205.26%)
Mutual labels:  serial
annotate
Create 3D labelled bounding boxes in RViz
Stars: ✭ 104 (+447.37%)
Mutual labels:  ros-melodic
Adalight Fastled
Adalight with FastLED support
Stars: ✭ 232 (+1121.05%)
Mutual labels:  serial
Huhnitor
Intergalactic serial monitor for ESP8266 Deauther
Stars: ✭ 265 (+1294.74%)
Mutual labels:  serial
arduivis
a bi-directional communication paradigm for programming languages & microcontrollers
Stars: ✭ 48 (+152.63%)
Mutual labels:  serial
1ZLAB PyEspCar
1ZLab在准备挑选合适的小车来研发计算机视觉的教程时候 , 发现习惯了Python语法的我们, 在市面上找不到合适小车, 后来我们选了ESP32作为小车的控制主板, 可以使用Python对其进行交互式编程, 极大的提升了开发效率.
Stars: ✭ 78 (+310.53%)
Mutual labels:  micropython-esp32
neato-serial
Python serial interface for Neato robot vacuum cleaners. Testing on XV Signature Pro, should work on others.
Stars: ✭ 39 (+105.26%)
Mutual labels:  serial

uPy-rosserial

rosserial is a method used by ROS in order to establish communication via serial, basically a middleware, mostly used with microcontrollers, which in this case are the ones responsible in some ROS applications for actuators and sensors usage.

This library targets the communication between ROS and uPy with rosserial as middleware.

Note: All of this library was coded using an ESP32, can't guarantee to work with other boards.

Features

  • Advertising Topics
  • Publishing
  • Subscribing
  • Services

To Do: Implement services usage.

Installation

Before using this library you must have ROS installed, as well as rosserial which would be with the following command:

sudo apt install ros-<version>-rosserial ros-<version>-rosserial-arduino

In theory every board with the kind of generic UART class for ESP32 is capable of using this library, but it must be known exactly which UART ID is being used, this means for example, for ESP32 defined pins correspond to TX0 and RX0 for UART0, and so on. In the examples below, UART2 is used.

Copying source files

In order to use ros node communication, have in mind a python class for each message must be available. this means a dependency of this library is uPy Genpy and uPy rosserial_msgs, ugenpy used to create Python classes for messages from *.msg files while rosserial_msgs has the TopicInfo class for topic negotiation. The folders from src from this current repo and the other two must be copied

I strongly recommend using rshell.

Using upip

Now available with upip, could be installed with:

import upip
upip.install('micropython-rosserial')

If micropython-rosserial is installed, because of requirementes, ugenpy and TopicInfo will too.

Note: must be connected to WiFi to use upip like this.

Have in mind before publishing or subscribing to a topic, the message class must be generated with ugenpy

Usage

Everytime before establishing rosserial communication, this command must be run, even before running the script in uPy, will be improved afterwards:

rosrun rosserial_arduino serial_node.py _port:=/dev/ttyUSB0 _baud:=115200

Note port and baudrate can be changed, in ESP32 I prefer using 115200 for baudrate.

Publish example

Suppose ColorRGBA.py has been created using ugenpy and ColorRGBA.msg file:

float32 r
float32 g
float32 b
float32 a

And then running the following e.g.:

import uros
from std_msgs import ColorRGBA #message object ColorRGBA
from time import sleep
node=uros.NodeHandle(2,115200) #node initialized, for tx2/rx2 and 115200 baudrate
msg=ColorRGBA() #msg object init
msg.r=1 #values to variables assigned
msg.g=3
msg.b=4
msg.a=1
while True:
    node.publish('Colorsh',msg) #publish data to node Colorsh
    sleep(1)

Subscribe example

import uros
from std_msgs import String

def cb(msg):
	print(msg.data)
	
node = uros.NodeHandle(2, 115200)
node.subscribe('chatter', String, cb)

Mixed example

import uros
from std_msgs import String

def cb(msg):
	print(msg.data)
	
packet=String()
packet.data='hola fpy'
node = uros.NodeHandle(2, 115200)
node.subscribe('chatter', String, cb)
while True:
	node.publish('greet', packet)

Classes

uros.NodeHandle

Constructor

uros.NodeHandle(serial_id = 2, baudrate = 115200, **kwargs)

Initiates the class which handles the node, advertised topics, publishes and subscribe.

  • serial_id: corresponds to the UART ID, in case of ESP32, it has 3 UARTS, in the examples UART2 is used.
  • baudrate: is the baudrate in which the board will communicate.
  • **kwargs: used in order to be able to define the serial communication with uart in different ways, in case a custom UART object is wanted to be used, it should be defined as uros.NodeHandle(serial = uart_object) or in case certain tx and rx pins are wanted for the uart with certain ID, it should be like node = uros.NodeHandle(2, 115200, tx=16, rx= 16).

Methods

uros.NodeHandle.publish(topic_name, msg, buffer_size=1024)

Publishes data to a defined topic, with a defined message class.

  • topic_name: the topic where the message will be put or published.
  • msg: the msg class initiated with its slots values defined.
  • buffer_size: the amount of bytes that will be published as a maximum from this particular topic, 1024 is by default.
uros.NodeHandle.subscribe(topic_name, msgobj, cb, buffer_size=1024)

Subscribe to a defined topic.

  • topic_name: same as publish.
  • msgobj: is the object class, but not instantiated, just the class passed.
  • cb: must be defined, it is a callback function, with a single argument that corresponds to the inconming message class.
  • buffer_size: same as publish.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].