Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

309
Vistas
ros2 pub/sub custom message through ros2-web-bridge to client app

I want to publish ros2 custom message through ros2-web-bridge to react app. In react i have subscribed to published custom message. ros2-web-bridge is running on port ws://localhost:9090. I have created the custom message interface on ros2.

   // this is client side web app subscribe method
   var example = new ROSLIB.Topic({
  ros: ros,
  name: "/sample",
  messageType: `tutorial_interfaces/msg/Num`,
});

// Subscribe a Topic
example.subscribe(function (message) {
  console.log("Subscribe data", message);
});


// This is ros2 publish python code
import rclpy
from rclpy.node import Node
from tutorial_interfaces.msg import Num    # CHANGE
class MinimalPublisher(Node):

def __init__(self):
    super().__init__('minimal_publisher')
    self.publisher_ = self.create_publisher(Num, 'sample', 10)     # CHANGE
    timer_period = 0.5
    self.timer = self.create_timer(timer_period, self.timer_callback)
    self.i = 0

// This is ros2 published class and method
def timer_callback(self):
    msg = Num()                                           # CHANGE
    msg.num = self.i                                      # CHANGE
    self.publisher_.publish(msg)
    self.get_logger().info('Publishing: "%d"' % msg.num)  # CHANGE
    self.i += 1
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you already have a custom message created and subscribed to on the React side all you have to do here is include the message header and it'll work just like a std_msg. Ex: if you have package custom_interface that includes a custom message type my_msg your code would look something like this:

// This is ros2 publish python code
import rclpy
from rclpy.node import Node
from custom_interface.msg import my_msg
class MinimalPublisher(Node):

def __init__(self):
    super().__init__('minimal_publisher')
    self.publisher_ = self.create_publisher(my_msg, 'sample', 10)
    timer_period = 0.5
    self.timer = self.create_timer(timer_period, self.timer_callback)
    self.i = 0

// This is ros2 published class and method
def timer_callback(self):
    msg = my_msg()
    my_msg.custom_field = self.i
    self.publisher_.publish(my_msg)
    self.get_logger().info('Publishing: "%d"' % my_msg.custom_field)
    self.i += 1

If the web-bridge is already setup like you say, that will all work.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda