我正在尝试创建我的 swerveDrive
,但我遇到了构造函数与参数列表不匹配的问题。
我已经尝试进入类并更改要求的参数。
通用外壳.h
class GenericEnclosure : public SwerveEnclosure {
công cộng:
GenericEnclosure( std::string name,
frc::SpeedController& m_moveMotor,
frc::SpeedController& m_turnMotor,
rev::CANEncoder& m_encoder,
double m_gearRatio);
~GenericEnclosure();
};
RobotDriveSwerve.h文件
class RobotDriveSwerve
{
công cộng:
RobotDriveSwerve(SwerveEnclosure* frontLeftWheel,
SwerveEnclosure* frontRightWheel,
SwerveEnclosure* rearLeftWheel,
SwerveEnclosure* rearRightWheel,
double width, double length);
virtual ~RobotDriveSwerve() = default;
.cpp文件
//All Drive Motors
rev::CANSparkMax m_leftFrontDriveMotor{1, rev::CANSparkMax::MotorType::kBrushless};
rev::CANSparkMax m_leftBackDriveMotor{2, rev::CANSparkMax::MotorType::kBrushless};
rev::CANSparkMax m_rightFrontDriveMotor{3, rev::CANSparkMax::MotorType::kBrushless};
rev::CANSparkMax m_rightBackDriveMotor{4, rev::CANSparkMax::MotorType::kBrushless};
//All Turn Motors
rev::CANSparkMax m_leftFrontTurnMotor{5, rev::CANSparkMax::MotorType::kBrushless};
rev::CANSparkMax m_leftBackTurnMotor{6, rev::CANSparkMax::MotorType::kBrushless};
rev::CANSparkMax m_rightFrontTurnMotor{7, rev::CANSparkMax::MotorType::kBrushless};
rev::CANSparkMax m_rightBackTurnMotor{8, rev::CANSparkMax::MotorType::kBrushless};
//All Drive Encoders
rev::CANEncoder m_leftFrontDriveEncoder = m_leftFrontDriveMotor.GetEncoder();
rev::CANEncoder m_leftBackDriveEncoder = m_leftBackDriveMotor.GetEncoder();
rev::CANEncoder m_rightFrontDriveEncoder = m_rightFrontDriveMotor.GetEncoder();
rev::CANEncoder m_rightBackDriveEncoder = m_rightBackDriveMotor.GetEncoder();
//All Turn Encoders
rev::CANEncoder m_leftFrontTurnEncoder = m_leftFrontTurnMotor.GetEncoder();
rev::CANEncoder m_leftBackTurnEncoder = m_leftBackTurnMotor.GetEncoder();
rev::CANEncoder m_rightFrontTurnEncoder = m_rightFrontTurnMotor.GetEncoder();
rev::CANEncoder m_rightBackTurnEncoder = m_rightBackTurnMotor.GetEncoder();
const double GEAR_RATIO = (1988/1.2);
const double L = 24.5;
const double W = 20.5;
//Enclosure initialization
GenericEnclosure swerveEnclosure1{"enc 1", m_rightFrontDriveMotor, m_rightFrontDriveMotor, m_rightFrontTurnEncoder,GEAR_RATIO};
GenericEnclosure swerveEnclosure2{"enc 2", m_leftFrontDriveMotor, m_leftFrontTurnMotor, m_leftFrontTurnEncoder, GEAR_RATIO};
GenericEnclosure swerveEnclosure3{"enc 3", m_leftBackDriveMotor, m_leftBackTurnMotor, m_leftBackTurnEncoder, GEAR_RATIO};
GenericEnclosure swerveEnclosure4{"enc 4", m_rightBackDriveMotor, m_rightBackTurnMotor, m_rightBackTurnEncoder, GEAR_RATIO};
//Swerve Drive initialization
RobotDriveSwerve swerveDrive{swerveEnclosure1, swerveEnclosure2, swerveEnclosure3, swerveEnclosure4, W, L};
错误来自此行 RobotDriveSwerve swerveDrive{swerveEnclosure1, swerveEnclosure2, swerveEnclosure3, swerveEnclosure4, W, L};
并抛出此错误 no instance of constructor "RobotDriveSwerve::RobotDriveSwerve"匹配参数列表——参数类型是:(GenericEnclosure, GenericEnclosure, GenericEnclosure, GenericEnclosure, const double, const double)
。一切都编译得很好,但这是唯一挣扎的线。对不起所有的代码,但它是一个相当大的类来正确构建。非常感谢所有能够提供帮助的人!
RobotDriveSwerve
构造函数正在寻找指针。您需要使用“地址”运算符。改变
RobotDriveSwerve swerveDrive{swerveEnclosure1, swerveEnclosure2, swerveEnclosure3, swerveEnclosure4, W, L};
đến
RobotDriveSwerve swerveDrive{&swerveEnclosure1, &swerveEnclosure2, &swerveEnclosure3, &swerveEnclosure4, W, L};
Tôi là một lập trình viên xuất sắc, rất giỏi!