![]() ![]() Xdot = x + np.tan(x) * np.sin(x) * x + np.tan(x) * np.cos(x) * x # total force and moment acting on quadcopter in inertial frame # calculate motor-mixer scalar coefficients # calculate aerodynamic pitching, rolling, and yawing moments # confirm electric motor torque isn't exceeding limit Qe = (Kt / resistanceMotor) * (bigOmegasTarget - x) / Kv # calculate induced power, profile power, and rotor aerodynamic torque for each rotor # converge iterated induced velocity and calculated induced velocity VPrime = np.sqrt(UVWp ** 2 + UVWp ** 2 + (UVWp - vi) ** 2) # omega = rotation about positive z-axisĭef Derivative6DOF(x,dt,bigOmegasTarget,batterySOC,m,g,I,Cd0,pitch,rho,a,b,c,R,viGuessInitial,posProps,A,maxCapacity,powerDrawComponents,Kv,Kt,voltMax,resistanceMotor,PeMax,Jp,processNoise,theta0,theta1): # dischargeRate - discharge rate of battery # percentRemaining - percent battery charge remaining # omegadot4 - angular acceleration of back left rotor # omegadot3 - angular acceleration of front right rotor # omegadot2 - angular acceleration of back right rotor # omegadot1 - angular acceleration of front left rotor # omega4 - angular speed of back left rotor # omega3 - angular speed of front right rotor # omega2 - angular speed of back right rotor # omega1 - angular speed of front left rotor # rdot - angular acceleration about z-axis # qdot - angular acceleration about x-axis # pdot - angular acceleration about y-axis # maxBatteryPower = maxCapacity*voltMax/1000 # (Whr) Max possible power from battery at start # totalPowerDraw - total power load on battery from all components (motors, camera, electronics, etc.) # powerDrawMotors - sum of all power draw from all 4 motors # M - sum of all moments acting on vehicle # F - sum of all forces acting on vehicle # Maero - aerodynamic pitching, rolling and yawing moments = ' # Qe - electric motor torque (desired motor torque) # QeMax - max electric motor torque possible # Qp - rotor aerodynamic torque (current motor torque) # vPrime - effective speed of flow at the rotor # UVWp - translational velocity at each propeller = ' # DCM - rotation matrix from body frame to inertial frame # Jp - inertia about each motor (includes propellor and motor) # powerDrawComponents - power drawn by components from battery ![]() # posProps - position of propellers from center of gravity = ' # viGuessInitial - guess induced velocity # Cd0 - Profile drag coefficient of each rotor # g - gravitational acceleration constant # batterySOC - percent battery charge remaining # bigOmegasTarget - commanded rotor speeds = ' Thank you!ĭerivative6DOF.py # Derivative6DOF Variables I understand there is a lot of code so if anyone could help me with making my python derivative code perform more similarly to MATLAB that would be greatly appreciated! If you have any questions feel free to ask. I profiled my python code and it says that this function accounts for 76% of the run time (It doesn't take up nearly as much percent-wise in MATLAB). ![]() The big culprit I believe is my derivative function. Both produce correct results albeit different due to stochasticity. To run my script in Python takes 113 seconds meanwhile it takes 7 seconds in MATLAB. I'm much more comfortable in Matlab however I've been required to convert my code from Matlab to Python. I'm sorry for my ignorance in using NumPy and python. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |