Viewing blog entries in category: #MakeWithMaxim

  • vali andrei
    Introduction
    For this contest I looked forward into designing and building my own quadcopter. The design features the MAX32630FTHR board, mmWave Sensor from TI for distance measurments, BMP280 barometric sensor, Raspberry PI 3 with NoIR camera and RFM12B for wireless control.

    BOM
    - 1xMAX32630FTHR
    - 1xIWR1443 mmWave Sensor - yet to arrive
    - 1xBMP280 - Pressure Sensor Evaluation Board from Adafruit - yet to arrive
    - 1xRaspberry PI 3
    - 1xNoIR camera for RPi
    - 2xRFM12B transceiver module
    - 1xArduinoNano
    - 4xBSS138
    - 8xLED's
    - 2xCapacitors
    - 10xResistors
    - 2.54mm Header Pins
    - 2xPrototyping board
    - 4xVibration Absorption bolts
    - 1xF450 DJI frame kit
    - 4xBrushless Motors
    - 4xSN20A Mini ESC's from RTFQUADS w/ BLHeli
    - 1x4S 3000mAh Turnigy Battery
    - 1xLM2594 eval. board
    Schematics


    Instructions
    So this project should be something like this: the MAX32630 the brain of the Quadcopter, controlling the motors through the ESC's based on the PID algorithm that sets the individual speeds for each motor. The remote control powered by an arduino nano connected to an RFM12B transceiver module sends to the MAX32630 the Setpoint for the PID algorithm. RFM12B boards connect via SPI the Nano and the MAX32630. Connected to the MAX board should be an mmWave sensor from TI, IWR1443 for distance measurments to obstacles in front of the Quadcopter. A barometer from Bosch should allow me to keep the Quadcopter at the same altitude.
    On top of this setup an Raspberry Pi 3 will have connected a NoIR camera, with IR LED's (winter nights are quite long). The RPi will stream the images from the camera to the laptop or the the iOS or the Android app, BerryCam. The camera will also be attached to a custom camera gimball driven by 2 servo's controlled by the RPi in such a way to create a beautiful panorama or just to move around.
    LED's on the bottom of the Quad will make it look nicer in the night.
    To power this setup, I'll use the 4S battery from Turnigy. Of course, I cannot supply directly the 2 boards so I'm using an evaluation board with an LM2594, buck-converter, even though in the future I'll move to a smaller solution.
    To check the battery level, all cells are connected to a diff op amp that outputs a logic high when one voltage cell is lower than a certain threshold.

    19221716_1454954687904112_2792996295191565316_o.jpg

    For the software part, I am writing from scratch the control algorithms and sensor communications (except for the BMI160 which has a great library and RFM12B which I had to make a few modifications as the arduino library for RFM12 is a bit different).

    As you can see in this image things did not go as planned. This is the second pair of propellers that I ruin. No one was hurt during the destruction of the propellers...except a small part of my forearm that felt the power of a propeller when spinning at about 85% of power...
    Yes, the PID algorithm was badly configured...twice...
    The RFM12B module is operating on 3.3V, but the arduino is 5V. Took me a pair of modules to figure that out...
    Now I have two other modules, with proper level shifting, done with BSS138 MOSFET's and 10k resistors.

    The SW also writes to an SD card various information for later visualization or for debugging purposes.

    The Quadcopter's status at this moment is that it flies rather nicely with a nice PID algorithm. The entire computation of the roll and pitch angles takes about 750 microseconds and with this timing I think I can send OneShot125 signals to the ESC and stay in a loop of 1100 us. Currently I am sending 1-2ms signals at a rate of 250 HZ, that is every 4000 us.

    Video
    Unfortunately, due to the limited time I could not further advance with the development of this project. At this moment I am a final year student and I had to work extensively on my diploma project and prepare for the diploma exam in the last 2 months.

    Source Code
    Code (Text):
    1.  
    2. while(1)
    3.   {
    4.  
    5.   tmr.start(); //timer start.
    6.   timerS = tmr.read_us();
    7.  
    8. //***************************************************Angle Computation*************************************************************************
    9.  
    10.   imu.getGyroAccXYZandSensorTime(accData, gyroData, sensorTime, accConfig.range, gyroConfig.range);
    11.   imu.getTemperature(&imuTemperature);
    12.  
    13.   double dt = (double)(tmr.read_us() - timer) / 1000000; // Calculate delta time
    14.  
    15.   //No restriction
    16.   double roll  = atan(accData.yAxis.scaled / sqrt(accData.xAxis.scaled * accData.xAxis.scaled + accData.zAxis.scaled * accData.zAxis.scaled)) * RAD_TO_DEG;
    17.   double pitch = atan2(-accData.xAxis.scaled, accData.zAxis.scaled) * RAD_TO_DEG;
    18.  
    19.   // This fixes the transition problem when the accelerometer angle jumps between -180 and 180 degrees
    20.   if ((pitch < -90 && kalAngleY > 90) || (pitch > 90 && kalAngleY < -90)) {
    21.   kalmanY.setAngle(pitch);
    22.   kalAngleY = pitch;
    23.   }  
    24.   else
    25.   kalAngleY = kalmanY.getAngle(pitch, gyroData.yAxis.scaled, dt); // Calculate the angle using a Kalman filter*/
    26.   if (abs(kalAngleY) > 90)
    27.   gyroData.xAxis.scaled = -gyroData.xAxis.scaled; // Invert rate, so it fits the restriced accelerometer reading*/
    28.  
    29.   kalAngleX = kalmanX.getAngle(roll, gyroData.xAxis.scaled, dt); // Calculate the angle using a Kalman filter
    30.  
    31. //************************************************PID computation and Speeds of individual motors update*****************************************
    32. //************************************************X configuration of the Quadcopter******************************************************************
    33.  
    34.  RollCorrection = compute(0.0, roll);
    35.   PitchCorrection = compute(0.0, pitch);
    36.   thrF1 = DefaultSpeed + RollCorrection + PitchCorrection;
    37.   thrF2 = DefaultSpeed + RollCorrection - PitchCorrection;
    38.   thrB3 = DefaultSpeed - RollCorrection - PitchCorrection;
    39.   thrB4 = DefaultSpeed - RollCorrection + PitchCorrection;
    40.  
    41. //***********************************************************Limitation of the maximum and minimum speeds******************************************
    42.   if(thrF1 > 1800)
    43.   thrF1 = 1800;
    44.   if(thrF2 > 1800)
    45.   thrF2 = 1800;
    46.   if(thrB3 > 1800)
    47.   thrB3 = 1800;
    48.   if(thrB4 > 1800)
    49.   thrB4 = 1800;
    50.   if(thrF1 < 1200)
    51.   thrF1 = 1200;
    52.   if(thrF2 < 1200)
    53.   thrF2 = 1200;
    54.   if(thrB3 < 1200)
    55.   thrB3 = 1200;
    56.   if(thrB4 < 1200)
    57.   thrB4 = 1200;
    58.  
    59. //************************************************update esc's with new pulse widths************************************************
    60.   MotorF1.pulsewidth_us(thrF1);
    61.   MotorF2.pulsewidth_us(thrF2);
    62.   MotorB3.pulsewidth_us(thrB3);
    63.   MotorB4.pulsewidth_us(thrB4);
    64. //**********************************************make sure we stay in the 4000 us loop************************************************
    65. timerE = tmr.read_us();  
    66.   while(tmr.read_us() < 4000){
    67.   wait_us(1);
    68.   }
    69.  
    70.  
    71. /***********************************************PID functions***************************************************************************
    72. void PIDGains(double Kp, double Ki, double Kd)
    73. {
    74.   kp = Kp;
    75.   ki = Ki;
    76.   kd = Kd;
    77. }  
    78.  
    79. //*****************************************************************************
    80. int compute(double Setpoint, double Input)  //input is the gyro; setpoint is 0 when self leveling or stick position from RFM
    81. {
    82.   PIDerror = Setpoint - Input;
    83.   Pout = PIDerror * kp;
    84.   Iout = Iout_prev + (PIDerror * ki);
    85.   Dout = (PIDerror - prev_error) * kd;
    86.    
    87.   prev_error = PIDerror;
    88.    
    89.   PIDOutput = Pout + Iout + Dout;
    90.    
    91.   return PIDOutput;
    92. }
    93.  
    94. .