Bird
Raised Fist0
ROSframework~10 mins

Action definition (.action files) in ROS - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Action definition (.action files)
Define Goal Fields
↓
Define Result Fields
↓
Define Feedback Fields
↓
Save as .action file
↓
ROS builds action messages
↓
Use in Action Server and Client
The flow shows how you define goal, result, and feedback in a .action file, then ROS generates code to use in action servers and clients.
Execution Sample
ROS
int32 order
---
int64 factorial
---
float32 progress
This .action file defines a goal with an integer order, a result with the factorial value, and feedback with progress percentage.
Execution Table
StepSectionFields DefinedPurpose
1Goalint32 orderInput to action server: number to compute factorial of
2Resultint64 factorialOutput from action server: factorial result
3Feedbackfloat32 progressIntermediate progress updates during computation
4Save File.action file savedFile ready for ROS build system
5ROS BuildGenerate message codeROS creates code for client/server communication
6UseAction Server and ClientImplement logic and communicate using generated messages
7ExitProcess completeAction definition ready for use
💡 All three sections defined and file saved; ROS build generates code for use
Variable Tracker
VariableStartAfter GoalAfter ResultAfter FeedbackFinal
Goal FieldsNoneint32 orderint32 orderint32 orderint32 order
Result FieldsNoneNoneint64 factorialint64 factorialint64 factorial
Feedback FieldsNoneNoneNonefloat32 progressfloat32 progress
Key Moments - 3 Insights
Why are there three sections separated by '---' in a .action file?
Each section defines a different message type: Goal (input), Result (output), and Feedback (updates). This separation is required for ROS to generate correct communication messages, as shown in execution_table steps 1-3.
Can I define multiple fields in each section?
Yes, you can define as many fields as needed in each section. The example shows one field per section for simplicity, but ROS supports multiple fields to carry complex data.
What happens after saving the .action file?
After saving, ROS build system generates code for action clients and servers to use these messages, as shown in execution_table step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is defined in the Feedback section at step 3?
Aint32 order
Bint64 factorial
Cfloat32 progress
DNo fields defined
💡 Hint
Check the 'Fields Defined' column at step 3 in the execution_table
At which step does ROS generate message code from the .action file?
AStep 2
BStep 5
CStep 4
DStep 6
💡 Hint
Look for 'Generate message code' in the 'Fields Defined' column in execution_table
If you add a new field to the Goal section, how does variable_tracker change after Goal?
AGoal Fields update to include the new field
BGoal Fields remain 'int32 order'
CResult Fields change
DFeedback Fields change
💡 Hint
Variable_tracker shows Goal Fields after step 1; adding fields updates this value
Concept Snapshot
Action Definition (.action files):
- Three sections separated by '---': Goal, Result, Feedback
- Define input fields in Goal
- Define output fields in Result
- Define progress fields in Feedback
- Save file and ROS generates communication code
- Used by action servers and clients for async tasks
Full Transcript
An action definition in ROS uses a .action file with three parts separated by '---'. The first part defines the Goal, which is the input data sent to the action server. The second part defines the Result, which is the output data returned when the action finishes. The third part defines Feedback, which is data sent periodically to show progress. After writing these sections, you save the file. Then, ROS build tools generate code to handle these messages. This code is used by action servers and clients to communicate asynchronously. The example shows a factorial calculation with an integer order as goal, the factorial result as output, and progress as feedback. Understanding these parts helps you create custom actions for your robots.

Practice

(1/5)
1. What is the main purpose of an .action file in ROS?
easy
A. To define goals, results, and feedback for long-running tasks
B. To list all the nodes in a ROS system
C. To configure robot sensors
D. To specify message types for topics

Solution

  1. Step 1: Understand the role of .action files

    .action files are designed to define the structure of actions, which include goals, feedback, and results for tasks that take time.
  2. Step 2: Compare with other ROS files

    Unlike message or service files, .action files specifically handle long-running tasks with progress updates.
  3. Final Answer:

    To define goals, results, and feedback for long-running tasks -> Option A
  4. Quick Check:

    Action files = goals + feedback + results [OK]
Hint: Remember: .action files split into goal, result, feedback [OK]
Common Mistakes:
  • Confusing .action files with .msg or .srv files
  • Thinking .action files configure hardware
  • Assuming .action files list nodes
2. Which of the following is the correct structure of a ROS .action file?
easy
A. goal fields --- feedback fields --- result fields
B. goal fields --- result fields --- feedback fields
C. result fields --- feedback fields --- goal fields
D. feedback fields --- goal fields --- result fields

Solution

  1. Step 1: Recall the .action file format

    The .action file has three parts separated by lines with three dashes (---): first goal, then result, then feedback.
  2. Step 2: Match the order

    The correct order is goal fields first, result fields second, and feedback fields last.
  3. Final Answer:

    goal fields --- result fields --- feedback fields -> Option B
  4. Quick Check:

    Order = goal, result, feedback [OK]
Hint: Remember order: Goal first, Result second, Feedback last [OK]
Common Mistakes:
  • Mixing up the order of feedback and result
  • Using only two sections instead of three
  • Forgetting the --- separators
3. Given this .action file snippet:
int32 goal_value
---
int32 result_value
---
float32 progress

What is the type of the feedback field?
medium
A. int32
B. bool
C. string
D. float32

Solution

  1. Step 1: Identify the feedback section

    The .action file is split by --- lines. The third section after the second --- is the feedback part.
  2. Step 2: Check the feedback field type

    The third section contains float32 progress, so the feedback field type is float32.
  3. Final Answer:

    float32 -> Option D
  4. Quick Check:

    Feedback type = float32 [OK]
Hint: Feedback is always after second --- line [OK]
Common Mistakes:
  • Confusing result and feedback sections
  • Choosing goal field type instead
  • Ignoring the --- separators
4. What is wrong with this .action file?
int32 goal_value
---
float32 feedback_value
---
int32 result_value
medium
A. Result section must come before feedback
B. The order of sections is correct; no error
C. Feedback section cannot have fields
D. Feedback section is in the wrong place

Solution

  1. Step 1: Check the order of sections

    The file has goal fields first, then feedback fields, then result fields, separated by --- lines.
  2. Step 2: Verify field types in each section

    Goal has int32, feedback has float32, result has int32. However, the correct order is goal, result, feedback.
  3. Final Answer:

    Result section must come before feedback -> Option A
  4. Quick Check:

    Correct order is goal, result, feedback [OK]
Hint: Check section order and field types carefully [OK]
Common Mistakes:
  • Thinking feedback must come last
  • Assuming feedback cannot have fields
  • Mixing up result and feedback order
5. You want to define an action for a robot to move to a position with feedback on distance left and a result indicating success. Which .action file snippet correctly defines this?
hard
A. float64 target_x float64 target_y --- bool success --- float64 distance_left
B. bool success --- float64 target_x float64 target_y --- float64 distance_left
C. float64 target_x float64 target_y --- float64 distance_left --- bool success
D. float64 distance_left --- float64 target_x float64 target_y --- bool success

Solution

  1. Step 1: Identify goal, feedback, and result roles

    The goal should specify the target position (target_x, target_y). Feedback should provide ongoing info (distance_left). Result should indicate success (bool success).
  2. Step 2: Match the correct order in the .action file

    The order is goal fields first, then feedback fields, then result fields. float64 target_x float64 target_y --- float64 distance_left --- bool success matches this order correctly.
  3. Final Answer:

    float64 target_x float64 target_y --- float64 distance_left --- bool success -> Option C
  4. Quick Check:

    Goal=target, Feedback=distance, Result=success [OK]
Hint: Goal first, feedback second, result last with correct fields [OK]
Common Mistakes:
  • Swapping feedback and result sections
  • Putting result fields in goal section
  • Mislabeling feedback as result
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard