基礎底盤控制
方法1:使用PROS API:
void opcontrol() {
pros::Controller master(pros::E_CONTROLLER_MASTER);
pros::Motor left_motor(1);
pros::Motor right_motor(-2);
while (true) {
left_motor.move_velocity(std::fmin(std::fmax(master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) + master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X), -127), 127));
right_motor.move_velocity(std::fmin(std::fmax(master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y) - master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X), -127), 127));
pros::delay(10);
}
}
方法2:使用Okapilib:
// main.h
/**
* You should add more #includes here
*/
#include "okapi/api.hpp" // <---
#include "pros/api_legacy.h" // <---
// 把上兩行的註解拿掉
// ...
/**
* If you find doing pros::Motor() to be tedious and you'd prefer just to do
* Motor, you can use the namespace with the following commented out line.
*
* IMPORTANT: Only the okapi or pros namespace may be used, not both
* concurrently! The okapi namespace will export all symbols inside the pros
* namespace.
*/
// using namespace pros;
// using namespace pros::literals;
using namespace okapi; // 把這行的註解拿掉,但是要把pros的namespace都拿掉
// main.cpp
void opcontrol() {
Controller master(ControllerId::master);
Motor left_motor(1);
Motor right_motor(-2);
while (true) {
left_motor.moveVelocity(std::fmin(std::fmax(master.getAnalog(ControllerAnalog::leftY) + master.getAnalog(ControllerAnalog::rightX), -1), 1));
right_motor.moveVelocity(std::fmin(std::fmax(master.getAnalog(ControllerAnalog::leftY) - master.getAnalog(ControllerAnalog::rightX), -1), 1));
pros::delay(10);
}
}
Last updated