I need to execute certain code after certain duration/after certain timestep.
For an example, In ROS, we implement Service API and client can call the service request whenever needed.
So When a client call a service API, first block of code should be executed without any delay and then after certain duration/timeStep second block of code should be executed (like LED blinking) and the cycle repeat until client sends stop request.
Now my question is that how can I achieve this cycle?
uint m_tickCount{};
uint duration {500}; // timeStep /** tick */
void LedFlash(const Animation& animation, std::unordered_map<int, int> ledsHandle)
{
//first block
std::for_each(leds.begin(), leds.end(), [&](int value) {
simSetShapeColor(ledsHandle[value], nullptr, sim_colorcomponent_ambient_diffuse,
colorValue.data());
});
//second block
std::for_each(leds.begin(), leds.end(), [&](int value) {
simSetShapeColor(ledsHandle[value], nullptr, sim_colorcomponent_ambient_diffuse,
colorValue.data());
});
}
For an example, as soon as the client call the service first block of code should be executed and after specified time step second block of code should be executed, then again after specified time step first block should be executed and cycle repeat.
Any hint or suggestion?
Thanks in advance
You want to clearly define all of your variables first, then you can do two if statements to determine if the sword_check and/or shield_check dummy variables should be equal to 1. The following code should get you started.