我正在编写一些软件来控制四轴飞行器,并且完全陷入了RtosTimers的困境。我收到错误消息“错误:没有构造函数“ rtos :: RtosTimer :: RtosTimer的实例”与“ flightController.h”中的参数列表匹配,行:13,列:29”

我看过手册中的示例代码,我的代码似乎匹配。我也用谷歌搜索,但在RtosThreads内使用RtosTimers找不到任何东西。

也许我会以错误的方式进行操作,因此,如果有人有任何建议,将不胜感激。

这是导致我出现问题的代码

//Rtos Timers
RtosTimer UpdateFlightTimer(Task500Hz, osTimerPeriodic, (void *)0);
RtosTimer UpdateCommandTimer(Task50Hz, osTimerPeriodic, (void *)0);

// A thread to monitor the serial ports
void FlightControllerThread(void const *args)
{
UpdateFlightTimer.start(2);
UpdateCommandTimer.start(20);

// Wait here forever
Thread::wait(osWaitForever);
}

void Task500Hz(void const *n)
{
//Get IMU data and convert to yaw, pitch, roll
_freeIMU.getQ(_rawQuaternion);
_freeIMU.getRate(_gyroRate);
GetAttitude();

//Rate mode
if(_rate == true && _stab == false)
{
    //Update rate PID process value with gyro rate
    _yawRatePIDController->setProcessValue(_gyroRate[0]);
    _pitchRatePIDController->setProcessValue(_gyroRate[2]);
    _rollRatePIDController->setProcessValue(_gyroRate[1]);

    //Update rate PID set point with desired rate from RC
    _yawRatePIDController->setSetPoint(_rcConstrainedCommands[0]);
    _pitchRatePIDController->setSetPoint(_rcConstrainedCommands[1]);
    _rollRatePIDController->setSetPoint(_rcConstrainedCommands[2]);

    //Compute rate PID outputs
    _ratePIDControllerOutputs[0] = _yawRatePIDController->compute();
    _ratePIDControllerOutputs[1] = _pitchRatePIDController->compute();
    _ratePIDControllerOutputs[2] = _rollRatePIDController->compute();
}
//Stability mode
else
{
    //Update stab PID process value with ypr
    _yawStabPIDController->setProcessValue(_yrp[0]);
    _pitchStabPIDController->setProcessValue(_yrp[2]);
    _rollStabPIDController->setProcessValue(_yrp[1]);

    //Update stab PID set point with desired angle from RC
    _yawStabPIDController->setSetPoint(_yawTarget);
    _pitchStabPIDController->setSetPoint(_rcConstrainedCommands[1]);
    _rollStabPIDController->setSetPoint(_rcConstrainedCommands[2]);

    //Compute stab PID outputs
    _stabPIDControllerOutputs[0] = _yawStabPIDController->compute();
    _stabPIDControllerOutputs[1] = _pitchStabPIDController->compute();
    _stabPIDControllerOutputs[2] = _rollStabPIDController->compute();

    //if pilot commanding yaw
    if(abs(_rcConstrainedCommands[0]) > 5)
    {
        _stabPIDControllerOutputs[0] = _rcConstrainedCommands[0];  //Feed to rate PID     (overwriting stab PID output)
        _yawTarget = _yrp[0];
    }

    //Update rate PID process value with gyro rate
    _yawRatePIDController->setProcessValue(_gyroRate[0]);
    _pitchRatePIDController->setProcessValue(_gyroRate[2]);
    _rollRatePIDController->setProcessValue(_gyroRate[1]);

    //Update rate PID set point with desired rate from stab PID
    _yawRatePIDController->setSetPoint(_stabPIDControllerOutputs[0]);
    _pitchRatePIDController->setSetPoint(_stabPIDControllerOutputs[1]);
    _rollRatePIDController->setSetPoint(_stabPIDControllerOutputs[2]);

    //Compute rate PID outputs
    _ratePIDControllerOutputs[0] = _yawRatePIDController->compute();
    _ratePIDControllerOutputs[1] = _pitchRatePIDController->compute();
    _ratePIDControllerOutputs[2] = _rollRatePIDController->compute();
}


//Calculate motor power if flying
if(_rcCommands[3] > 0 && _armed == true)
{
    _motorPower[0] = Constrain(_rcConstrainedCommands[3] + _ratePIDControllerOutputs[1] + _ratePIDControllerOutputs[2] + _ratePIDControllerOutputs[0], MOTORS_MIN, MOTORS_MAX);
    _motorPower[1] = Constrain(_rcConstrainedCommands[3] + _ratePIDControllerOutputs[1] - _ratePIDControllerOutputs[2] - _ratePIDControllerOutputs[0], MOTORS_MIN, MOTORS_MAX);
    _motorPower[2] = Constrain(_rcConstrainedCommands[3] - _ratePIDControllerOutputs[1] - _ratePIDControllerOutputs[2] + _ratePIDControllerOutputs[0], MOTORS_MIN, MOTORS_MAX);
    _motorPower[3] = Constrain(_rcConstrainedCommands[3] - _ratePIDControllerOutputs[1] + _ratePIDControllerOutputs[2] - _ratePIDControllerOutputs[0], MOTORS_MIN, MOTORS_MAX);
}
//Not flying
else
{
    //Disable motors
    _motorPower[0] = MOTORS_OFF;
    _motorPower[1] = MOTORS_OFF;
    _motorPower[2] = MOTORS_OFF;
    _motorPower[3] = MOTORS_OFF;

    _notFlying ++;
    if(_notFlying > 200) //Not flying for 1 second
    {
        //Reset iteratior
        _notFlying = 0;

        //Zero gyro
        _freeIMU.zeroGyro();

        //Reset I
        _yawRatePIDController->reset();
        _pitchRatePIDController->reset();
        _rollRatePIDController->reset();
        _yawStabPIDController->reset();
        _pitchStabPIDController->reset();
        _rollStabPIDController->reset();
    }
}

//Set motor power
_motor1.write(_motorPower[0]);
_motor2.write(_motorPower[1]);
_motor3.write(_motorPower[2]);
_motor4.write(_motorPower[3]);


}

void Task50Hz(void const *n)
{
//Get RC control values

//Constrain
//Rate mode
if(_rate == true && _stab == false)
{
    _rcConstrainedCommands[0] = Constrain(_rcCommands[0], RC_YAW_RATE_MIN, RC_YAW_RATE_MAX);
    _rcConstrainedCommands[1] = Constrain(_rcCommands[1], RC_PITCH_RATE_MIN, RC_PITCH_RATE_MAX);
    _rcConstrainedCommands[2] = Constrain(_rcCommands[2], RC_ROLL_RATE_MIN, RC_ROLL_RATE_MAX);
    _rcConstrainedCommands[3] = Constrain(_rcCommands[3], RC_THRUST_MIN, RC_THRUST_MAX);
}
else
{
    _rcConstrainedCommands[0] = Constrain(_rcCommands[0], RC_YAW_RATE_MIN, RC_YAW_RATE_MAX);
    _rcConstrainedCommands[1] = Constrain(_rcCommands[1], RC_PITCH_ANGLE_MIN, RC_PITCH_ANGLE_MAX);
    _rcConstrainedCommands[2] = Constrain(_rcCommands[2], RC_ROLL_ANGLE_MIN, RC_ROLL_ANGLE_MAX);
    _rcConstrainedCommands[3] = Constrain(_rcCommands[3], RC_THRUST_MIN, RC_THRUST_MAX);
}
}


我的程序可以在http://mbed.org/users/joe4465/code/QuadMK5/上找到

问题出在flightController.h中,我认为应该弄清楚我要做什么,但是如果有人不确定,请告诉我。

我还有另一个完全不相关的问题。我可以通过串行设置我的PID变量,然后将它们保存到配置文件中,但是如果将数据保存到文件中后立即挂起,将有3分之1挂起,我不确定为什么。有谁知道这可能导致什么?

谢谢乔

最佳答案

我忘记将void const * n放在顶部定义的函数的参数中

关于c++ - mBed C++在RtosThread内部使用RtosTimer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22045359/

10-15 06:27