Skip to content

Commit

Permalink
implemented callback in loop with timer
Browse files Browse the repository at this point in the history
  • Loading branch information
TiaSinghania committed Oct 23, 2024
1 parent 1043ab8 commit 858196f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
49 changes: 49 additions & 0 deletions rb_ws/src/buggy/buggy/simulator/engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#! /usr/bin/env python3
import sys
import time
import rclpy
from rclpy.node import Node

from std_msgs.msg import String, Float64

class Simulator(Node):
# simulator constants:

def __init__(self):
super().__init__('SC_sim_single')
self.get_logger().info("INITIALIZING")
self.number_publisher = self.create_publisher(Float64, 'numbers', 1)
self.test_publisher = self.create_publisher(String, 'test', 1)
self.i = 0

self.buggy_name = "NONE"

if (self.get_namespace() == "/SC"):
self.buggy_name = "SC"

if (self.get_namespace() == "/NAND"):
self.buggy_name = "NAND"

freq = 10
timer_period = 1/freq # seconds
self.timer = self.create_timer(timer_period, self.loop)

def loop(self):

self.get_logger().info("LOOPING")

msg = String()
msg.data = self.buggy_name
self.test_publisher.publish(msg)
msg2 = Float64()
msg2.data = float(self.i)
self.number_publisher.publish(msg2)
self.i += 1

def main(args=None):
rclpy.init(args=args)
sim = Simulator()
sim.get_logger().info("CREATED NODE")
rclpy.spin(sim)


10 changes: 5 additions & 5 deletions rb_ws/src/buggy/launch/sim_2d_single.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<launch>
<node pkg="foxglove_bridge" exec="foxglove_bridge" name="foxglove" namespace="SC"/>
<node pkg="buggy" exec="hello_world" name="hello_world" namespace="SC"/>
<node pkg="buggy" exec="sim-single" name="SC-sim-single" namespace="SC"/>
<node pkg="buggy" exec="sim-single" name="NAND-sim-single" namespace="NAND"/>
<node pkg="buggy" exec="hello_world" name="hello_world" namespace="SC" />
<node pkg="buggy" exec="sim_single" name="SC_sim_single" namespace="SC"/>
<node pkg="buggy" exec="sim_single" name="NAND_sim_single" namespace="NAND"/>

<!-- <node name="foxglove" pkg="foxglove_bridge" type="foxglove_bridge" /> -->
<!-- <node name="hello_world" pkg="buggy" type="hello_world" /> -->
<!-- <node name="foxglove" pkg="foxglove_bridge" type="foxglove_bridge" />
<node name="hello_world" pkg="buggy" type="hello_world" /> -->
</launch>
32 changes: 0 additions & 32 deletions rb_ws/src/buggy/scripts/simulator/engine.py

This file was deleted.

7 changes: 3 additions & 4 deletions rb_ws/src/buggy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join("share", package_name), glob("launch/*.xml")),
(os.path.join("share", package_name), glob("launch/*.xml"))
],
install_requires=['setuptools'],
zip_safe=True,
Expand All @@ -24,9 +24,8 @@
tests_require=['pytest'],
entry_points={
'console_scripts': [
'hello_world = buggy.hello_world:main'
'sim-single = buggy.engine:main'

'hello_world = buggy.hello_world:main',
'sim_single = buggy.simulator.engine:main'
],
},
)

0 comments on commit 858196f

Please sign in to comment.