Position Hold with Flowdeck and CPPM input

Discussions about all things Bitcraze
Post Reply
4things
Beginner
Posts: 9
Joined: Wed Mar 02, 2022 8:27 pm

Position Hold with Flowdeck and CPPM input

Post by 4things »

Dear Bitcraze,

we would like to use CPPM Receiver with Position Hold for our Application, therefore we are using the Flowdeck for that.
While flying with Crazy Radio the Position Hold works flawlessly, I can't figure out how to use Position Hold with CPPM Input though.

What can I do to configure Channel 5 or 6 of the CPPM Lib ( extra.c) to activate Position Hold (through Optical Flow / FlowDeck)?

Thank you in Advance.

4things
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Position Hold with Flowdeck and CPPM input

Post by tobias »

Easiest is probably if you rewrite the ALT hold part and change it to Position hold. This mode is the hoverDecoder in crtp_commander_generic.c. You would have to scale the CPPM input properly.

Without testing it, I think it would look something like this:

Code: Select all

  if (extRxAltHold) 
  {
    extrxSetpoint.thrust = 0;
    extrxSetpoint.mode.z = modeVelocity;

    extrxSetpoint.velocity.z = cppmConvert2Float(ch[EXTRX_CH_THRUST], -1, 1, EXTRX_DEADBAND_ZVEL);
    
    
    extrxSetpoint->mode.yaw = modeVelocity;
    extrxSetpoint->attitudeRate.yaw = EXTRX_SIGN_YAW * EXTRX_SCALE_YAW *cppmConvert2Float(ch[EXTRX_CH_YAW], -1, 1, EXTRX_DEADBAND_YAW);
    
    
    extrxSetpoint->mode.x = modeVelocity;
    extrxSetpoint->mode.y = modeVelocity;
    extrxSetpoint->velocity.x = cppmConvert2Float(ch[EXTRX_CH_ROLL], -1, 1, EXTRX_DEADBAND_ZVEL);
    extrxSetpoint->velocity.y = cppmConvert2Float(ch[EXTRX_CH_PITCH], -1, 1, EXTRX_DEADBAND_ZVEL);
    
    extrxSetpoint->velocity_body = true;
  } 
  else 
  {
    extrxSetpoint.mode.z = modeDisable;
    extrxSetpoint.thrust = cppmConvert2uint16(ch[EXTRX_CH_THRUST]);

    extrxSetpoint.attitude.roll = EXTRX_SIGN_ROLL * EXTRX_SCALE_ROLL * cppmConvert2Float(ch[EXTRX_CH_ROLL], -1, 1, EXTRX_DEADBAND_ROLL);
    extrxSetpoint.attitude.pitch = EXTRX_SIGN_PITCH * EXTRX_SCALE_PITCH * cppmConvert2Float(ch[EXTRX_CH_PITCH], -1, 1, EXTRX_DEADBAND_PITCH);
    extrxSetpoint.attitudeRate.yaw = EXTRX_SIGN_YAW * EXTRX_SCALE_YAW *cppmConvert2Float(ch[EXTRX_CH_YAW], -1, 1, EXTRX_DEADBAND_YAW);
  }
  
  extRxAltHoldPrev = extRxAltHold;
  
  #else
  extrxSetpoint.mode.z = modeDisable;
  extrxSetpoint.thrust = cppmConvert2uint16(ch[EXTRX_CH_THRUST]);
  extrxSetpoint.attitude.roll = EXTRX_SIGN_ROLL * EXTRX_SCALE_ROLL * cppmConvert2Float(ch[EXTRX_CH_ROLL], -1, 1, EXTRX_DEADBAND_ROLL);
  extrxSetpoint.attitude.pitch = EXTRX_SIGN_PITCH * EXTRX_SCALE_PITCH * cppmConvert2Float(ch[EXTRX_CH_PITCH], -1, 1, EXTRX_DEADBAND_PITCH);
  extrxSetpoint.attitudeRate.yaw = EXTRX_SIGN_YAW * EXTRX_SCALE_YAW *cppmConvert2Float(ch[EXTRX_CH_YAW], -1, 1, EXTRX_DEADBAND_YAW);
  #endif
  
  commanderSetSetpoint(&extrxSetpoint, COMMANDER_PRIORITY_EXTRX);

4things
Beginner
Posts: 9
Joined: Wed Mar 02, 2022 8:27 pm

Re: Position Hold with Flowdeck and CPPM input

Post by 4things »

thank you so much that worked perfectly. :D
only one change need to be done

Code: Select all

extrxSetpoint.velocity.x = cppmConvert2Float(ch[EXTRX_CH_ROLL], -1, 1, EXTRX_DEADBAND_ZVEL);
extrxSetpoint.velocity.y = cppmConvert2Float(ch[EXTRX_CH_PITCH], -1, 1, EXTRX_DEADBAND_ZVEL);
needs to be changed to

Code: Select all

extrxSetpoint.velocity.y = cppmConvert2Float(ch[EXTRX_CH_ROLL], -1, 1, EXTRX_DEADBAND_ZVEL);
extrxSetpoint.velocity.x = cppmConvert2Float(ch[EXTRX_CH_PITCH], -1, 1, EXTRX_DEADBAND_ZVEL);
the whole change to extrx.c (https://github.com/bitcraze/crazyflie-f ... trx.c#L202:

Code: Select all

  if (extRxAltHold) 
  {
    extrxSetpoint.thrust = 0;
    extrxSetpoint.mode.z = modeVelocity;

    extrxSetpoint.velocity.z = cppmConvert2Float(ch[EXTRX_CH_THRUST], -1, 1, EXTRX_DEADBAND_ZVEL);
    
    
    extrxSetpoint->mode.yaw = modeVelocity;
    extrxSetpoint->attitudeRate.yaw = EXTRX_SIGN_YAW * EXTRX_SCALE_YAW *cppmConvert2Float(ch[EXTRX_CH_YAW], -1, 1, EXTRX_DEADBAND_YAW);
    
    
    extrxSetpoint->mode.x = modeVelocity;
    extrxSetpoint->mode.y = modeVelocity;
    extrxSetpoint->velocity.y = cppmConvert2Float(ch[EXTRX_CH_ROLL], -1, 1, EXTRX_DEADBAND_ZVEL);
    extrxSetpoint->velocity.x = cppmConvert2Float(ch[EXTRX_CH_PITCH], -1, 1, EXTRX_DEADBAND_ZVEL);
    
    extrxSetpoint->velocity_body = true;
  } 
  else 
  {
    extrxSetpoint.mode.z = modeDisable;
    extrxSetpoint.thrust = cppmConvert2uint16(ch[EXTRX_CH_THRUST]);

    extrxSetpoint.attitude.roll = EXTRX_SIGN_ROLL * EXTRX_SCALE_ROLL * cppmConvert2Float(ch[EXTRX_CH_ROLL], -1, 1, EXTRX_DEADBAND_ROLL);
    extrxSetpoint.attitude.pitch = EXTRX_SIGN_PITCH * EXTRX_SCALE_PITCH * cppmConvert2Float(ch[EXTRX_CH_PITCH], -1, 1, EXTRX_DEADBAND_PITCH);
    extrxSetpoint.attitudeRate.yaw = EXTRX_SIGN_YAW * EXTRX_SCALE_YAW *cppmConvert2Float(ch[EXTRX_CH_YAW], -1, 1, EXTRX_DEADBAND_YAW);
  }
  
  extRxAltHoldPrev = extRxAltHold;
  
  #else
  extrxSetpoint.mode.z = modeDisable;
  extrxSetpoint.thrust = cppmConvert2uint16(ch[EXTRX_CH_THRUST]);
  extrxSetpoint.attitude.roll = EXTRX_SIGN_ROLL * EXTRX_SCALE_ROLL * cppmConvert2Float(ch[EXTRX_CH_ROLL], -1, 1, EXTRX_DEADBAND_ROLL);
  extrxSetpoint.attitude.pitch = EXTRX_SIGN_PITCH * EXTRX_SCALE_PITCH * cppmConvert2Float(ch[EXTRX_CH_PITCH], -1, 1, EXTRX_DEADBAND_PITCH);
  extrxSetpoint.attitudeRate.yaw = EXTRX_SIGN_YAW * EXTRX_SCALE_YAW *cppmConvert2Float(ch[EXTRX_CH_YAW], -1, 1, EXTRX_DEADBAND_YAW);
  #endif
  
  commanderSetSetpoint(&extrxSetpoint, COMMANDER_PRIORITY_EXTRX);
Post Reply