本文整理汇总了C++中Encoder::attach方法的典型用法代码示例。如果您正苦于以下问题:C++ Encoder::attach方法的具体用法?C++ Encoder::attach怎么用?C++ Encoder::attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoder
的用法示例。
在下文中一共展示了Encoder::attach方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
/*
* Updates the fields of current motor and sets the Heading
* of its pins
*/
void MotorController::init()
{
// Attach motors
leftMotor.attach(LEFT_MOTOR_IN_A_PIN, LEFT_MOTOR_IN_B_PIN, LEFT_MOTOR_PWM_PIN);
rightMotor.attach(RIGHT_MOTOR_IN_A_PIN, RIGHT_MOTOR_IN_B_PIN, RIGHT_MOTOR_PWM_PIN);
// Attach encoders
leftEncoder.attach(LEFT_ENCODER_INT_PIN, LEFT_ENCODER_DIGITAL_PIN);
rightEncoder.attach(RIGHT_ENCODER_INT_PIN, RIGHT_ENCODER_DIGITAL_PIN);
// Consider the starting point of the robot
// as its origin
_position.setX(0);
_position.setY(0);
// Suppose robot is heading along Y axis
_heading = 90;
// Initialize the number of commands to 0
_commandsCount = 0;
_processingNewCommand = true;
_leftMotorPosition = 0;
_leftMotorLastPosition = 0;
_rightMotorPosition = 0;
_rightMotorLastPosition = 0;
_leftMotorSpeed = 0;
_rightMotorSpeed = 0;
_leftMotorPWM = 0;
_rightMotorPWM = 0;
// Set vacuum pump pin as output
pinMode(VACUUM_PIN, OUTPUT);
stopVacuum();
}