riebl / vanetza

Open-source implementation of the ETSI C-ITS protocol stack
Other
201 stars 158 forks source link

Socktap - gps_position_provider #232

Closed khevessy closed 3 weeks ago

khevessy commented 4 weeks ago

Hi, I encountered a GPSD server which does not send position confidence values, even though the position data is valid. After reading the 102-894 CDD

/**
 * This DE indicates the horizontal position confidence value which represents the estimated absolute position accuracy, in one of the axis direction as defined in a shape of ellipse with a 
 * confidence level of 95 %. 
 * 
 * The value shall be set to:
 * - `n` (`n > 0` and `n < 4 094`) if the accuracy is equal to or less than n * 0,01 metre,
 * - `4 094` if the accuracy is out of range, i.e. greater than 4,093 m,
 * - `4 095` if the accuracy information is unavailable.
 *
 * The value 0 shall not be used.
 * 
 * @note: The fact that a position coordinate value is received with confidence value set to `unavailable(4095)`.
 * can be caused by several reasons, such as:
 * - the sensor cannot deliver the accuracy at the defined confidence level because it is a low-end sensor,
 * - the sensor cannot calculate the accuracy due to lack of variables, or
 * - there has been a vehicle bus (e.g. CAN bus) error.
 * In all 3 cases above, the position coordinate value may be valid and used by the application.
 * If a position coordinate value is received and its confidence value is set to `outOfRange(4094)`, it means that
 * the position coordinate value is not valid and therefore cannot be trusted. Such value is not useful
 * for the application.

 * @unit 0,01 metre 
 * @category: GeoReference Information
 * @revision: Description revised in V2.1.1
 */
SemiAxisLength ::= INTEGER{
    doNotUse    (0),
    outOfRange  (4094), 
    unavailable (4095)
} (0..4095)

How about that if the value is not available, position provider sets it to unavailable, e.g.

        if (!std::isnan(gps_data.fix.epx) && !std::isnan(gps_data.fix.epy)) {
            if (gps_data.fix.epx > gps_data.fix.epy) {
                fetched_position_fix.confidence.semi_minor = gps_data.fix.epy * si::meter;
                fetched_position_fix.confidence.semi_major = gps_data.fix.epx * si::meter;
                fetched_position_fix.confidence.orientation = north + 90.0 * degree;
            } else {
                fetched_position_fix.confidence.semi_minor = gps_data.fix.epx * si::meter;
                fetched_position_fix.confidence.semi_major = gps_data.fix.epy * si::meter;
                fetched_position_fix.confidence.orientation = north;
            }
        } else {
            fetched_position_fix.confidence = vanetza::PositionConfidence();
            fetched_position_fix.confidence.semi_minor = 4.095 * si::meter;
            fetched_position_fix.confidence.semi_major = 4.095 * si::meter;
            fetched_position_fix.confidence.orientation = north;
        }

so that then the application can actually use the location? I am not sure how to determine when the location is valid and when it is not.

riebl commented 4 weeks ago

Hi @khevessy,

the vanetza::PositionFix and vanetza::PositionConfidence data structures are not directly linked to CDD on purpose, so you can use them in other contexts too. The fields semi_minor and semi_major are set to infinity by default, i.e. you can check if they are set to a proper value using std::isinf. In the context of CDD, you can set SemiAxisLength to 4095 in that case. To make socktap generate CAMs without position confidence, I suggest setting the latitude and longitude fields to NaN or infinity when no position fix is available and checking for these special values in CamApplication instead of the validity of position confidence.

khevessy commented 3 weeks ago

I tried to implement it as you say, seems to be working well. GPSD: host 212.234.160.97 port 1971 (will be used in coming ETSI Plugtest)

riebl commented 3 weeks ago

Thanks, I have merged it. Are you going to join the upcoming ETSI Plugtest?

khevessy commented 3 weeks ago

Sorry there were some mistakes in the code, fixed in the next pull request. Yes, we are going to be there, I think you are participating too?

riebl commented 3 weeks ago

Oops, have completely missed this issue; should work with glasses ;-) Nice, then we will meet in Malaga!