import sys from guizero import App, Text, PushButton from example_interfaces.srv import AddTwoInts import rclpy from rclpy.node import Node row = 1 state = 3
class MinimalClientAsync(Node):
def __init__(self): super().__init__('minimal_client_async') self.cli = self.create_client(AddTwoInts, 'add_two_ints') while not self.cli.wait_for_service(timeout_sec=1.0): self.get_logger().info('service not available, waiting again...') self.req = AddTwoInts.Request() def send_request(self): self.req.a = row #int(sys.argv[1]) self.req.b = state #int(sys.argv[2]) self.future = self.cli.call_async(self.req)
def main(r=0, s = 0):
row = r state = s app = App(title="lights", layout= "grid", height=400, width=800) #message = Text(app, text="Welcome to the Hello world app!",grid=) button = PushButton(app, text="on", command=main_def,args=(1,1), grid=[0,1]) button = PushButton(app, text="off", command=main_def,args=(1,0), grid=[1,1]) app.display()
def row_one_on(): row=1 global state state=1 main_def() def row_one_off(): row=1 global state state=0 main_def()
def main_def(r=0,s=0): rclpy.init() #print(args) global row , state row=r state=s minimal_client = MinimalClientAsync() minimal_client.send_request()
while rclpy.ok(): rclpy.spin_once(minimal_client) if minimal_client.future.done(): try: response = minimal_client.future.result() except Exception as e: minimal_client.get_logger().info( 'Service call failed %r' % (e,)) else: minimal_client.get_logger().info( 'Result of add_two_ints: for %d + %d = %d' % (minimal_client.req.a, minimal_client.req.b, response.sum)) break minimal_client.destroy_node() rclpy.shutdown()
if name == 'main': main()
Log in to post a comment.
import sys
from guizero import App, Text, PushButton
from example_interfaces.srv import AddTwoInts
import rclpy
from rclpy.node import Node
row = 1
state = 3
class MinimalClientAsync(Node):
def main(r=0, s = 0):
def row_one_on():
row=1
global state
state=1
main_def()
def row_one_off():
row=1
global state
state=0
main_def()
def main_def(r=0,s=0):
rclpy.init()
#print(args)
global row , state
row=r
state=s
minimal_client = MinimalClientAsync()
minimal_client.send_request()
if name == 'main':
main()