- 
                Notifications
    
You must be signed in to change notification settings  - Fork 392
 
User_App_Fibonacci_Action_Client
- Requirements
 - Launch the Action Server on ROS
 - Configure Action Client on Unity3D
 - The Code Explained
 
This tutorial assumes that you have completed:
- 1. Installation and Configuration of ROS#
 - Writing a Simple Action Server using the Execute Callback
 - How to add new Message Types
 
- 
Note: This section assumes that you have ROS installed on a machine accessible from Unity machine and have
rosbridge_serverinstalled in ROS. See our wiki page for installation guide - 
In order to get Unity to talk to ROS, fire up
RosBridge WebSocketby running the following in terminal 
$ roslaunch rosbridge_server rosbridge_websocket.launch- Then get Fibonacci action server from ROS tutorial "Writing a Simple Action Server using the Execute Callback" running by executing the following in a separate terminal window:
 
$ rosrun actionlib_tutorials fibonacci_server- 
Create a new empty
GameObject, name it as 'RosConnector'. This is where we will attach ourRosConnectorandUnityFibonacciActionClientcomponents. - 
Action Nameis the name of the action, set it to "fibonacci". Usually published and subscribed topics are named as 'action_name/goal', 'action_name/feedback', etc. - 
Fibonacci Orderis the order of Fibonacci series defined as the goal for this particular action. Users set the goal, and clicks onSend Goalto activate the action server. Users can preempt the activated server by clicking onCancel Goal. - 
Status,Feedback, andResultare the fields to inform users about the current state of action server, and updated via callback functions of subscribed topics to the action server. - 
Simply run the Unity3D application, and click on "Send Goal".
 
- 
ActionClient.csis an abstract class which can be implemented by providing the message types of the defined ROS action. Please see the example implementationFibonacciActionClient.csto observe the message types used for Fibonacci action example. 
public abstract class ActionClient<TAction, TActionGoal, TActionResult, TActionFeedback, TGoal, TResult, TFeedback>
        where TAction : Action<TActionGoal, TActionResult, TActionFeedback, TGoal, TResult, TFeedback>
        where TActionGoal : ActionGoal<TGoal>
        where TActionResult : ActionResult<TResult>
        where TActionFeedback : ActionFeedback<TFeedback>
        where TGoal : Message
        where TResult : Message
        where TFeedback : Message- 
ActionClienthas generic callback functions for subscriptions to 'action_name/status', 'action_name/feedback', and 'action_name/result', in which application-specific handling functions are called. - 
In order to implement
ActionClient, users only have to implement the handling functions, for example, OnResultReceived() function to process the result received from the action server. 
// Implement by user to handle result.
protected abstract void OnResultReceived();
private void ResultCallback(TActionResult actionResult)
{
    action.action_result = actionResult;
    OnResultReceived();
}- 
FibonacciActionClientobject can be instantiated either on Unity3D or in a console application. - 
For the use of action client implementation on Unity3D, please see
UnityFibonacciActionClient.csand the corresponding inspector editor script. 
public class UnityFibonacciActionClient : MonoBehaviour
{
    private RosConnector rosConnector;
    public FibonacciActionClient fibonacciActionClient;
    public string actionName;
    public int fibonacciOrder = 20;
    public string status = "";
    public string feedback = "";
    public string result = "";
    private void Start()
    {
        rosConnector = GetComponent<RosConnector>();
        fibonacciActionClient = new FibonacciActionClient(actionName, rosConnector.RosSocket);
        fibonacciActionClient.Initialize();
    }- Note that this is a MonoBehaviour class. On Unity3D application start, 
FibonacciActionClientobject is instantiated with an action name and a RosSocket. 
private void Update()
{
    status   = fibonacciActionClient.GetStatusString();
    feedback = fibonacciActionClient.GetFeedbackString();
    result   = fibonacciActionClient.GetResultString();
}- On every Unity3D update step, we just call the getter functions of 
FibonacciActionClientobject to update the fields on the inspector. 
public void RegisterGoal()
{
    fibonacciActionClient.fibonacciOrder = fibonacciOrder;
}- 
RegisterGoal() binds the Fibonacci order from the Unity3D inspector to the
FibonacciActionClientobject. - 
For the use of action client implementation in a console application, please see
FibonacciActionClientConsoleExample.cs. 
Next tutorial: Fibonacci Action Server
© Siemens AG, 2017-2024
- 
- 1.3.1 R2D2 Setup
 - 1.3.2 Gazebo Setup on VM
 - 1.3.3 TurtleBot Setup (Optional for ROS2)
 
 
- 2.1 Quick Start
 - 2.2 Transfer a URDF from ROS to Unity
 - 2.3 Transfer a URDF from Unity to ROS
 - 2.4 Unity Simulation Scene Example
 - 2.5 Gazebo Simulation Scene Example
 - 2.6 Fibonacci Action Client
 - 2.7 Fibonacci Action Server
 
- 3.1 Import a URDF on Windows
 - 3.2 Create, Modify and Export a URDF Model
 - 3.3 Animate a Robot Model in Unity
 
- 4.1 Introduction to RosBridgeClient
 - 4.2 Image Publication
 - 4.3 URDF Transfer
 - 4.4 Fibonacci Action Client/Server
 
- Message Handling: Readers & Writers
 - Thread Safety for Message Reception
 - File Server Package
 - ROS-Unity Coordinate System Conversions
 - Post Build Events
 - Preprocessor Directives in ROS#
 - Adding New Message Types
 - RosBridgeClient Protocols
 - RosBridgeClient Serializers
 - Actions in ROS#
 - Action Server State Machine Model
 
© Siemens AG, 2017-2025