88 isRosbridgeActionFeedbackMessage ,
99 isRosbridgeActionResultMessage ,
1010 isRosbridgeCancelActionGoalMessage ,
11+ isRosbridgeSendActionGoalMessage ,
12+ RosbridgeSendActionGoalMessage ,
1113} from "../types/protocol.ts" ;
1214import Ros from "./Ros.js" ;
1315
@@ -65,8 +67,7 @@ export default class Action<
6567 return ;
6668 }
6769
68- const actionGoalId =
69- "send_action_goal:" + this . name + ":" + ++ this . ros . idCounter ;
70+ const actionGoalId = `send_action_goal:${ this . name } :${ ( ++ this . ros . idCounter ) . toString ( ) } ` ;
7071
7172 this . ros . on ( actionGoalId , function ( message ) {
7273 if ( isRosbridgeActionResultMessage < TResult > ( message ) ) {
@@ -124,7 +125,15 @@ export default class Action<
124125
125126 this . #actionCallback = actionCallback ;
126127 this . #cancelCallback = cancelCallback ;
127- this . ros . on ( this . name , this . #executeAction. bind ( this ) ) ;
128+ this . ros . on ( this . name , ( msg ) => {
129+ if ( isRosbridgeSendActionGoalMessage ( msg ) ) {
130+ this . #executeAction. bind ( this ) ;
131+ } else {
132+ throw new Error (
133+ "Received unrelated message on Action server event stream!" ,
134+ ) ;
135+ }
136+ } ) ;
128137 this . ros . callOnConnection ( {
129138 op : "advertise_action" ,
130139 type : this . actionType ,
@@ -156,7 +165,7 @@ export default class Action<
156165 * @param rosbridgeRequest.id - The ID of the action goal.
157166 * @param rosbridgeRequest.args - The arguments of the action goal.
158167 */
159- #executeAction( rosbridgeRequest : { id : string ; args : TGoal } ) {
168+ #executeAction( rosbridgeRequest : RosbridgeSendActionGoalMessage < TGoal > ) {
160169 const id = rosbridgeRequest . id ;
161170
162171 // If a cancellation callback exists, call it when a cancellation event is emitted.
@@ -173,7 +182,13 @@ export default class Action<
173182
174183 // Call the action goal execution function provided.
175184 if ( this . #actionCallback) {
176- this . #actionCallback( rosbridgeRequest . args , id ) ;
185+ if ( rosbridgeRequest . args ) {
186+ this . #actionCallback( rosbridgeRequest . args , id ) ;
187+ } else {
188+ throw new Error (
189+ "Received Action goal with no arguments! This should never happen, because rosbridge should fill in blanks!" ,
190+ ) ;
191+ }
177192 }
178193 }
179194
0 commit comments