按键滤波算法
来源:互联网 发布:android多线程编程 编辑:程序博客网 时间:2024/06/05 20:46
一、状态稳定才改变键值
/*******************************************************************************capture sensors value*******************************************************************************/static int RobotSensors_CRobotcapture(CRobotSensors_typedef* pRobot){#define SENSORS_IO_AVRANGE_TIME 5//200static uint32_t sLeftLimitTimeOut = 0, sRightLimitTimeOut = 0, sEmercyButtonTimeOut = 0;static uint8_t sLeftlimitAction = Bit_SET, sRightlimitAction = Bit_SET,\ sEmercyButtonAction = Bit_SET;/* Left limit sensor */if(sLeftlimitAction != CROBOT_LEFT_LIMIT_READ){sLeftlimitAction = CROBOT_LEFT_LIMIT_READ;sLeftLimitTimeOut = 0;}else{sLeftLimitTimeOut++;if(sLeftLimitTimeOut > 5){pRobot->L_SideLimit = (SwitchSensorValue_typedef)sLeftlimitAction;sLeftLimitTimeOut = 0;}}/* Right limit sensor */if(sRightlimitAction != CROBOT_RIGHT_LIMIT_READ){sRightlimitAction = CROBOT_RIGHT_LIMIT_READ;sRightLimitTimeOut = 0;}else{sRightLimitTimeOut++;if(sRightLimitTimeOut > 5){pRobot->R_SideLimit = (SwitchSensorValue_typedef)sRightlimitAction;sRightLimitTimeOut = 0;}} /* Emercy button check */if(sEmercyButtonAction != CROBOT_EMECY_STOP_KEY_READ){sEmercyButtonAction = CROBOT_EMECY_STOP_KEY_READ;sEmercyButtonTimeOut = 0;}else{sEmercyButtonTimeOut++;if(sEmercyButtonTimeOut > 5){pRobot->EmercyButton = (SwitchSensorValue_typedef)sEmercyButtonAction;sEmercyButtonTimeOut = 0;}}/* Intergrate check by logical */if(RobotTaskMag.CRobot.RoCtl.ParkOnDir == PARK_ON_RIGHT){if(pRobot->R_SideLimit == ON){pRobot->Integrate = ON;}else{pRobot->Integrate = OFF;}}else if(RobotTaskMag.CRobot.RoCtl.ParkOnDir == PARK_ON_LEFT){if(pRobot->L_SideLimit == ON){pRobot->Integrate = ON;}else{pRobot->Integrate = OFF;}}else if(RobotTaskMag.CRobot.RoCtl.ParkOnDir == PARK_ON_BOTH){if((pRobot->L_SideLimit == ON)||(pRobot->R_SideLimit == ON)){pRobot->Integrate = ON;}else{pRobot->Integrate = OFF;}}/* Check Emergency Button */if(pRobot->EmercyButton == ON){RoSafety.SafetyStatus.SafetyFlagBit.bit_EmergencyButton = 1;}else{RoSafety.SafetyStatus.SafetyFlagBit.bit_EmergencyButton = 0;}return 0;}
二、按键滤波,按键按下保持一段时间才改变键值
static int RobotSensors_TRobotcapture(TRobotSensors_typedef* pRobot){#define SENSORS_IO_AVRANGE_TIME 5static uint32_t sAlignHighSensorTimeout = 0;static uint32_t sAlignLowSensorTimeout = 0;static uint32_t sAheadSensorTimeout = 0;static uint32_t sTailSensorTimeout = 0;static uint32_t sIntegrateSensorTimeout = 0; static uint32_t sEmercyButtonTimeout = 0; static uint32_t sParkedOnSensorTimeout = 0; static uint32_t sSpeedChangeSensorTimeout = 0; /* Ahead limit */if((SwitchSensorValue_typedef)TROBOT_AHEAD_LIMIT_READ == ON){if(sAheadSensorTimeout < SENSORS_IO_AVRANGE_TIME){sAheadSensorTimeout++;}else{pRobot->LimitAhead = ON;}}else{sAheadSensorTimeout = 0;pRobot->LimitAhead = OFF;} /* Tail limit */if((SwitchSensorValue_typedef)TROBOT_TAIL_LIMIT_READ == ON){if(sTailSensorTimeout < SENSORS_IO_AVRANGE_TIME){sTailSensorTimeout++;}else{pRobot->LimitTail = ON;}}else{sTailSensorTimeout = 0;pRobot->LimitTail = OFF;} /* Emercy Button */if((SwitchSensorValue_typedef)TROBOT_EMECY_STOP_KEY_READ == ON){if(sEmercyButtonTimeout < SENSORS_IO_AVRANGE_TIME){sEmercyButtonTimeout++;}else{pRobot->EmercyButton = ON;}}else{sEmercyButtonTimeout = 0;pRobot->EmercyButton = OFF;} /* Packing limit */if((SwitchSensorValue_typedef)TROBOT_PARKING_LIMIT_READ == ON){if(sParkedOnSensorTimeout < SENSORS_IO_AVRANGE_TIME){sParkedOnSensorTimeout++;}else{pRobot->ParkedOn = ON;}}else{pRobot->ParkedOn = OFF;sParkedOnSensorTimeout = 0;} /* Intergrate limit */ if((SwitchSensorValue_typedef)TROBOT_INTERGRATE_READ == ON){if(sIntegrateSensorTimeout < SENSORS_IO_AVRANGE_TIME){sIntegrateSensorTimeout++;}else{pRobot->Integrate = ON;}}else{sIntegrateSensorTimeout = 0;pRobot->Integrate = OFF;} /* Speed change sensor */if((SwitchSensorValue_typedef)TROBOT_SPEED_CHANGE_LIMIT_READ == ON){if(sSpeedChangeSensorTimeout < SENSORS_IO_AVRANGE_TIME){sSpeedChangeSensorTimeout++;}else{pRobot->SpeedChange = ON;}}else{pRobot->SpeedChange = OFF;sSpeedChangeSensorTimeout = 0;} /* Align high */if((SwitchSensorValue_typedef)ALIGN_HIGH_LIMIT_READ == ON){if(sAlignHighSensorTimeout < SENSORS_IO_AVRANGE_TIME){sAlignHighSensorTimeout++;}else{pRobot->AlignHighside = ON;}}else{sAlignHighSensorTimeout = 0;pRobot->AlignHighside = OFF;} /* Align low */if((SwitchSensorValue_typedef)ALIGN_LOW_LIMIT_READ == ON){if(sAlignLowSensorTimeout < SENSORS_IO_AVRANGE_TIME){sAlignLowSensorTimeout++;}else{pRobot->AlignLowside = ON;}}else{sAlignLowSensorTimeout = 0;pRobot->AlignLowside = OFF;}/* Check Emergency Button */if(pRobot->EmercyButton == ON){RoSafety.SafetyStatus.SafetyFlagBit.bit_EmergencyButton = 1;}else{RoSafety.SafetyStatus.SafetyFlagBit.bit_EmergencyButton = 0;}return 0;}
阅读全文
0 0
- 按键滤波算法
- 滤波算法
- 滤波算法
- 滤波算法
- 滤波算法
- 滤波算法
- 滤波算法
- 按键软件滤波,PCB板检查完毕
- 图像滤波算法
- 常用滤波算法搜集
- 常用滤波算法
- 单片机 滤波算法
- 常用滤波算法搜集
- osea滤波算法
- 滤波算法比较
- 经典的滤波算法
- 中值滤波算法
- 常用滤波算法
- mui软键盘顶起底部选项卡
- repo git 设置proxy
- ListView的监听器中OnItemClick各个参数的作用
- 转载-【Python】Python中的True, False条件判断
- Error inflating class android.support.design.widget.NavigationView
- 按键滤波算法
- json字符串中,包含函数的处理
- C#学习笔记之——重载
- jquery限制输入的数字为(8,2)格式
- NERSim v1.09a 1CD+HyperMILL 2018.1
- 一只程序猿的养成日记 第一章 第九节 小游戏 扫雷的实现
- TinyXML2使用方法及示例
- 交叉熵到logistic和softmax
- 我的Ubuntu脚印