Bir Robot Programı Oluşturmak - WPILib

TimedRobot

Documentation: Java - C++

Kaynak: Java <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java> __ - C ++ <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibc/src/main/native/cpp/TimedRobot.cpp> __

The TimedRobot class is the base class recommended for most users. It provides control of the robot program through a collection of init(), periodic(), and exit() methods, which are called by WPILib during specific robot states (e.g. autonomous or teleoperated). During these calls, your code typically polls each input device and acts according to the data it receives. For instance, you would typically determine the position of the joystick and state of the joystick buttons on each call and act accordingly. The TimedRobot class also provides an example of retrieving autonomous routines through SendableChooser (Java/ C++)

Not

Bazı bilgilendirici yorumları ve otonom örneği kaldıran bir TimedRobot Skeleton şablonu mevcuttur. Zaten TimedRobot u biliyorsanız bunu kullanabilirsiniz. Aşağıda gösterilen örnek TimedRobot Skeleton içindir.

JAVA 7importedu.wpi.first.wpilibj.TimedRobot; 8 9/** 10 * The methods in this class are called automatically corresponding to each mode, as described in 11 * the TimedRobot documentation. If you change the name of this class or the package after creating 12 * this project, you must also update the Main.java file in the project. 13 */ 14publicclass RobotextendsTimedRobot{ 15/** 16 * This function is run when the robot is first started up and should be used for any 17 * initialization code. 18 */ 19publicRobot(){} 20 21@Override 22publicvoidrobotPeriodic(){} 23 24@Override 25publicvoidautonomousInit(){} 26 27@Override 28publicvoidautonomousPeriodic(){} 29 30@Override 31publicvoidteleopInit(){} 32 33@Override 34publicvoidteleopPeriodic(){} 35 36@Override 37publicvoiddisabledInit(){} 38 39@Override 40publicvoiddisabledPeriodic(){} 41 42@Override 43publicvoidtestInit(){} 44 45@Override 46publicvoidtestPeriodic(){} 47 48@Override 49publicvoidsimulationInit(){} 50 51@Override 52publicvoidsimulationPeriodic(){} 53} C++ 5#include"Robot.h" 6 7Robot::Robot(){} 8voidRobot::RobotPeriodic(){} 9 10voidRobot::AutonomousInit(){} 11voidRobot::AutonomousPeriodic(){} 12 13voidRobot::TeleopInit(){} 14voidRobot::TeleopPeriodic(){} 15 16voidRobot::DisabledInit(){} 17voidRobot::DisabledPeriodic(){} 18 19voidRobot::TestInit(){} 20voidRobot::TestPeriodic(){} 21 22voidRobot::SimulationInit(){} 23voidRobot::SimulationPeriodic(){} 24 25#ifndef RUNNING_FRC_TESTS 26intmain(){ 27returnfrc::StartRobot<Robot>(); 28} 29#endif

Periyodik yöntemler varsayılan olarak her 20 ms’de bir çağrılır. Bu, istenen yeni güncelleme oranıyla üst sınıf kurucusunu çağırarak değiştirilebilir.

Tehlike

Changing your robot rate can cause some unintended behavior (loop overruns). Teams can also use Notifiers to schedule methods at a custom rate.

JAVA publicRobot(){ super(0.03);// Periodic methods will now be called every 30 ms. } C++ Robot():frc::TimedRobot(30_ms){}

Từ khóa » Visual Studio Code örnek Projeler