title: mBed C++ Using an RtosTimer inside of an RtosThread
body: <p>I am writing some software to control a quadcopter and have got completely stuck with RtosTimers. I am getting the error "Error: No instance of constructor "rtos::RtosTimer::RtosTimer" matches the argument list in "flightController.h", Line: 13, Col: 29"</p>
  
  <p>I have looked at the example code in the handbook and my code seems to match. I have also googled but I couldn't find anything on using RtosTimers inside of RtosThreads.</p>
  
  <p>Maybe I am going about this the wrong way so if anyone has any suggestions it would be much appreciated.</p>
  
  <p>Here is the code that is causing me problems</p>
  
  <pre><code>//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 &amp;&amp; _stab == false)
  {
      //Update rate PID process value with gyro rate
      _yawRatePIDController-&gt;setProcessValue(_gyroRate[0]);
      _pitchRatePIDController-&gt;setProcessValue(_gyroRate[2]);
      _rollRatePIDController-&gt;setProcessValue(_gyroRate[1]);
  
      //Update rate PID set point with desired rate from RC
      _yawRatePIDController-&gt;setSetPoint(_rcConstrainedCommands[0]);
      _pitchRatePIDController-&gt;setSetPoint(_rcConstrainedCommands[1]);
      _rollRatePIDController-&gt;setSetPoint(_rcConstrainedCommands[2]);
  
      //Compute rate PID outputs
      _ratePIDControllerOutputs[0] = _yawRatePIDController-&gt;compute();
      _ratePIDControllerOutputs[1] = _pitchRatePIDController-&gt;compute();
      _ratePIDControllerOutputs[2] = _rollRatePIDController-&gt;compute();
  }
  //Stability mode
  else
  {
      //Update stab PID process value with ypr
      _yawStabPIDController-&gt;setProcessValue(_yrp[0]);
      _pitchStabPIDController-&gt;setProcessValue(_yrp[2]);
      _rollStabPIDController-&gt;setProcessValue(_yrp[1]);
  
      //Update stab PID set point with desired angle from RC
      _yawStabPIDController-&gt;setSetPoint(_yawTarget);
      _pitchStabPIDController-&gt;setSetPoint(_rcConstrainedCommands[1]);
      _rollStabPIDController-&gt;setSetPoint(_rcConstrainedCommands[2]);
  
      //Compute stab PID outputs
      _stabPIDControllerOutputs[0] = _yawStabPIDController-&gt;compute();
      _stabPIDControllerOutputs[1] = _pitchStabPIDController-&gt;compute();
      _stabPIDControllerOutputs[2] = _rollStabPIDController-&gt;compute();
  
      //if pilot commanding yaw
      if(abs(_rcConstrainedCommands[0]) &gt; 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-&gt;setProcessValue(_gyroRate[0]);
      _pitchRatePIDController-&gt;setProcessValue(_gyroRate[2]);
      _rollRatePIDController-&gt;setProcessValue(_gyroRate[1]);
  
      //Update rate PID set point with desired rate from stab PID
      _yawRatePIDController-&gt;setSetPoint(_stabPIDControllerOutputs[0]);
      _pitchRatePIDController-&gt;setSetPoint(_stabPIDControllerOutputs[1]);
      _rollRatePIDController-&gt;setSetPoint(_stabPIDControllerOutputs[2]);
  
      //Compute rate PID outputs
      _ratePIDControllerOutputs[0] = _yawRatePIDController-&gt;compute();
      _ratePIDControllerOutputs[1] = _pitchRatePIDController-&gt;compute();
      _ratePIDControllerOutputs[2] = _rollRatePIDController-&gt;compute();
  }
  
  
  //Calculate motor power if flying
  if(_rcCommands[3] &gt; 0 &amp;&amp; _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 &gt; 200) //Not flying for 1 second
      {
          //Reset iteratior
          _notFlying = 0;
  
          //Zero gyro
          _freeIMU.zeroGyro();
  
          //Reset I
          _yawRatePIDController-&gt;reset();
          _pitchRatePIDController-&gt;reset();
          _rollRatePIDController-&gt;reset();
          _yawStabPIDController-&gt;reset();
          _pitchStabPIDController-&gt;reset();
          _rollStabPIDController-&gt;reset();
      }
  } 
  
  //Set motor power
  _motor1.write(_motorPower[0]);
  _motor2.write(_motorPower[1]);
  _motor3.write(_motorPower[2]);
  _motor4.write(_motorPower[3]);
  </code></pre>
  
  <p>}</p>
  
  <pre><code>void Task50Hz(void const *n)
  {
  //Get RC control values
  
  //Constrain
  //Rate mode
  if(_rate == true &amp;&amp; _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);
  }
  }
  </code></pre>
  
  <p>My program can be found at <a href="http://mbed.org/users/joe4465/code/QuadMK5/" rel="nofollow">http://mbed.org/users/joe4465/code/QuadMK5/</a></p>
  
  <p>And the problem is in flightController.h I think it should be clear what I am trying to do but if anyone isn't sure let me know.</p>
  
  <p>I also have another totally unrelated problem. I can set my PID variables over serial and then save them to a config file but 1 in 3 times if will hang just after it has saved the data to the file and I'm not sure why. Does anyone have any idea what could cause this?</p>
  
  <p>Thanks Joe</p>