I have a c++ issue which I am not sure what to ask and what might be the best solution for it given my few weeks of c++ experience.
Given a c++ class, in one of it's functions I initialize the following object:
franka::Robot robot(robot_ip);
and after some other lines I reach to:
robot.control(callback);
which starts a non-stopping internal While loop that and keeps the code blocked on this line. However, I want to still continue using another function of this class which is not possible now since the code is blocked in that last line.
Is there a way that I tell C++ to execute that last line in a non-blocking way in the background or in a separate process or thread and continue with the remaining lines?
I am not sure what might be the advantage of each way also. For example I can imagine it may be possible to do this in a separate process or separate thread or other ways while not knowing which might be the best, and hope that their syntax is easy. I know however the speed can be crucial and that we don't want to have this internal loop interrupted.
I looked at some other questions for example in this thread but I'm confused how I can modify my syntax if I were to use them or not sure even if it's possible.
------edit::
I tried std::thread([](){ robot.control(torque_control_cb); }).detach();
as the answer from here suggests but got the following error:
5: error: ‘robot’ is not captured
std::thread([](){ robot.control(callback); }).detach();
Changing that line to std::thread t1(robot.control, callback);
also gave the error:
error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, std::function<franka::Torques(const franka::RobotState&, franka::Duration)>&)’
std::thread t1(robot.control, callback)
Similarly:
error: ‘async’ is not a member of ‘std’
auto result = std::async(std::launch::async, [](){robot.control(callback);});