CrazyFlie源码学习2-Stabilizer任务
来源:互联网 发布:刘嘉玲康康 知乎 编辑:程序博客网 时间:2024/06/04 20:23
static void stabilizerTask(void* param){ RPYType rollType; RPYType pitchType; RPYType yawType; uint32_t attitudeCounter = 0; uint32_t altHoldCounter = 0; uint32_t lastWakeTime; float yawRateAngle = 0; vTaskSetApplicationTaskTag(0, (void*)TASK_STABILIZER_ID_NBR); //Wait for the system to be fully started to start stabilization loop systemWaitStart(); lastWakeTime = xTaskGetTickCount (); while(1) { vTaskDelayUntil(&lastWakeTime, F2T(IMU_UPDATE_FREQ)); // 500Hz // Magnetometer not yet used more then for logging. imu9Read(&gyro, &acc, &mag); if (imu6IsCalibrated()) { commanderGetRPY(&eulerRollDesired, &eulerPitchDesired, &eulerYawDesired); commanderGetRPYType(&rollType, &pitchType, &yawType); // Rate-controled YAW is moving YAW angle setpoint if (yawType == RATE) { yawRateAngle -= eulerYawDesired/500.0; while (yawRateAngle > 180.0) yawRateAngle -= 360.0; while (yawRateAngle < -180.0) yawRateAngle += 360.0; eulerYawDesired = -yawRateAngle; } // 250HZ if (++attitudeCounter >= ATTITUDE_UPDATE_RATE_DIVIDER) { sensfusion6UpdateQ(gyro.x, gyro.y, gyro.z, acc.x, acc.y, acc.z, FUSION_UPDATE_DT); sensfusion6GetEulerRPY(&eulerRollActual, &eulerPitchActual, &eulerYawActual); accWZ = sensfusion6GetAccZWithoutGravity(acc.x, acc.y, acc.z); accMAG = (acc.x*acc.x) + (acc.y*acc.y) + (acc.z*acc.z); // Estimate speed from acc (drifts) vSpeed += deadband(accWZ, vAccDeadband) * FUSION_UPDATE_DT; // Adjust yaw if configured to do so stabilizerYawModeUpdate(); controllerCorrectAttitudePID(eulerRollActual, eulerPitchActual, eulerYawActual, eulerRollDesired, eulerPitchDesired, -eulerYawDesired, &rollRateDesired, &pitchRateDesired, &yawRateDesired); attitudeCounter = 0; /* Call out after performing attitude updates, if any functions would like to use the calculated values. */ stabilizerPostAttitudeUpdateCallOut(); } // 100HZ if (imuHasBarometer() && (++altHoldCounter >= ALTHOLD_UPDATE_RATE_DIVIDER)) { stabilizerAltHoldUpdate(); altHoldCounter = 0; } if (rollType == RATE) { rollRateDesired = eulerRollDesired; } if (pitchType == RATE) { pitchRateDesired = eulerPitchDesired; } // TODO: Investigate possibility to subtract gyro drift. controllerCorrectRatePID(gyro.x, -gyro.y, gyro.z, rollRateDesired, pitchRateDesired, yawRateDesired); controllerGetActuatorOutput(&actuatorRoll, &actuatorPitch, &actuatorYaw); if (!altHold || !imuHasBarometer()) { // Use thrust from controller if not in altitude hold mode commanderGetThrust(&actuatorThrust); } else { // Added so thrust can be set to 0 while in altitude hold mode after disconnect commanderWatchdog(); } /* Call out before performing thrust updates, if any functions would like to influence the thrust. */ stabilizerPreThrustUpdateCallOut(); if (actuatorThrust > 0) {#if defined(TUNE_ROLL) distributePower(actuatorThrust, actuatorRoll, 0, 0);#elif defined(TUNE_PITCH) distributePower(actuatorThrust, 0, actuatorPitch, 0);#elif defined(TUNE_YAW) distributePower(actuatorThrust, 0, 0, -actuatorYaw);#else distributePower(actuatorThrust, actuatorRoll, actuatorPitch, -actuatorYaw);#endif } else { distributePower(0, 0, 0, 0); controllerResetAllPID(); // Reset the calculated YAW angle for rate control yawRateAngle = eulerYawActual; } } }}static void stabilizerPreAltHoldComputeThrustCallOut(void){ /* Code that shall run BEFORE each altHold thrust computation, should be placed here. */#if defined(SITAW_ENABLED) /*
0 0
- CrazyFlie源码学习2-Stabilizer任务
- CrazyFlie源码学习1-姿态解算
- Crazyflie微型四轴 深入解读2
- spark1.2源码学习之任务调度1
- TBSchedule源码学习笔记-任务处理
- 任务2学习感悟
- 嵌入式材料 crazyflie材料
- Crazyflie 2.0 System Architecture
- crazyflie控制算法
- crazyflie 功能包安装
- Hadoop-2.4.1学习之Map任务源码分析(上)
- Hadoop-2.4.1学习之Map任务源码分析(下)
- WPF学习开发客户端软件-任务助手(已上传源码)
- spark源码学习(七);task任务的提交分析
- TBSchedule源码学习笔记-线程组任务调度
- Voltage Stabilizer – Protect Your Home Appliances
- (Orbit-stabilizer theorem) 的简单证明
- 优达学城 深度学习 任务2
- android开发人员收藏网站
- 【Android】各个版本发布
- Atom插件go-plus的离线安装
- OC基础之字典,集合,字符串
- 推荐系统学习之概率算法及其增量算法
- CrazyFlie源码学习2-Stabilizer任务
- android适配
- LLVM
- java_67---67,68没有看,pass
- CompletableFuture(二)
- 二维LIS Gym100820G Racing Gems
- P25 (*) Generate a random permutation of the elements of a list.
- [Leetcode] 98. Validate Binary Search Tree @python
- 模版方法模式