如何同步Led闪烁的客户端呼叫?

问题描述

我正在ROS中为c ++中的机器人实现灯光控制模块服务API。我负责实现原型。我已经成功实现了换色和led颜色插值功能。但是对于led闪烁功能,我需要在led闪烁的客户端调用之间进行同步,这意味着,每当客户端对led闪烁的服务API进行调用时,他/她都会给出led的数量(假设在第一个调用中leds是1,2,3,在第二个呼叫4,5,6中则闪烁),闪烁的持续时间(状态在1s,2s等两种颜色之间转换),闪烁的颜色(状态在绿色和红色之间,红色和蓝色)和偏移量(应开始同步闪烁多长时间后,如果需要,您可以忽略它)。

现在,我已经实现了闪烁功能,例如,对于每个客户端呼叫,将创建一个客户端闪烁对象并将其存储在映射容器中,该容器的呼叫名称为key(call1,call2等),并将值作为客户端请求参数。如果新的客户端呼叫具有与前一个相同的led,则旧的客户端呼叫对象将从容器中删除。最后,将为每次运行的系统执行功能。

始终同步所有客户端调用的第一状态,其他状态无需同步。 例如,如果第一呼叫持续时间是1s,第二呼叫持续时间是2s,第三呼叫持续时间是3s。第一次通话的第二个眨眼周期为第二个,而第二个通话的第二个眨眼周期为一个和三个眨眼周期。

这是代码...

bool LightControlModule::Delay()
{
   
    return m_tickCount == 0;
}

void LightControlModule::LedFlash(LightControlModule::Animation& animation,sim_vector_l ledsHandle)
{
    if (animation.offset && animation.function == "snap" && animation.colorValue.size() == 2 &&
        m_clientCall)
    {
        animation.tickCount += 1;
        if (animation.tickCount == animation.offset)
        {
            animation.stateFlag = false;
            animation.offset = 0;
            if (!Delay())
            {
                animation.stateFlag = true;
                return;
            }
        }
        else
        {
            return;
        }
    }
    else if (animation.function == "snap" && animation.stateFlag)
    {
        if (Delay())
        {
            animation.stateFlag = false;
            animation.tickCount = 0;
        }
        else
        {
            return;
        }
    }
/**  increasing the duration count of previous blinking client calls is also possible in oder to
 * synchronize with the new blinking client call through creating separate container for
 * blinking client call objects and check the size of the container for everytick,if size
 * increased which means,duration count of previous blinking client objects should be increased
 * for the synchronization,while increasing duration count we need to take offset of new
 * blinking client call into account */

if (animation.colorValue.size() == 2 && m_clientCall && animation.function == "snap")
{
    auto result =
        static_cast<float>(animation.tick) / static_cast<float>(animation.colorValue.size());
    if (animation.tickCount == animation.tick || animation.tickCount == 0)
    {
        animation.colorIndex1 = 0;
        animation.tickCount = 0;
        animation.halfCount = 0; // there is a possibility to remove halfCount!
    }
    else if ((animation.halfCount % static_cast<int>(std::ceil(result))) == 0)
    {
        animation.colorIndex1 = 1;
        animation.halfCount = 0;
    }

    std::for_each(animation.leds.begin(),animation.leds.end(),[&](int value) {
        simSetShapeColor(ledsHandle[value - 1],nullptr,sim_colorcomponent_ambient_diffuse,animation.colorValue[animation.colorIndex1].data());
    });
    m_tickCount = animation.tickCount;
    animation.tickCount += 1;
    animation.halfCount += 1;
}

}

当前在上面的代码中,我正在同步新的客户端闪烁呼叫,而不会增加旧客户端闪烁呼叫的闪烁持续时间,这意味着新客户端闪烁会等待直到准备好与旧呼叫同步为止。

但是我的经理突然改变了要求,因此我需要增加旧客户端闪烁呼叫的持续时间,以增加同步时间,而不是等待。

我知道如何执行此操作(您可以在代码中间的注释中阅读),但是我觉得这不是完成任务的有效方法。

任何机构都有暗示或建议如何实现吗?

注意:这只是一个伪代码,如果需要更多信息,我会提供。

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...