基于Arduino:球轮机器人(完整程序+3D建模文件).zip

上传者: 46423500 | 上传时间: 2021-12-14 18:04:26 | 文件大小: 66.38MB | 文件类型: ZIP
主程序: #include "gyro.h" #include "pid.h" #include "motor.h" #define dt 10 // in ms /* Object definitions and settings */ Gyro myGyro(dt); PIDControl pid(1.0,0,0.005,-255,255,dt); OmniMotorDriver omd; /* Deadzone definition. With a rotation of less than this value, * the robot will stand still */ double deadzone = 1.5; /* Buffers for timing, gyro data and PID outputs */ long lastMillis; double xAngle, yAngle; double xOut, yOut; /* Main setup call * Initializes Serial, the IMU and prepares the motor driver, * calbriates the IMU and enables the PID controller */ void setup() { pinMode(13, OUTPUT); Serial.begin(115200); if(!myGyro.init()) { while(1) { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(2000); } } myGyro.calibrate(); omd.init(); pid.enable(); } /* Main loop * The main loop connects all the libraries and classes together, * in that it describes the order of function calls that is necessary * for the function of the robot */ void loop() { /* Save the current point in time in lastMillis */ lastMillis = millis(); /* Get Data from Gyro */ myGyro.update(&xAngle, &yAngle); /* Compute PID Output with the data */ pid.compute(xAngle, yAngle, &xOut, &yOut); /* Plot Angle on Serial Plotter Serial.print(xAngle); Serial.print(" "); Serial.print(yAngle); Serial.println(" "); */ /* Plot Angle on Serial Plotter Serial.print(xOut); Serial.print(" "); Serial.println(yOut); */ /* If any calculated angle is larger than the deadzone */ if(abs(xAngle) > deadzone || abs(yAngle) > deadzone) { /* Actually drive the motors */ omd.drive(xOut, yOut); /* Otherwise, stop them */ } else omd.stop(); /* Wait until the next dt cycle * if processing took less than dt, wait for the remaining time, * otherwise wait for the next full cycle to start * This is needed for gyro and PID accuracy */ int pTime = millis() - lastMillis; int resttime = (dt > pTime

文件下载

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明