Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

312
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda