[c++] How to stream drone Position to TargetLocation

Ok, so the callback is never called. You can try to make sure the message is sent by requesting the position at a certain rate.

I tried something else; I set promise on Position and slightly changed the callback code

Telemetry::PositionCallback positionCallback(shared_ptr<FollowMe>& followMe, promise<void>& promise){
    return [&promise,&followMe](Telemetry::Position position){
        FollowMe::TargetLocation target{};
        target.latitude_deg = position.latitude_deg;
        target.longitude_deg = position.longitude_deg;
        target.absolute_altitude_m = position.absolute_altitude_m;
        followMe->set_target_location(target);
        cout<<target.latitude_deg<<target.longitude_deg<<target.absolute_altitude_m<<endl;
        promise.set_value();
    };
}

now It’s called once, which is something better than not called at all, but how to make it called only while leader drone is in the air (when his LandedState is Telemetry::LandedState::InAir)?

If you’re having a hard time wrapping your head around all the callbacks and promises, you can also just try to use a while loop and poll the position and then update the target for the follow drone. Maybe that would be an easier approach.

Now I got another progress, one drone actually following other :slight_smile: how I did it:

promise<void> landingPromise;
auto landingFuture = landingPromise.get_future();
bool promiseSatisfied = false;

leaderTelemetry->subscribe_landed_state(landedStateCallback(leaderTelemetry, followMe, inAirPromise,promiseSatisfied));
landingFuture.wait();

callback code:

Telemetry::LandedStateCallback landedStateCallback(shared_ptr<Telemetry>& telemetry, shared_ptr<FollowMe>& followMe, promise<void>& promise,
        bool& promiseSatisfied) {
    return [&promise,&followMe,&telemetry,&promiseSatisfied](Telemetry::LandedState landed){
        FollowMe::TargetLocation targetLocation;
        switch (landed){
            case Telemetry::LandedState::Landing:
                telemetry->subscribe_landed_state(nullptr);
                if(!promiseSatisfied){
                    promise.set_value(); //here "promise already satisfied" error is thrown
                    promiseSatisfied=true;
                }
                break;
            case Telemetry::LandedState::InAir:
                targetLocation.longitude_deg = telemetry->position().longitude_deg;
                targetLocation.latitude_deg = telemetry->position().latitude_deg;
                targetLocation.absolute_altitude_m = telemetry->position().absolute_altitude_m;
                followMe->set_target_location(targetLocation);
                break;
            case Telemetry::LandedState::Unknown:
                std::cout << "Unknown landed state." << std::endl;
                break;
            case Telemetry::LandedState::OnGround:
                break;
            case Telemetry::LandedState::TakingOff:
                break;
        }
    };
}

my only gripe at this moment is throwing “promise already satisfied” error

A promise can only be set once unless you switch to C++17.

I switched on c++17 and still get an error…