当前位置:网站首页>[ardunio] two methods to control the steering gear
[ardunio] two methods to control the steering gear
2022-07-23 13:48:00 【Related to the sun_】
This is my participation in the 11th marine vehicle competition Of Option three :Ardunio programme Control steering gear in
Detailed steering gear control reference -https://www.bilibili.com/video/BV15X4y157ay
The first method :
analogWrite(pin, value)
This method can only make the steering gear in 0~90 Turn... Degrees And the input parameters can only be in [70,350] Between , Otherwise, it will not move , Can't meet my needs .
#define pinServo 11 /* Steering gear control pin be based on ATmega168 and ATmega328 Of Arduino The controller ,
analogWrite() The function supports the following pins : 3, 5, 6, 9, 10, 11*/
// Steering angle The tested value
#define servoRight 70
#define servoMiddle 210
#define servoLeft 350
void setup()
{
Serial.begin(9600);// Serial initialization , Baud rate 9600 byte / second
}
void loop()
{
prePWM = angle2Pwm(realAngle);// Calculate and return the corresponding PWM
analogWrite(pinServo,prePWM);
}
int angle2Pwm(int preAngle)
{
// Convert the angle into the corresponding pwm
int realAngle;
prePWM = float(255*(float)preAngle / 360);
return prePWM;
}
The second method :
Servo library
The angle range that can be controlled is large , Meet my needs .nice
#include <Servo.h>
Servo myservo; // Create a steering gear control object
#define pinServo 11// Steering gear control pin be based on ATmega168 and ATmega328 Of Arduino The controller ,analogWrite() The function supports the following pins : 3, 5, 6, 9, 10, 11.
void setup()
{
myservo.attach(pinServo,500,2500); // inform Arduino Which pin is the data line of the steering gear connected to .
}
void loop()
{
// Let the steering gear in 0~180 Turn back and forth
myservo.write(0);
delay(1000);
myservo.write(180);
delay(1000);
}
边栏推荐
- 高中语文教资考试大纲
- 数据库系统原理与应用教程(041)—— MySQL 查询(三):设置查询条件
- 2022-07-22 回顾链表操作以及部分问题
- docker redis
- 做测试如何应对新的开发模式?
- 浅谈Anroid设备的CPU类型以及so文件的放置目录
- High school Chinese teaching material examination outline
- 数据库系统原理与应用教程(047)—— MySQL 查询(九):连接查询
- [play with FPGA in simple terms to learn 10 ----- simple testbench design]
- 第二章关系数据库课后习题
猜你喜欢

How to deal with the new development mode when doing testing?

vs2019:constexpr 函数“qCountLeadingZeroBits”不能生成常量表达式

Point target simulation of SAR imaging (II) -- matlab simulation

Point target simulation of SAR imaging (III) -- Analysis of simulation results

Special lecture 5 combinatorial mathematics learning experience (long-term update)

Kotlin - Job 任务/取消

Warcraft map editor trigger notes

Convergence of abnormal integral

CSDN推荐模板

做测试如何应对新的开发模式?
随机推荐
Running matlab program on GPU
Backtracking method to solve the eight queens problem
docker mysql
Special topic of MIMO Radar (0) - General Chapter
基于BIM+3DGIS的智慧城市基础设施管理
面试官:有了解过ReentrantLock的底层实现吗?说说看
Chapter II relational database after class exercises
Client does not support authentication protocol requested by server; consider upgrading MySQL client
[cocos creator] spin animation, monitoring and playback end
Probability meditation: 2. The quantitative rules
[play with FPGA in simple terms to learn 10 ----- simple testbench design]
[Muduo] epollplayer event distributor
在虚拟环境下使用pip时默认使用系统环境的pip该怎么办
Interviewer: have you learned about the underlying implementation of reentrantlock? tell us your opinion
Error running ‘XXX‘: Command line is too long. Shorten command line for AudioTest or also ...
Vs2019:constexpr function "qcountleadingzerobits" cannot generate constant expressions
keepalived双机热备
Interface test - simple interface automation test demo
Kept dual machine hot standby
Unity关于本地加载图片涉及webrequest或者byte