@@ -89,20 +89,38 @@ type inputEnabledActuator interface {
89
89
// Config describes how to configure the service; currently only used for specifying dependency on framesystem service.
90
90
type Config struct {
91
91
LogFilePath string `json:"log_file_path"`
92
+ NumThreads int `json:"num_threads"`
92
93
}
93
94
94
95
// Validate here adds a dependency on the internal framesystem service.
95
96
func (c * Config ) Validate (path string ) ([]string , []string , error ) {
97
+ if c .NumThreads < 0 {
98
+ return nil , nil , fmt .Errorf ("cannot configure with %d number of threads, number must be positive" , c .NumThreads )
99
+ }
96
100
return []string {framesystem .InternalServiceName .String ()}, nil , nil
97
101
}
98
102
103
+ type builtIn struct {
104
+ resource.Named
105
+ mu sync.RWMutex
106
+ fsService framesystem.Service
107
+ movementSensors map [resource.Name ]movementsensor.MovementSensor
108
+ slamServices map [resource.Name ]slam.Service
109
+ visionServices map [resource.Name ]vision.Service
110
+ components map [resource.Name ]resource.Resource
111
+ logger logging.Logger
112
+ state * state.State
113
+ configuredDefaultExtras map [string ]any
114
+ }
115
+
99
116
// NewBuiltIn returns a new move and grab service for the given robot.
100
117
func NewBuiltIn (
101
118
ctx context.Context , deps resource.Dependencies , conf resource.Config , logger logging.Logger ,
102
119
) (motion.Service , error ) {
103
120
ms := & builtIn {
104
- Named : conf .ResourceName ().AsNamed (),
105
- logger : logger ,
121
+ Named : conf .ResourceName ().AsNamed (),
122
+ logger : logger ,
123
+ configuredDefaultExtras : make (map [string ]any ),
106
124
}
107
125
108
126
if err := ms .Reconfigure (ctx , deps , conf ); err != nil {
@@ -128,6 +146,10 @@ func (ms *builtIn) Reconfigure(
128
146
fileAppender , _ := logging .NewFileAppender (config .LogFilePath )
129
147
ms .logger .AddAppender (fileAppender )
130
148
}
149
+ if config .NumThreads > 0 {
150
+ ms .configuredDefaultExtras ["num_threads" ] = config .NumThreads
151
+ }
152
+
131
153
movementSensors := make (map [resource.Name ]movementsensor.MovementSensor )
132
154
slamServices := make (map [resource.Name ]slam.Service )
133
155
visionServices := make (map [resource.Name ]vision.Service )
@@ -162,18 +184,6 @@ func (ms *builtIn) Reconfigure(
162
184
return nil
163
185
}
164
186
165
- type builtIn struct {
166
- resource.Named
167
- mu sync.RWMutex
168
- fsService framesystem.Service
169
- movementSensors map [resource.Name ]movementsensor.MovementSensor
170
- slamServices map [resource.Name ]slam.Service
171
- visionServices map [resource.Name ]vision.Service
172
- components map [resource.Name ]resource.Resource
173
- logger logging.Logger
174
- state * state.State
175
- }
176
-
177
187
func (ms * builtIn ) Close (ctx context.Context ) error {
178
188
ms .mu .Lock ()
179
189
defer ms .mu .Unlock ()
@@ -188,6 +198,7 @@ func (ms *builtIn) Move(ctx context.Context, req motion.MoveReq) (bool, error) {
188
198
defer ms .mu .RUnlock ()
189
199
operation .CancelOtherWithLabel (ctx , builtinOpLabel )
190
200
201
+ ms .applyDefaultExtras (req .Extra )
191
202
plan , err := ms .plan (ctx , req , ms .logger )
192
203
if err != nil {
193
204
return false , err
@@ -207,6 +218,7 @@ func (ms *builtIn) MoveOnMap(ctx context.Context, req motion.MoveOnMapReq) (moti
207
218
// TODO: Deprecated: remove once no motion apis use the opid system
208
219
operation .CancelOtherWithLabel (ctx , builtinOpLabel )
209
220
221
+ ms .applyDefaultExtras (req .Extra )
210
222
id , err := state .StartExecution (ctx , ms .state , req .ComponentName , req , ms .newMoveOnMapRequest )
211
223
if err != nil {
212
224
return uuid .Nil , err
@@ -275,6 +287,7 @@ func (ms *builtIn) MoveOnGlobe(ctx context.Context, req motion.MoveOnGlobeReq) (
275
287
// TODO: Deprecated: remove once no motion apis use the opid system
276
288
operation .CancelOtherWithLabel (ctx , builtinOpLabel )
277
289
290
+ ms .applyDefaultExtras (req .Extra )
278
291
id , err := state .StartExecution (ctx , ms .state , req .ComponentName , req , ms .newMoveOnGlobeRequest )
279
292
if err != nil {
280
293
return uuid .Nil , err
@@ -578,6 +591,19 @@ func (ms *builtIn) execute(ctx context.Context, trajectory motionplan.Trajectory
578
591
return nil
579
592
}
580
593
594
+ // applyDefaultExtras iterates through the list of default extras configured on the builtIn motion service and adds them to the
595
+ // given map of extras if the key does not already exist.
596
+ func (ms * builtIn ) applyDefaultExtras (extras map [string ]any ) {
597
+ if extras == nil {
598
+ extras = make (map [string ]any )
599
+ }
600
+ for key , val := range ms .configuredDefaultExtras {
601
+ if _ , ok := extras [key ]; ! ok {
602
+ extras [key ] = val
603
+ }
604
+ }
605
+ }
606
+
581
607
func waypointsFromRequest (
582
608
req motion.MoveReq ,
583
609
fsInputs referenceframe.FrameSystemInputs ,
0 commit comments