@@ -100,6 +100,34 @@ void encode_pointer_to_integer(const void* ptr,fmi2Integer& hi,fmi2Integer& lo)
100
100
#endif
101
101
}
102
102
103
+ bool COSMPDummySensor::get_fmi_sensor_view_config (osi3::SensorViewConfiguration& data)
104
+ {
105
+ if (integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_SIZE_IDX] > 0 ) {
106
+ void * buffer = decode_integer_to_pointer (integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_BASEHI_IDX],integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_BASELO_IDX]);
107
+ normal_log (" OSMP" ," Got %08X %08X, reading from %p ..." ,integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_BASEHI_IDX],integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_BASELO_IDX],buffer);
108
+ data.ParseFromArray (buffer,integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_SIZE_IDX]);
109
+ return true ;
110
+ } else {
111
+ return false ;
112
+ }
113
+ }
114
+
115
+ void COSMPDummySensor::set_fmi_sensor_view_config_request (const osi3::SensorViewConfiguration& data)
116
+ {
117
+ data.SerializeToString (¤tConfigRequestBuffer);
118
+ encode_pointer_to_integer (currentConfigRequestBuffer.data (),integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_BASEHI_IDX],integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_BASELO_IDX]);
119
+ integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_SIZE_IDX]=(fmi2Integer)currentConfigRequestBuffer.length ();
120
+ normal_log (" OSMP" ," Providing %08X %08X, writing from %p ..." ,integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_BASEHI_IDX],integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_BASELO_IDX],currentConfigRequestBuffer.data ());
121
+ swap (currentConfigRequestBuffer,lastConfigRequestBuffer);
122
+ }
123
+
124
+ void COSMPDummySensor::reset_fmi_sensor_view_config_request ()
125
+ {
126
+ integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_SIZE_IDX]=0 ;
127
+ integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_BASEHI_IDX]=0 ;
128
+ integer_vars[FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_BASELO_IDX]=0 ;
129
+ }
130
+
103
131
bool COSMPDummySensor::get_fmi_sensor_view_in (osi3::SensorView& data)
104
132
{
105
133
if (integer_vars[FMI_INTEGER_SENSORVIEW_IN_SIZE_IDX] > 0 ) {
@@ -114,11 +142,11 @@ bool COSMPDummySensor::get_fmi_sensor_view_in(osi3::SensorView& data)
114
142
115
143
void COSMPDummySensor::set_fmi_sensor_data_out (const osi3::SensorData& data)
116
144
{
117
- data.SerializeToString (¤tBuffer );
118
- encode_pointer_to_integer (currentBuffer .data (),integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASEHI_IDX],integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASELO_IDX]);
119
- integer_vars[FMI_INTEGER_SENSORDATA_OUT_SIZE_IDX]=(fmi2Integer)currentBuffer .length ();
120
- normal_log (" OSMP" ," Providing %08X %08X, writing from %p ..." ,integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASEHI_IDX],integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASELO_IDX],currentBuffer .data ());
121
- swap (currentBuffer,lastBuffer );
145
+ data.SerializeToString (¤tOutputBuffer );
146
+ encode_pointer_to_integer (currentOutputBuffer .data (),integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASEHI_IDX],integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASELO_IDX]);
147
+ integer_vars[FMI_INTEGER_SENSORDATA_OUT_SIZE_IDX]=(fmi2Integer)currentOutputBuffer .length ();
148
+ normal_log (" OSMP" ," Providing %08X %08X, writing from %p ..." ,integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASEHI_IDX],integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASELO_IDX],currentOutputBuffer .data ());
149
+ swap (currentOutputBuffer,lastOutputBuffer );
122
150
}
123
151
124
152
void COSMPDummySensor::reset_fmi_sensor_data_out ()
@@ -128,6 +156,27 @@ void COSMPDummySensor::reset_fmi_sensor_data_out()
128
156
integer_vars[FMI_INTEGER_SENSORDATA_OUT_BASELO_IDX]=0 ;
129
157
}
130
158
159
+ void COSMPDummySensor::refresh_fmi_sensor_view_config_request ()
160
+ {
161
+ osi3::SensorViewConfiguration config;
162
+ if (get_fmi_sensor_view_config (config))
163
+ set_fmi_sensor_view_config_request (config);
164
+ else {
165
+ config.Clear ();
166
+ config.mutable_version ()->CopyFrom (osi3::InterfaceVersion::descriptor ()->file ()->options ().GetExtension (osi3::current_interface_version));
167
+ config.set_field_of_view_horizontal (3.14 );
168
+ config.set_field_of_view_vertical (3.14 );
169
+ config.set_range (fmi_nominal_range ()*1.1 );
170
+ config.mutable_update_cycle_time ()->set_seconds (0 );
171
+ config.mutable_update_cycle_time ()->set_nanos (20000000 );
172
+ config.mutable_update_cycle_offset ()->Clear ();
173
+ osi3::GenericSensorViewConfiguration* generic = config.add_generic_sensor_view_configuration ();
174
+ generic->set_field_of_view_horizontal (3.14 );
175
+ generic->set_field_of_view_vertical (3.14 );
176
+ set_fmi_sensor_view_config_request (config);
177
+ }
178
+ }
179
+
131
180
/*
132
181
* Actual Core Content
133
182
*/
@@ -152,23 +201,38 @@ fmi2Status COSMPDummySensor::doInit()
152
201
for (int i = 0 ; i<FMI_STRING_VARS; i++)
153
202
string_vars[i] = " " ;
154
203
204
+ set_fmi_nominal_range (135.0 );
155
205
return fmi2OK;
156
206
}
157
207
158
208
fmi2Status COSMPDummySensor::doStart (fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
159
209
{
160
210
DEBUGBREAK ();
161
- last_time = startTime;
211
+
162
212
return fmi2OK;
163
213
}
164
214
165
215
fmi2Status COSMPDummySensor::doEnterInitializationMode ()
166
216
{
217
+ DEBUGBREAK ();
218
+
167
219
return fmi2OK;
168
220
}
169
221
170
222
fmi2Status COSMPDummySensor::doExitInitializationMode ()
171
223
{
224
+ DEBUGBREAK ();
225
+
226
+ osi3::SensorViewConfiguration config;
227
+ if (!get_fmi_sensor_view_config (config))
228
+ normal_log (" OSI" ," Received no valid SensorViewConfiguration from Simulation Environment, assuming everything checks out." );
229
+ else {
230
+ normal_log (" OSI" ," Received SensorViewConfiguration for Sensor Id %llu" ,config.sensor_id ().value ());
231
+ normal_log (" OSI" ," SVC Ground Truth FoV Horizontal %f, FoV Vertical %f, Range %f" ,config.field_of_view_horizontal (),config.field_of_view_vertical (),config.range ());
232
+ normal_log (" OSI" ," SVC Mounting Position: (%f, %f, %f)" ,config.mounting_position ().position ().x (),config.mounting_position ().position ().y (),config.mounting_position ().position ().z ());
233
+ normal_log (" OSI" ," SVC Mounting Orientation: (%f, %f, %f)" ,config.mounting_position ().orientation ().roll (),config.mounting_position ().orientation ().pitch (),config.mounting_position ().orientation ().yaw ());
234
+ }
235
+
172
236
return fmi2OK;
173
237
}
174
238
@@ -194,19 +258,20 @@ void rotatePoint(double x, double y, double z,double yaw,double pitch,double rol
194
258
fmi2Status COSMPDummySensor::doCalc (fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPointfmi2Component)
195
259
{
196
260
DEBUGBREAK ();
261
+
197
262
osi3::SensorView currentIn;
198
263
osi3::SensorData currentOut;
199
264
double time = currentCommunicationPoint+communicationStepSize;
200
265
normal_log (" OSI" ," Calculating Sensor at %f for %f (step size %f)" ,currentCommunicationPoint,time ,communicationStepSize);
201
266
if (get_fmi_sensor_view_in (currentIn)) {
202
267
double ego_x=0 , ego_y=0 , ego_z=0 ;
203
268
osi3::Identifier ego_id = currentIn.global_ground_truth ().host_vehicle_id ();
204
- normal_log (" OSI" ," Looking for EgoVehicle with ID: %d " ,ego_id.value ());
269
+ normal_log (" OSI" ," Looking for EgoVehicle with ID: %llu " ,ego_id.value ());
205
270
for_each (currentIn.global_ground_truth ().moving_object ().begin (),currentIn.global_ground_truth ().moving_object ().end (),
206
271
[this , ego_id, &ego_x, &ego_y, &ego_z](const osi3::MovingObject& obj) {
207
- normal_log (" OSI" ," MovingObject with ID %d is EgoVehicle: %d" ,obj.id ().value (), obj.id ().value () == ego_id.value ());
272
+ normal_log (" OSI" ," MovingObject with ID %llu is EgoVehicle: %d" ,obj.id ().value (), obj.id ().value () == ego_id.value ());
208
273
if (obj.id ().value () == ego_id.value ()) {
209
- normal_log (" OSI" ," Found EgoVehicle with ID: %d " ,obj.id ().value ());
274
+ normal_log (" OSI" ," Found EgoVehicle with ID: %llu " ,obj.id ().value ());
210
275
ego_x = obj.base ().position ().x ();
211
276
ego_y = obj.base ().position ().y ();
212
277
ego_z = obj.base ().position ().z ();
@@ -224,8 +289,9 @@ fmi2Status COSMPDummySensor::doCalc(fmi2Real currentCommunicationPoint, fmi2Real
224
289
currentOut.add_sensor_view ()->CopyFrom (currentIn);
225
290
226
291
int i=0 ;
292
+ double actual_range = fmi_nominal_range ()*1.1 ;
227
293
for_each (currentIn.global_ground_truth ().moving_object ().begin (),currentIn.global_ground_truth ().moving_object ().end (),
228
- [this ,&i,¤tIn,¤tOut,ego_id,ego_x,ego_y,ego_z](const osi3::MovingObject& veh) {
294
+ [this ,&i,¤tIn,¤tOut,ego_id,ego_x,ego_y,ego_z,actual_range ](const osi3::MovingObject& veh) {
229
295
if (veh.id ().value () != ego_id.value ()) {
230
296
// NOTE: We currently do not take sensor mounting position into account,
231
297
// i.e. sensor-relative coordinates are relative to center of bounding box
@@ -236,11 +302,11 @@ fmi2Status COSMPDummySensor::doCalc(fmi2Real currentCommunicationPoint, fmi2Real
236
302
double rel_x,rel_y,rel_z;
237
303
rotatePoint (trans_x,trans_y,trans_z,veh.base ().orientation ().yaw (),veh.base ().orientation ().pitch (),veh.base ().orientation ().roll (),rel_x,rel_y,rel_z);
238
304
double distance = sqrt (rel_x*rel_x + rel_y*rel_y + rel_z*rel_z);
239
- if ((distance <= 150.0 ) && (rel_x/distance > 0.866025 )) {
305
+ if ((distance <= actual_range ) && (rel_x/distance > 0.866025 )) {
240
306
osi3::DetectedMovingObject *obj = currentOut.mutable_moving_object ()->Add ();
241
307
obj->mutable_header ()->add_ground_truth_id ()->CopyFrom (veh.id ());
242
308
obj->mutable_header ()->mutable_tracking_id ()->set_value (i);
243
- obj->mutable_header ()->set_existence_probability (cos ((distance- 75.0 )/ 75.0 ));
309
+ obj->mutable_header ()->set_existence_probability (cos ((2.0 *distance-actual_range)/actual_range ));
244
310
obj->mutable_header ()->set_measurement_state (osi3::DetectedItemHeader_MeasurementState_MEASUREMENT_STATE_MEASURED);
245
311
obj->mutable_header ()->add_sensor_id ()->CopyFrom (currentIn.sensor_id ());
246
312
obj->mutable_base ()->mutable_position ()->set_x (veh.base ().position ().x ());
@@ -255,15 +321,15 @@ fmi2Status COSMPDummySensor::doCalc(fmi2Real currentCommunicationPoint, fmi2Real
255
321
candidate->mutable_vehicle_classification ()->CopyFrom (veh.vehicle_classification ());
256
322
candidate->set_probability (1 );
257
323
258
- normal_log (" OSI" ," Output Vehicle %d[%d ] Probability %f Relative Position: %f,%f,%f (%f,%f,%f)" ,i,veh.id ().value (),obj->header ().existence_probability (),rel_x,rel_y,rel_z,obj->base ().position ().x (),obj->base ().position ().y (),obj->base ().position ().z ());
324
+ normal_log (" OSI" ," Output Vehicle %d[%llu ] Probability %f Relative Position: %f,%f,%f (%f,%f,%f)" ,i,veh.id ().value (),obj->header ().existence_probability (),rel_x,rel_y,rel_z,obj->base ().position ().x (),obj->base ().position ().y (),obj->base ().position ().z ());
259
325
i++;
260
326
} else {
261
- normal_log (" OSI" ," Ignoring Vehicle %d[%d ] Outside Sensor Scope Relative Position: %f,%f,%f (%f,%f,%f)" ,i,veh.id ().value (),veh.base ().position ().x ()-ego_x,veh.base ().position ().y ()-ego_y,veh.base ().position ().z ()-ego_z,veh.base ().position ().x (),veh.base ().position ().y (),veh.base ().position ().z ());
327
+ normal_log (" OSI" ," Ignoring Vehicle %d[%llu ] Outside Sensor Scope Relative Position: %f,%f,%f (%f,%f,%f)" ,i,veh.id ().value (),veh.base ().position ().x ()-ego_x,veh.base ().position ().y ()-ego_y,veh.base ().position ().z ()-ego_z,veh.base ().position ().x (),veh.base ().position ().y (),veh.base ().position ().z ());
262
328
}
263
329
}
264
330
else
265
331
{
266
- normal_log (" OSI" ," Ignoring EGO Vehicle %d[%d ] Relative Position: %f,%f,%f (%f,%f,%f)" ,i,veh.id ().value (),veh.base ().position ().x ()-ego_x,veh.base ().position ().y ()-ego_y,veh.base ().position ().z ()-ego_z,veh.base ().position ().x (),veh.base ().position ().y (),veh.base ().position ().z ());
332
+ normal_log (" OSI" ," Ignoring EGO Vehicle %d[%llu ] Relative Position: %f,%f,%f (%f,%f,%f)" ,i,veh.id ().value (),veh.base ().position ().x ()-ego_x,veh.base ().position ().y ()-ego_y,veh.base ().position ().z ()-ego_z,veh.base ().position ().x (),veh.base ().position ().y (),veh.base ().position ().z ());
267
333
}
268
334
});
269
335
normal_log (" OSI" ," Mapped %d vehicles to output" , i);
@@ -284,6 +350,7 @@ fmi2Status COSMPDummySensor::doCalc(fmi2Real currentCommunicationPoint, fmi2Real
284
350
fmi2Status COSMPDummySensor::doTerm ()
285
351
{
286
352
DEBUGBREAK ();
353
+
287
354
return fmi2OK;
288
355
}
289
356
@@ -304,7 +371,7 @@ COSMPDummySensor::COSMPDummySensor(fmi2String theinstanceName, fmi2Type thefmuTy
304
371
functions(*thefunctions),
305
372
visible(!!thevisible),
306
373
loggingOn(!!theloggingOn),
307
- last_time( 0.0 )
374
+ simulation_started( false )
308
375
{
309
376
loggingCategories.clear ();
310
377
loggingCategories.insert (" FMI" );
@@ -385,6 +452,7 @@ fmi2Status COSMPDummySensor::EnterInitializationMode()
385
452
fmi2Status COSMPDummySensor::ExitInitializationMode ()
386
453
{
387
454
fmi_verbose_log (" fmi2ExitInitializationMode()" );
455
+ simulation_started = true ;
388
456
return doExitInitializationMode ();
389
457
}
390
458
@@ -405,6 +473,7 @@ fmi2Status COSMPDummySensor::Reset()
405
473
fmi_verbose_log (" fmi2Reset()" );
406
474
407
475
doFree ();
476
+ simulation_started = false ;
408
477
return doInit ();
409
478
}
410
479
@@ -429,10 +498,15 @@ fmi2Status COSMPDummySensor::GetReal(const fmi2ValueReference vr[], size_t nvr,
429
498
fmi2Status COSMPDummySensor::GetInteger (const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[])
430
499
{
431
500
fmi_verbose_log (" fmi2GetInteger(...)" );
501
+ bool need_refresh = !simulation_started;
432
502
for (size_t i = 0 ; i<nvr; i++) {
433
- if (vr[i]<FMI_INTEGER_VARS)
503
+ if (vr[i]<FMI_INTEGER_VARS) {
504
+ if (need_refresh && (vr[i] == FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_BASEHI_IDX || vr[i] == FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_BASELO_IDX || vr[i] == FMI_INTEGER_SENSORVIEW_CONFIG_REQUEST_SIZE_IDX)) {
505
+ refresh_fmi_sensor_view_config_request ();
506
+ need_refresh = false ;
507
+ }
434
508
value[i] = integer_vars[vr[i]];
435
- else
509
+ } else
436
510
return fmi2Error;
437
511
}
438
512
return fmi2OK;
0 commit comments