59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
import rclpy
|
|
from rclpy.action import ActionClient
|
|
from rclpy.node import Node
|
|
import time
|
|
|
|
|
|
from pubsub.pubsub_library_v4 import MinimalActionClient
|
|
|
|
from custom_interfaces.action import TestACT
|
|
|
|
|
|
class Client(MinimalActionClient):
|
|
|
|
def goalrequest(self):
|
|
# Create a goal request and send it
|
|
goal_msg = TestACT.Goal()
|
|
goal_msg.number = 7
|
|
Tester.send_action_goal(goal_msg)
|
|
|
|
# for only one variable:
|
|
# goal_msg = 7
|
|
# Tester.send_action_goal(goal_msg)
|
|
# is also valid
|
|
|
|
# Start a 5 second timer to initiate cancel request (demonstarate cancel)
|
|
self._timer = self.create_timer(5.0, self.cancel_goal)
|
|
|
|
|
|
def get_result_callback(self, future):
|
|
# get result
|
|
result = future.result().result
|
|
self.get_logger().info(f'Result: {result.success}')
|
|
|
|
|
|
def feedback_callback(self, feedback_msg):
|
|
# get feedback
|
|
feedback = feedback_msg.feedback
|
|
#print(feedback.current_number)
|
|
self.get_logger().info(f'Received feedback: {feedback.current_number}')
|
|
|
|
def spin_once(self):
|
|
rclpy.spin_once(self, timeout_sec=0.01)
|
|
|
|
|
|
def main(args=None):
|
|
rclpy.init(args=args)
|
|
global Tester
|
|
|
|
Tester = Client(NODE_NAME="action_client", ACT_NAME="ActionTest", ACT_TYPE=TestACT)
|
|
Tester.goalrequest()
|
|
|
|
|
|
while rclpy.ok():
|
|
Tester.spin_once()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|