在单一四旋翼导航代码中的简单数值错误。

huangapple go评论111阅读模式
英文:

Simple ValueError in a single quadrotor navigation code

问题

我遇到了一个简单的四旋翼代码的新手错误。我读到的错误是"ValueError: not enough values to unpack (expected 5, got 4)",出现在以下这行代码:

  1. States[0:6], Thrust_calc, z_accel, x_accel, y_accel = quadrotor(States, S_desired[6:11], Thrust)

我将代码分成了两个文件。相关的代码行如下所示:

  1. for j in range(N):
  2. x_vel_desired = (final_x_coordinate - States[6]) / (50 * dt)
  3. x_accel_desired = 0
  4. y_vel_desired = (final_y_coordinate - States[7]) / (50 * dt)
  5. y_accel_desired = 0
  6. S_desired[0], S_desired[1], S_desired[2] = final_x_coordinate, x_vel_desired, x_accel_desired
  7. S_desired[3], S_desired[4], S_desired[5] = final_y_coordinate, y_vel_desired, y_accel_desired
  8. # 期望的角度
  9. # Theta
  10. S_desired[6] = angle_objective(S_desired[0:3], States[6], States[9], States[0], Thrust, Kxp1, Kxd1)
  11. # Phi
  12. S_desired[7] = angle_objective(S_desired[3:7], States[7], States[10], States[1], Thrust, Kyp1, Kyd1)
  13. # 无人机高度位置、速度和加速度
  14. # 获取四旋翼的状态
  15. States[0:6], Thrust_calc, z_accel, x_accel, y_accel = quadrotor(States, S_desired[6:11], Thrust)
  16. # 推力的增量平滑
  17. if Thrust_calc - Thrust > 0.05:
  18. Thrust = Thrust_calc + 0.05
  19. elif Thrust - Thrust_calc > 0.05:
  20. Thrust = Thrust_calc - 0.05
  21. # 获取X_POS和X_VEL
  22. States[9], States[6] = EulerIntegration(x_accel, States[9], States[6])
  23. States[10], States[7] = EulerIntegration(y_accel, States[10], States[7])

另一个文件是:

  1. def quadrotor(States, desired_states, Thrust):
  2. inputs = [0] * 4
  3. # desired_states = list(map(int, desired_states))
  4. # PID参数
  5. Kp, Ki, Kd = 4.05, 0, 20.64
  6. Torque = [0] * 4
  7. # PID控制器。滚转 = 0
  8. err_phi = desired_states[1] - States[1]
  9. Torque[1] = (err_phi * Kp + err_phi * Ki * dt - States[4] * Kd * dt) * I[0, 0]
  10. # PID控制器。俯仰 = 0
  11. err_theta = desired_states[0] - States[0]
  12. Torque[2] = (err_theta * Kp + err_theta * Ki * dt - States[3] * Kd * dt) * I[1, 1]
  13. # PID控制器。偏航 = 0
  14. err_yaw = desired_states[2] - States[2]
  15. Torque[3] = (err_yaw * Kp + err_yaw * Ki * dt - States[5] * Kd * dt) * I[2, 2]
  16. # PID控制器。高度误差 = 0
  17. err_height = desired_states[3] - States[8]
  18. Torque[0] = err_height * Kp + err_height * Ki * dt - States[8] * Kd * dt + (m * g) / (math.cos(States[1]) * math.cos(States[0]))
  19. if Torque[0] > 8:
  20. Torque[0] = 8
  21. elif Torque[0] < 3:
  22. Torque[0] = 3
  23. # 输入
  24. inputs[0] = 1 / (4 * k) * Torque[0] - 1 / (2 * k * L) * Torque[2] - 1 / (4 * b) * Torque[3]
  25. inputs[1] = 1 / (4 * k) * Torque[0] - 1 / (2 * k * L) * Torque[1] + 1 / (4 * b) * Torque[3]
  26. inputs[2] = 1 / (4 * k) * Torque[0] + 1 / (2 * k * L) * Torque[2] - 1 / (4 * b) * Torque[3]
  27. inputs[3] = 1 / (4 * k) * Torque[0] + 1 / (2 * k * L) * Torque[1] + 1 / (4 * b) * Torque[3]
  28. phi_acel = Torque[1] / I[0, 0]
  29. theta_acel = Torque[2] / I[1, 1]
  30. psi_acel = Torque[3] / I[2, 2]
  31. theta_vel, theta = EulerIntegration(theta_acel, States[3], States[0])
  32. phi_vel, phi = EulerIntegration(phi_acel, States[4], States[1])
  33. psi_vel, psi = EulerIntegration(psi_acel, States[5], States[2])
  34. z_accel = -g + (math.cos(theta) * math.cos(phi)) * Torque[0] / m
  35. x_accel = (math.sin(psi) * math.sin(phi) + math.cos(psi) * math.sin(theta) * math.cos(phi)) * Torque[0] / m
  36. results = [theta, phi, psi, theta_vel, phi_vel, psi_vel]
  37. return results, Torque[0], z_accel, x_accel

完整的代码可以在这里找到。有人可以帮助我吗?

英文:

I'm having a newbie error with a simple piece of code of a flying quadrotor. The error I read is "ValueError: not enough values to unpack (expected 5, got 4) on line:

  1. States[0:6], Thrust_calc, z_accel, x_accel, y_accel= quadrotor(States,S_desired[6:11],Thrust)

I have the code divided in two files. The involved lines are coded are shown next:

  1. for j in range(N):
  2. x_vel_desired = (final_x_coordinate - States[6])/(50*dt)
  3. x_accel_desired = 0
  4. y_vel_desired = (final_y_coordinate - States[7])/(50*dt)
  5. y_accel_desired = 0
  6. S_desired[0], S_desired[1], S_desired[2] = final_x_coordinate,x_vel_desired,x_accel_desired
  7. S_desired[3], S_desired[4], S_desired[5] = final_y_coordinate,y_vel_desired,y_accel_desired
  8. #DESIRED ANGLE
  9. #Theta
  10. S_desired[6] = angle_objective(S_desired[0:3],States[6],States[9],States[0],Thrust,Kxp1,Kxd1)
  11. #Phi
  12. S_desired[7] = angle_objective(S_desired[3:7],States[7],States[10],States[1],Thrust,Kyp1,Kyd1)
  13. #DRONE height position, velocity and acceleration
  14. #OBTAINING OF THE STATES OF THE QUADROTOR
  15. States[0:6], Thrust_calc, z_accel, x_accel, y_accel= quadrotor(States,S_desired[6:11],Thrust)
  16. #the increment of the thrust is smooth
  17. if Thrust_calc-Thrust&gt;0.05:
  18. Thrust=Thrust_calc+0.05
  19. elif Thrust-Thrust_calc&gt;0.05:
  20. Thrust=Thrust_calc-0.05
  21. #OBTAINTION OF X_POS AND X_VEL
  22. States[9],States[6] = EulerIntegration(x_accel,States[9],States[6])
  23. States[10],States[7] = EulerIntegration(y_accel,States[10],States[7])

and the other file is:

  1. def quadrotor(States, desired_states, Thrust):
  2. inputs=[0]*4
  3. #desired_states=list(map(int, desired_states))
  4. #PID Values
  5. Kp, Ki, Kd = 4.05, 0, 20.64
  6. Torque=[0]*4
  7. #pid controller. Roll = 0
  8. err_phi=desired_states[1]-States[1]
  9. Torque[1]=(err_phi*Kp + err_phi*Ki*dt - States[4]*Kd*dt )* I[0,0]
  10. #PID Controller. Pitch = 0
  11. err_theta=desired_states[0]-States[0]
  12. Torque[2]=(err_theta*Kp + err_theta*Ki*dt - States[3]*Kd*dt) * I[1,1]
  13. #PID Controller. Yaw = 0
  14. err_yaw=desired_states[2]-States[2]
  15. Torque[3]=(err_yaw*Kp + err_yaw*Ki*dt - States[5]*Kd*dt ) * I[2,2]
  16. #PID Controller. Height error = 0
  17. err_height=desired_states[3]-States[8]
  18. Torque[0]=err_height*Kp + err_height*Ki*dt - States[8]*Kd*dt + (m*g)/(math.cos(States[1])*math.cos(States[0]))
  19. if Torque[0]&gt;8:
  20. Torque[0]=8
  21. elif Torque[0]&lt;3:
  22. Torque[0]=3
  23. #inputs
  24. inputs[0]= 1/(4*k)*Torque[0] - 1/(2*k*L)*Torque[2] - 1/(4*b)*Torque[3]
  25. inputs[1]= 1/(4*k)*Torque[0] - 1/(2*k*L)*Torque[1] + 1/(4*b)*Torque[3]
  26. inputs[2]= 1/(4*k)*Torque[0] + 1/(2*k*L)*Torque[2] - 1/(4*b)*Torque[3]
  27. inputs[3]= 1/(4*k)*Torque[0] + 1/(2*k*L)*Torque[1] + 1/(4*b)*Torque[3]
  28. phi_acel= Torque[1]/I[0,0]
  29. theta_acel= Torque[2]/I[1,1]
  30. psi_acel= Torque[3]/I[2,2]
  31. theta_vel, theta = EulerIntegration(theta_acel,States[3],States[0])
  32. phi_vel, phi = EulerIntegration(phi_acel,States[4],States[1])
  33. psi_vel, psi = EulerIntegration(psi_acel,States[5],States[2])
  34. z_accel= -g + (math.cos(theta)*math.cos(phi))*Torque[0]/m
  35. x_accel=(math.sin(psi)*math.sin(phi)+math.cos(psi)*math.sin(theta)*math.cos(phi))*Torque[0]/m
  36. results= [theta, phi, psi, theta_vel, phi_vel, psi_vel]
  37. return results, Torque[0], z_accel, x_accel

Whole code is published here. Can anyone help me, please?

答案1

得分: 0

"OK,我最后看到我必须定义'y_accel'并将其包括在变量的'return'行中"

英文:

OK, I saw finally that I have to define "y_accel" and include it in the "return" line of variables

huangapple
  • 本文由 发表于 2023年7月13日 17:36:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76677946.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定