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

如何解决如何同步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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-