matlab如何实现PID控制小车前进到指定位置

发布时间:2022-01-14 10:22:21 作者:iii
来源:亿速云 阅读:192

这篇文章主要介绍“matlab如何实现PID控制小车前进到指定位置”,在日常操作中,相信很多人在matlab如何实现PID控制小车前进到指定位置问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”matlab如何实现PID控制小车前进到指定位置”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

分为三步:

根据目标位置确定小车前进方向

计算目标方向与当前方向的差异

选取适当PID参数驱动左右轮运转


首先打开这个文件

matlab如何实现PID控制小车前进到指定位置  

matlab如何实现PID控制小车前进到指定位置  

实现PID控制小车前进到指定位置

%% START CODE BLOCK %%

            % 1. Calculate the heading (angle) to the goal.

            % distance between goal and robot in x-direction

            u_x = x_g-x;

            % distance between goal and robot in y-direction

            u_y = y_g-y;

            % angle from robot to goal. Hint: use ATAN2, u_x, u_y here.

            theta_g = atan2(u_y,u_x);

            % 2. Calculate the heading error.

            % error between the goal angle and robot's angle

            % Hint: Use ATAN2 to make sure this stays in [-pi,pi].

            e_k = atan2(sin(theta_g-theta),cos(theta_g-theta));  

            % 3. Calculate PID for the steering angle 

            % error for the proportional term

            e_P = e_k;

            % error for the integral term. Hint: Approximate the integral using

            % the accumulated error, obj.E_k, and the error for

            % this time step, e_k.

            e_I = obj.E_k + e_k*dt;

            % error for the derivative term. Hint: Approximate the derivative

            % using the previous error, obj.e_k_1, and the

            % error for this time step, e_k.

            e_D = (e_k-obj.e_k_1)/dt;   

            %% END CODE BLOCK %%

最后运行

matlab如何实现PID控制小车前进到指定位置    

到此,关于“matlab如何实现PID控制小车前进到指定位置”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. 怎么在OpenLayer中实现小车按路径运动
  2. python3怎么实现raspberry pi 4驱小车控制程序

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

matlab

上一篇:​matlab怎么实现小车避让障碍物

下一篇:springboot整合quartz定时任务框架的方法是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》