Full text
Project of an attitude control system for nanosatellites Master’s thesis Author: Bablon, Olivier Mentor: Gonz`alez Diez, David Master’s degree in Space and Aeronautical Engineering Deliverable for the 22th June 2021
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Abstract This paper describes the study and design of a 1 DoF attitude control system for a 1U CubeSat based on reaction wheel with the aim of implementing it on a PCB along with a magnetorquers system. This thesis takes place in the frame of the PLATHON project which aims to develop a simulation platform for optical communications between nanosatellites by regrouping many students and teacher from the Polytechnical University of Catalonia (UPC). To do this, a complete state of the art presents the features of nanosatellites and the existing technology to control the attitude of a CubeSat. Then, the method used for reading and controlling the attitude of a CubeSat is explained. To be more precise, the principle of operation of two Inertial Measurement Unit (IMU) is shown to understand how the attitude can be red. Along with this, the controlling program of the reaction wheel system is detailed to have an overview of the different functions required to impose a certain positioning to the CubeSat. The design of the hardware components of the project is then presented. Most of the pieces have been drawn under Solidworks software and manufactured by a 3D printer. Finally, the result of some experiments made at the university laboratory with an air bearing system are presented. Those results are discussed and highlight the different problems encountered over the project. 1
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 2
Declaration on Honour I declare that, the work in this Degree Thesis is completely my own work, no part of this Degree Thesis is taken from other people’s work without giving them credit, all references have been clearly cited, I’m authorised to make use of the research group TIEG and PLATHON related information I’m providing in this document. I understand that an infringement of this declaration leaves me subject to the foreseen disciplinary actions by The Polytechnical University of Catalonia - BarcelonaTECH. Olivier Bablon 22/06/2021 Name of the Student Signature Date Thesis title: Project of an attitude control system for nanosatellites
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 4
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Contents 1 Introduction 10 1.1 Aim........................................... 10 1.2 Scope.......................................... 10 1.3 Requirements...................................... 11 1.4 Justification ...................................... 11 2 State of the art 14 2.1 CubeSat ........................................ 14 2.1.1 CubeSatdescription .............................. 14 2.1.2 History of the CubeSat . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.1.3 Classification of satellites . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.2 Cubesatsubsystems .................................. 17 2.2.1 Attitude Determination Control System (ADCS) . . . . . . . . . . . . . . . 17 2.2.2 Electrical Power Subsystem (EPS) . . . . . . . . . . . . . . . . . . . . . . 19 2.2.3 Communication Subsystem (COMMS) . . . . . . . . . . . . . . . . . . . . 20 2.2.4 On Board Computer (OBC) . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.3 Microcontrollers and I2C communication . . . . . . . . . . . . . . . . . . . . . . . 21 2.3.1 Microprocessors ................................ 21 2.3.2 I2CBus .................................... 22 2.4 PLATHONProject................................... 23 3 Description of the attitude reading method and controlling program 27 3.1 Description of the attitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.1.1 Eulerangles .................................. 27 3.1.2 Quaternions .................................. 28 3.2 STM32Bluepill.................................... 29 3.3 Inertial Measurement Unit (IMU) . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.3.1 Accelerometer ................................. 31 3.3.2 Gyroscope ................................... 32 3.3.3 ModuleGY-521 ................................ 32 3.3.4 ModuleBNO055................................ 35 3.4 Software design and implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 38 3.4.1 General description of the final program schematic . . . . . . . . . . . . . . 38 3.4.2 Functions and variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4 Hardware design 50 4.1 Theoreticalpart .................................... 50 4.2 CAOpart........................................ 52 4.2.1 DCMotor ................................... 52 4.2.2 SPARKFUN Qwiic motor driver . . . . . . . . . . . . . . . . . . . . . . . . 55 5
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 4.2.3 Reactionwheel................................. 55 4.2.4 Fixation of the motor to the PCB . . . . . . . . . . . . . . . . . . . . . . . 57 4.2.5 FinalPCB ................................... 60 5 Results of the experiments 63 5.1 Tests with the air bearing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.1.1 MODE1:READIMU............................. 65 5.1.2 MODE 2: MOTOR ON OFF . . . . . . . . . . . . . . . . . . . . . . . . . 66 5.1.3 MODE 3: COARSE POSITIONING . . . . . . . . . . . . . . . . . . . . . . 67 5.1.4 MODE 4: FINE POSITIONING ONLY . . . . . . . . . . . . . . . . . . . . 69 6 Budget 72 6.1 Cost of hardware components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 6.2 Costofsoftwaretools ................................. 73 6.3 Totalcostoftheproject................................ 73 7 Environmental impact 75 8 Conclusion 77 8.1 Summaryofthetesis ................................. 77 8.2 Futureprojects..................................... 78 A Control program variables 82 B General flowchart of the controlling program 87 C Detailed flowchart of the fine positioning function 89 D Detailed flowchart of the coarse positioning function 91 E MPU6050 Datasheet 95 F DC Motor RF-300EA Datasheet 107 G Final control program - Arudino code 109 6
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE List of Tables 1 General requirements for a CubeSat . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2 Classification of satellite by mass and cost . . . . . . . . . . . . . . . . . . . . . . 17 3 Features comparison between Arduino UNO and STM32 Blue pill . . . . . . . . . . 29 4 Description of the functions of the controlling code . . . . . . . . . . . . . . . . . . 48 5 Sizing parameter for the reaction wheel . . . . . . . . . . . . . . . . . . . . . . . . 50 6 ComponentsofthePCB................................ 60 7 MODE READ IMU - Features of Test 1 . . . . . . . . . . . . . . . . . . . . . . . 65 8 MODE READ IMU - Features of Test 2 . . . . . . . . . . . . . . . . . . . . . . . . 65 9 MODE READ IMU - Features of Test 3 . . . . . . . . . . . . . . . . . . . . . . . 65 10 MODE MOTOR ON OFF - Features of Test 1,2 and 3 . . . . . . . . . . . . . . . 66 11 MODE COARSE POSITIONING - Features of Test 1,2 and 3 . . . . . . . . . . . . 68 12 MODE FINE POSITIONING - Features of Test 1 and 2 . . . . . . . . . . . . . . . 69 13 Electronic components budget . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 14 PCB manufacturing budget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 15 Softwarelicencesbudget................................ 73 16 Totalbudget...................................... 73 17 Environmentalwaste.................................. 75 18 Variable and definitions of the controlling code . . . . . . . . . . . . . . . . . . . . 86 List of Figures Figure 1 CubeSat ³Cat-1 designed in UPC NanoSat Laboratory . . . . . . . . . . . . 12 Figure 2 Image of a Poly Picosatellite Orbital Deployer . . . . . . . . . . . . . . . . . 15 Figure 3 CubeSats launched per year depending on the organization . . . . . . . . . . 16 Figure 4 ADCS subsystem diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Figure 5 Apollo missions Inertial Measurement Unit . . . . . . . . . . . . . . . . . . . 18 Figure 6 EPS Subsystem diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Figure 7 Microprocessor Intel 4004 . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Figure 8 Typical I2C bus communication circuit . . . . . . . . . . . . . . . . . . . . . 22 Figure 9 I2C communication protocol . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Figure 10 Representation of Euler angles . . . . . . . . . . . . . . . . . . . . . . . . . 27 Figure 11 STM32 Blue pill pinout and pin function description . . . . . . . . . . . . . 30 Figure 12 Representation of the MEMS accelerometer . . . . . . . . . . . . . . . . . . 31 Figure 13 Representation of the MEMS Gyroscope . . . . . . . . . . . . . . . . . . . . 32 Figure 14 Connection of the module GY-521 . . . . . . . . . . . . . . . . . . . . . . . 33 Figure 15 Connection of the module BNO055 . . . . . . . . . . . . . . . . . . . . . . 35 Figure 16 Control program main goals . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Figure17 Timerclockgraph ............................... 39 Figure 18 General flowchart of the controlling program . . . . . . . . . . . . . . . . . . 40 Figure 19 Rotation of Cubesat with coarse positioning . . . . . . . . . . . . . . . . . . 41 7
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 2 State of the art In this chapter, a description and an historical background of CubeSats are presented in order to have a deeper comprehension of the rest of the report. The subsystems of a CubeSat are also descirbed to have a global view of the subject. Then the different existing attitude control systems are discussed to justify which one is used in PLATHON project. Finally, a summarized report of what has already been done within the PLATHON project is made to show the systems and innovations that are still missing in this one. 2.1 CubeSat 2.1.1 CubeSat description CubeSat is a technical specification for miniature satellites that are the size of a 10 cm cube. The CubeSat specification generate several requirements that have to be respected in order to insure the safety and functionality of the system. The main general requirements can be found in Table 1. [1] Requirement ID Description 1.1 All parts shall remain attached to the CubeSats during launch, ejection and operation. No additional space debris will be created. 1.2 No pyrotechnics shall be permitted. 1.3 Any propulsion systems shall be designed, integrated, and tested in accordance with AFSPCMAN 91-710 Volume 3. 1.4 Propulsion systems shall have at least 3 inhibits to activation. 1.5 Total stored chemical energy will not exceed 100 Watt-Hours. 1.6 CubeSat hazardous materials shall conform to AFSPCMAN 91- 710, Volume 3. 1.7 CubeSat materials shall satisfy the following low out-gassing criterion to prevent contamination of other spacecraft during integration, testing, and launch. 1.7.1 CubeSats materials shall have a Total Mass Loss (TML) <1.0 % 1.7.2 CubeSat materials shall have a Collected Volatile Condensable Material (CVCM) <0.1 % 1.8 The CubeSat shall be designed to accommodate ascent venting per ventable volume/area <2000 inches. Table 1: General requirements for a CubeSat 14
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 2.1.2 History of the CubeSat The CubeSat standard was developed by Bob Twiggs of Standford University and Jordi Puig-Sari of California Polytechnic State University in 1999. Their goal was to design a satellite that was free of important financial and time constraints so that the students could work on it. The great innovation by the time was also to create satellites compatible with the Poly-Picosatellite Orbital Deployer (P-POD) which is a launch interface that can carry between one and three nanosatellites totaling less than 5 kg and 10 cm x 10 cm x 33 cm in size. Knowing that the unit size of a CubeSat is 10 cm x 10 cm x 11 cm (also called 1U CubeSat), the P-POD can carry a 3U CubeSat. Figure 2: Image of a Poly Picosatellite Orbital Deployer The first CubeSats were launched in June 2003 with Eurockot Launch Services in Russia. A triple CubeSat called QuakeSat developed with Stanford students by Quakefinder was launched to determine if they could observe low frequency electromagnetic radiation in areas prior to an earthquake. [2] Nine years later, more than a hundred CubeSats had been sent in orbit, representing a panel of 80 institutions and 24 different countries. It includes universities, national space agencies, private companies, and amateur organizations. According to Nanosats Database [3], the part of CubeSats launched every year is mainly dominated by private companies that can send satellites with lower costs. The second main actors are universities that drives research projects with their students. 15
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 3: CubeSats launched per year depending on the organization With this growing interest, Cubesats experiments have taken a major place in the space field, as technologies continue to evolve in support of miniaturization, and interest in space is reignited with each success. CubeSat demand and popularity among universities, governments, students and other users have at this point overwhelmed conventional launch resources. This is partly attributable to heightened interest from government agencies and private industry but also to the huge amount of research and educational projects for which a low cost CubeSat platform is ideal. 2.1.3 Classification of satellites Small satellites have been around for over half a century, but interest in this area is growing now more than ever. Since the size of a satellite corresponds directly to expenses associated with physical materials, labor for development and launch vehicle fuel, it is natural to conclude that the principal advantages of small satellites over bigger satellites are lower cost and shorter development time. [4] We can now see in the aerospace industry landscape, the development of more and more miniaturized satellites. This miniaturization has led to the creation of different type of small satellites that can be classified by their mass as seen in the Table 2. [5] 16
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Class Cost ($) Mass (kg) Large satellite 0.1-2 Billion >1000 Medium satellite 50-100 M 500-1000 Mini-satellite 10-50 M 100-500 Micro-satellite 2-10 M 10-100 Nano-satellite 0.2-2 M 1-10 Pico-satellite 20-200 k <1 Femto-satellite 0.1-20 k <0.1 Table 2: Classification of satellite by mass and cost 2.2 Cubesat subsystems 2.2.1 Attitude Determination Control System (ADCS) The Attitude Determination and Control System (ADCS) is the subsystem in charge of stabilizing the Cubesat and orientating it in desired directions despite the external perturbances acting on it. This requires that the Cubesat determine its attitude using sensors and control it using actuators. [6] The ADCS is generally divided into 4 modules that have the following objectives: •The Sensors System (SENS) is composed of a set of sensors. The goal of this module is to recover inertial data in order to get information about the Cubesat position. •The Actuators System (ACT) goal is to position the Cubesat in the target attitude by rotating around the 3 axis (Yaw, Pitch and Roll). •The Controller (CTRL) compute the attitude of the Cubesat with the data from the Sensors system and the target attitude in order to determine the rotation that must be accomplished around each axis. •The Interface (INT) module has for objective to ensure good connection with other systems of the satellite and to send data to the other systems. It’s the hardware part of the ADCS subsystem as it transmits the signal received from the sensors to the microcontroller and share power supply coming from the EPS subsystem to the actuators. The figure 4 illustrates the relations between the different modules of the ADCS subsystem. 17
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 4: ADCS subsystem diagram The sensors for reading the orientation of a Cubesat are also called Inertial Measurement Unit (IMU). The history of IMU began in the 1930s when the aircraft navigation started to expand. At that time, IMU was reserved to big applications due to his constraints in size, cost and power consumption. Indeed, it wasn’t still needed for smaller devices such as phones. [7] Figure 5: Apollo missions Inertial Measurement Unit It’s just recently that electromechanical systems was introduced to the industry with the great advantages of being cheap, compact and with low electric consumption. The market for IMU has 18
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE expanded a lot and nowadays the competition is quite hard in this sector. Many companies such as Invensense, Honeywell, STMicroelectronics, Mircostrain or X-sens participate in this industry. This has lead to a great variety of devices. Now we can find very precise and efficient sensors but also very low cost systems. Reaction wheels are a very efficient solution for any satellites that wish to control the attitude of this one. They are in increasing demand because they provide great maneuverability and precision. Reactions wheels are using the conservation of the angular momentum to cause a rotation of the spacecraft. When the speed of the motor connected to the wheel changes, the spacecraft starts to counter-rotate proportionately to the torque imposed by the reaction wheel. It controls a satellite’s attitude with very high precision, which is critical for applications that require excellent pointing accuracy, such as for Earth Observation purposes, or to keep a telescope fixed towards a particular region of interest. 2.2.2 Electrical Power Subsystem (EPS) The main role of the Electrical Power Subsystem (EPS) is to supply the others systems of the Cubesat with appropriate electrical power. This power is generally harvested from solar panels that produce electricity when they are exposed to sunlight or indirect radiations. It also needs batteries to store the energy when the Cubesat passes through the shadow of the Earth. The collected and sorted power is then redistributed to the different subsystems of the Cubesat. The EPS also has secondary functions such as measuring and transferring internal parameters about voltages, currents and temperatures. It’s also generally used to measure the temperature of the external faces of the Cubesat. [6] The following figure 6 shows the simplified process of the EPS. 19
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 6: EPS Subsystem diagram 2.2.3 Communication Subsystem (COMMS) The communication subsystem main goal is to transmit the data from the Cubesat to the ground station. The COMMS is composed of the telemetry and command systems which respectively send and receive data. Data collected by the sensors or the payload of the Cubesat are relayed to ground station with the telemetry system that is composed of a transmitter. This data is recovered by the sensors and convert into 8-bit binary numbers by the microcontroller in order to be send with the satellite’s antenna. The message is intercepted on ground by a radio operating generally in ultrahigh frequency (UHF) band. [6] The other important point for the communication subsystem is to receive commands from the ground station. All incoming signals from the ground station will be compared to all other inputs, and any errant signals are discarded. [8] 2.2.4 On Board Computer (OBC) The On Board Computer (OBC) is the main component for data transfer and acts as the embedded computer responsible for communications between all the other subsystems. It is dedicated to command and data handling (C&DH). Different parameters such as temperature or power comsuption are constantly stored in the OBC memory module and sent to the ground station via telemetry. The OBC also receive commands from the ground station. It decodes those commands and executes 20
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE them by commanding the other subsystems to achieve the desired action. [9] The OBC also uses the data from ADCS sensors to determine the attitude of the Cubesat and control the ADCS actuators and control this attitude. The OBC is composed of both hardware and software components. The OBC is the central piece of the Cubesat as it’s related to all the other subsystems. [6] 2.3 Microcontrollers and I2C communication 2.3.1 Microprocessors The first microprocessor was invented in 1971 by the company Intel (Integrated Electronics) which was founded by Gordan Moore, Robert Noyce and Andrew Grove. The first microprocessor, called the Intel 4004, was running at a clock speed of 108 KHz. This has lead to a 1st generation of microprocessors that weren’t very powerful but found applications in controlling devices. Figure 7: Microprocessor Intel 4004 Then, Intel 8008 was the first microprocessor of the 2nd generation of microprocessors. It was invented in 1972. Those microprocessors that were 8-bit processors were also used for controlling devices as they weren’t good enough for performing arithmetic calculations. The 3rd generation of microprocessors appeared around 1978 when Intel released the first 16-bit microprocessor: the Intel 8086. This processor became quite popular not only for controlling devices but also performing important calculations as the speed of those microprocessors was four times better than the ones from the 2nd generation. The 4th generation of microprocessors came in the early 80’s with the Intel 80386 microprocessor which was the first 32-bit processor. This one became very popular because it was used as a CPU 21
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE for many computers as it was a quite powerful processor that allowed to do complex algorithmic calculations. One processor that can be mentionned in this 4th generation is the Intel 80586, also named Pentium processor, because it was extremely fast in executing instructions. It had a clock frequency of 1.5 GHz and was rated for 1500 Million instructions per second. The 5th generation extend itself from 1995 to nowadays and has been bringing very high-performance processors that are 64-bit processors. [10] 2.3.2 I2C Bus The I2C Bus, also called Inter Integrated Circuit, was developed by Philipps Semiconductor at the beginning of the 80’s to connect easily a microprocessor to the various circuits of a modern televisor. The goal of an I2C Bus is to create a communication between different electronic components with only 3 wires: •The data line: SDA •The clock line: SCL •The electric mass This is a serial link, which means that the transfer speed will be lower than with a parallel bus. The I²C bus allows exchanges at a speed of 100 kbits per second. [11] The I2C communication bus is very popular and broadly used by many electronic devices because it can be easily implemented in many electronic designs which require communication between a master and one or multiple slaves. The implementation of the communication is quite easy as it requires only the two wires of the data line and the clock line. Figure 8: Typical I2C bus communication circuit A I2C bus allows a communication for up to 128 devices when using 7-bit addressing and up to 1024 devices when using 10-bit addressing. Each device has a unique address so the master can choose with which device it will be communicating. 22
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE The data signal is transferred with sequences of 8 bit. After a special start condition appears, the first 8 bit sequence occurs and indicate the address of the slave to which the data must be communicated. After a 8 bit sequence, there is a bit called Acknowledge. After this, in most of the case, a special internal address of the slave device is sent. Then follow as many 8 bit sequences as required to transmit the necessary data. Figure 9: I2C communication protocol The start condition appears when the data line goes low while the clock line is still high. After this, the clock starts and each data bit is transferred during each clock pulse. The eighth bit of the first sequence indicates whether the master will write to the salve or read from the slave. Then the data is transmitted and after the stop condition occurs when when the data line goes high while the clock line is high. [12] 2.4 PLATHON Project To successfully address the development of missions with nanosatellite clusters, it is essential to have tools that integrate orbital propagation, command and telemetry transmission between the nanosatellite and the ground station and the operational status of the satellites. In missions where nanosatellites are to be communication nodes, it is also necessary to integrate the communication network model. The applications that constitute the satellite’s mission goals can be validated by simulating the behavior of all the hardware that surrounds it and emulating the flight conditions (position, inclination, velocity, etc.). This form of software validation is called Software-in-the-Loop (SiTL). A more advanced step to ensure the success of the missions is to include the verification of the vehicle hardware operation and its correct use by the applications developing the mission. This aspect is covered when the actual hardware can be incorporated into the application development 23
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 11: STM32 Blue pill pinout and pin function description 3.3 Inertial Measurement Unit (IMU) To deduce the attitude of a CubeSat, an Inertial Measurement Unit (IMU) is generally used. It is an electronic device that measures and reports orientation, velocity, and gravitational forces with different types of sensors. In general, we distinguish five types of sensors that can give data about the Euler angles. These are detailed in the list below : GYROSCOPES - Gyroscopes are composed of spinning wheels in the axis on which the rotation is to be measured. As they are relative attitude sensors, they require a known initial value and inaccurate measurements can drift to a significant error. MAGNETOMETERS - Magnetometers sense magnetic field strengths and direction. The measurements are compared to the Earth’s magnetic field map (which is dependent on the spacecraft position) to determine the attitude. Moreover, it can only be used at low altitude orbits, where the magnetic field is strong enough. SUN SENSORS - Sun sensors sense the direction of the Sun, commonly based on some solar cells and shades that can determine the Sun’s position. 30
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE HORIZON SCANNERS - Horizon scanners are optical instruments that determine the ’limb’ of the Earth’s atmosphere often using thermal infrared sensing. STAR TRACKERS - Star trackers are also optical instruments that determine the position of stars using cameras or photocells. The attitude is determined relative to the position of the surrounding detected stars. The two mains instruments that you can find in an IMU are the gyroscope and the accelerometer. A magnetometer is also optionally add to increase the precision of the IMU. The addition of a magnetometer and filtering algorithms to determine orientation information can also be known as a device called Attitude and Heading Reference Systems (AHRS). [21] 3.3.1 Accelerometer The accelerometer can be find in various types such as mechanical accelerometers, quartz accelerometers, and Micro-Electro-Mechanical Systems (MEMS) accelerometers. In an electronic IMU, the accelerometer used is a MEMS. A MEMS accelerometer senses acceleration by measuring change in capacitance. It is a microstructure which has a mass attached to a screen. The mass is confined to move along one direction and between fixed outer plates as you can see on the following figure : Figure 12: Representation of the MEMS accelerometer When an acceleration in a particular direction is applied, the mass moves and the capacitance between the fixed plates changes. This changes is electrically measured and processed to get a raw value of acceleration. [22] 31
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 3.3.2 Gyroscope The most common gyroscope that everybody knows is a spinning wheel composed by a rotor and a spin axis. Nowadays, many different types of gyroscopes do exist, and they can use other operating principles. Today, the main types of gyroscopes used are : •Ring-laser gyroscopes •Fiber-optic gyroscopes •Fluid gyroscopes •Vibration gyroscopes The gyroscope measures angular rate using the Coriolis effect. When a mass is moving in a particular direction with a particular velocity, an external angular rate is applied. A force that cause perpendicular displacement of the mass occures. In Figure 13, the mass is moving in the direction of the blue arrow ~vand having an angular rate ~ Ωzaround the Z axis. Then we can see that the force of Coriolis represented by the orange arrow appears in the direction of Y axis . Figure 13: Representation of the MEMS Gyroscope The principle is the same than with the accelerometer. The displacement caused by the appearance of the Coriolis force will conduct to a change in electric capacitance. This one is measured to get a raw value of angular rate. [22] 3.3.3 Module GY-521 The module GY-521 is a breakout board of the MPU-6050 module. The module GY-521 is composed of an accelerometer, a gyroscope, a Digital Motion Processor (DMP) and a temperature 32
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE sensor. The DMP is used to process complex algorithms directly on the IMU. It allows to turn raw values from the sensor to more stable position data. The communication between this module and the Arduino microprocessor is made via an I2C bus. The connection is realized with 4 cables. First, the IMU must get power supply. The alimentation must be between 3.3V and 5V. In Figure 14, it is shown that the VCC pins is connected to the 3.3V pin of the microcontroller. The ground of the IMU must also be connected to the ground of the microcontroller. Then, the I2C communication requires two connections. The SCL pin corresponds to the clock line where the signal of the clock is transmitting and the SDA pin corresponds to the data line where the required data is transmitted. The SCL correspond to the pin B6 and the SDA corresponds to the pin B7 on the microcontroller. Figure 14: Connection of the module GY-521 The recovery of data from the GY-521 is made with a code. This code is written under the Arduino IDE and uploaded on the STM32 Blue pill. An arduino code is generally separated in two part: •The setup function which is a function that his run just once at the beginning when you launch the program. This one is generally used to initialize the code and sets the initial values. •The loop function which is the function that is run consecutively without interruption. This one is generally the heart of the code because it makes the program change and respond. The code for programming the GY-521 can be divided in 3 parts. The first part is the introduction of the libraries and variables. 33
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE The Wire library is used to communicate with the GY-521 module via I2C bus. The integer MPU represents the physical adress of the module GY-521. Different variables are then initialize to recover the raw values of the accelerometer and the gyroscope around the three axis X, Y and Z. The second part of the code is the set up function. In this part, the transmission is being established with the given address to transmit a first value that corresponds to 0 in order to reset the IMU. Then the transmission is ended and the data rate required is being set. The last part of the code is the loop function. 34
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE The same process of resetting the IMU is done every time we want to get data from it. Then the Wire.requestFrom() function is used to request 12 bytes of data from the IMU. This data is then read with the Wire.read() function. The Serial.print() function is used to show the data in the serial monitor. A delay of 333 ms is imposed at the end before a the loop function start again. The results of the lecture of the GY-521 is then show in the serial monitor. The values that appears are raw values. The accelerometer produces data in units of acceleration and the gyroscope reports the rate of rotation around each axis which is in degrees per second. [23] 3.3.4 Module BNO055 The module BNO-055 is another type of IMU that has a better sensibility than the module GY-521 seen previously. This is mainly due to the fact that it includes a magnetometer. Indeed, this device include 3 sensors: a tri-axial accelerometer, a tri-axial gyroscope, a geomagnetic sensor and a temperature sensor. The module uses I2C bus to communicate with microcontroller. The connection of this device is also realized with 4 cables. The IMU must get a voltage that is between 2.4V and 3.6V so the VCC pin is connected to the 3.3V pin of the microcontroller. The ground of the device is also connected to the ground of the microprocessor to have a close circuit. The I2C communication requires the same connection as with the module GY-521. The SCL (clock line) pin is connected to the pin B6 and the SDA (data line) is connected to the B7 pin of the microcontroller. Figure 15: Connection of the module BNO055 The data of the IMU is then extracted with an arduino code. The program can also be divided in 3 parts. 35
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE The first part introduce the libraries needed and the global parameters and objects required for the code. The Wire library is used to communicate with the device via I2C bus. The two Adafruit libraries are specific to the BNO-055 module. They are used to read more easily the data from the device. The utility and math libraries are used to make some inertial and mathematics calculations. The sample rate of the sensor is defined to be 100 ms which means that we want to get data from the IMU every 100 ms. An IMU object is created to collect data from the sensor. The second part of the program is the set up function that is run just once when the program is launched. The first line set baud rate speed which represents how fast the data is sent through the USB connection. The begin() function start the device and then a delay of 1 second is imposed to let time to the sensor to wake up correctly. The third part is the loop function that is repeated constantly when the program is launched. 36
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE The first line is used to get a vector of 4 components from the IMU. Those 4 components corresponds to the 4 variables that compose a quaternion. The result is then printed in the serial monitor with the Serial.print() function. The selected delay is imposed before getting the next iteration of the loop. The values that appears in the monitor are the components of the quaternions. Those values can be used to transform the quaternion into Euler angles. 37
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 3.4 Software design and implementation 3.4.1 General description of the final program schematic The final program for controlling the attitude of the Cubesat is quite complex as it requires to do many actions at the same time. The main step of it are shown in the following figure. Figure 16: Control program main goals Those goals can be achieved with only one program because only one program can be run at once with the microcontroller. Thus, it requires to do multiple actions at the same time as we want to continuously know the orientation of the Cubesat while knowing if the user wants to change the position of this one. To do that, it is used the timer function included in the Arduino environment. To be more precise, a timer is a piece of hardware built inside the Arduino controller. It is basically a clock that can be used to measure time events. With a timer, it’s also possible to implement interruptions. A program downloaded on a controller is normally running sequentially instructions by instructions. An interrupt is an external event that interrupts the running program and runs a special Interrupt Service Routine (ISR). After this ISR is finished, the program continues with the next instruction. The Figure 17 illustrates the operation of the timer clock. The last clock line shows a timer with an overflow of 4 which means that every 4 pulsations the ISR is triggered. This is equivalent to having a clock line with a prescale factor of 4 (and so a frequency of 0.25 Hz). It is important to notice that the timer clock is a different clock from the main clock of the microcontroller. 38
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 17: Timer clock graph When it comes to controlling the motor, the program can be decomposed into 2 different modes. The first mode is the coarse positioning and the second mode is the fine positioning. The code processing begins with functions that ask the user to choose between two options. The first one is to enter in a positioning mode which means that the user wants to change the position of the Cubesat by acting on the motor speed and direction. The second option is a waiting mode where the user just want to keep reading Euler angles from the IMU. If the user choose the positioning mode, then the program decides either to enter in the coarse positioning or the fine positioning depend. 39
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 3.4.2 Functions and variables As told previously, the main method to execute those different modes on the same Arduino microcontroller is to use functions with the timer method. The functions are written out of the setup or the void loops and they can be called at any moment with timers. There is a total of 12 functions that are related to different parts of the program. Those parts are basically: •Reading the OBC (On Board Computer) which is to collect the information transmitted by the user with the Serial1 Input. •Setting the motor parameter such as the direction and the speed when the user wants to change direction. •Reading the data collected from the IMU to have the orientation of the Cubesat in real time. •Executing the different modes of positioning depending on what position the user wants to reach. The different functions used in the code for doing those different actions can be seen in the following Table 4. The code also requires a lot of variables and definition that are used to stock different types of data. The list of all the global variables that are used in the program can be seen in the annex. 46
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Name Description Input Output Ambit OBC mode receive() Get mode from OBC None, but gets mode from User Serial1 input None, but saves OBC mode value OBC readings OBC data receive() Get data from OBC None, but gets mode from User Serial1 input None, but saves OBC data value OBC readings set impulse() Set the motor at a fixed direction and speed RW direction, New RW speed None, but saves RW speed Motor settings generate ramp() Creates a ramp RW direction, Acc ramp time reach, RW ramp speed reach, Acc Dec state - Motor settings read IMU() Read data from the IMU None None, but saves IMU variables, pitch, roll and yaw IMU reading show IMU() Show data from the IMU on the Serial1 monitor None None IMU reading read show IMU() Read then show data from the IMU None None, but saves IMU variables, pitch, roll and yaw IMU reading computePID() Compute the PID and updates the motor speed and direction None None, but saves PID values Fine Positioning (PID) mode Select() Decides the mode to execute depending on the mode read mode value None, but exits to selected mode Modes mode IMU reading() Test purpose function to read and show IMU values constantly None None, but saves IMU values Modes mode OBC Input Wait() Default mode, waits for a mode input from OBC None None, but exits to mode Select() Modes 47
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE mode Positioning RW()Waits for a data input from OBC and decides the positioning type (coarse or fine) None None, but exits to suitable positioning type Modes positioning Coarse() Executes a coarse pointing control (ramps and waiting) None None, but exits to positioning Fine() or mode Select() Modes positioning Fine() Executes a fine pointing control (PID) None None, but exits to mode Select() Modes Table 4: Description of the functions of the controlling code 48
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 49
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 4 Hardware design There are two majors limitations in designing the size of a reaction wheel for a CubeSat : the size and the weight. In our case, we know that the reaction wheel must have a maximum diameter of 95 millimeter in order to fit on the Printed Circuit Board (PCB). 4.1 Theoretical part The reaction wheels have been designed with a thin disk in the center and a ring along the periphery where most of the mass is placed. This is useful to reduce the global mass of the reaction wheel but still have an efficient torque. In this way, the design parameter of the reaction wheel can be decomposed between the disk and the ring. The Table 5 regroups the different sizing parameter chosen for the reaction wheel. Those parameters are used to do some inertial calculations. The choice of the values have been made knowing the limitations imposed by the PCB design. Parameter Acronym Value Disk radius rdisk (mm)60 Ring radius rring (mm)80 Disk height hdisk (mm)2.50 Ring height hring (mm)7.50 Table 5: Sizing parameter for the reaction wheel Those values allows us to do some inertial calculations about the reaction wheel to know if it will have the desired impact on the Cubesat attitude. The following calculations are estimations as the reaction wheel will not be a full disk but will have some holes to reduce it mass. Knowing the different sizing parameter of the reaction wheel, we can deduce the mass of both disk and ring. [24] The following formula gives the mass of the disk: mdisk =ρπr2 diskhdisk (6) where ρis the density of the material of the reaction wheel. As the reaction wheel will be printed with a 3D printer, the material chosen is plastic PLA (ρ=1240 kg/m3) because it is the most common material for a 3D printing. Then the mass of the disk can be calculated: mdisk =1240 ×π×0.0602×0.0025 mdisk =0.035 kg 50
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE The mass of the ring is also gave by the following formula: mring =ρπ(r2 ring −r2 disk)hring (7) mring =1240 ×π×(0.0802−0.0602)×0.0075 mring =0.082 kg The total mass of the reaction wheel is found by adding the mass of both ring and disk: mTOTAL =mdisk +mring mTOTAL =0.117 kg Knowing that the chosen motor weight approximately 0.022 kg, the total weight of the wheel-motor system is 0.139 kg. With the previous design parameters, we can deduce the inertial parameters of the reaction wheel. The inertial momentum of the reaction wheel is also decomposed between the inertial momentum of the disk and the inertial momentum of the ring. The inertial momentum of the disk is given by the following equation: Idisk =mdiskr2 disk 2 Idisk =0.035 ×0.0602 2 Idisk =6.3×10−5kg.m2 The inertial momentum of the ring is given by the following equation: Iring =mring(r2 disk +r2 ring) 2 Iring =0.082 ×(0.0802+0.0602) 2 Iring =4.1×10−4kg.m2 It produces a total inertia for the reaction wheel of: ITOTAL =Idisk +Iring ITOTAL =4.73 ×10−4kg.m2 The selected motor is a DC motor with a the reference RF-300EA-1D390. By looking on the datasheet of this motor that can be found in the annex, we find a maximum wheel speed of 3520 rpm. The maximum angular momentum of the reaction wheel can be found with the following formula: hmax =ITOTAL ×ωmotor 51
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Where ωmotor is the maximum wheel speed of the motor. It gives us a result of: hmax =4.73 ×10−4×3520 × 2π 360 hmax =0.029 N.m 4.2 CAO part 4.2.1 DC Motor The chosen motor is a brushed Direct Current (DC) motor. A simple DC motor can be illustrated as below. Figure 23: Representation of a DC motor The battery supplies a current-carrying conductor, also called the armature, with electricity. This armature is basically a coil of wire that produces an electric field when a current flows through it. This armature is placed inside a magnetic field so that when the motor is activated, the magnetic field and the electric field interacts. This create a torque that makes the armature turning. The direction of rotation of the motor is given by Fleming left hand rule. It is a memo-technique to remember in which direction is the force induced by an electromagnetic field. If the middle finger is the sense of current and the index finger is the direction of the magnetic field, then the thumb is direction of the force. The electricity flows doesn’t go directly to the armature, it passes first through a brush and then through the commutator which is circular metal piece that is red and blue on the Figure 23. This commutator allows the flow of electricity to be reversed midway during every full rotation. Every half rotation, the current enter in the red or the blue part of the commutator which changes direction the current flow direction inside the armature. This allows to create the torque in the right direction at the right moment during every rotation. 52
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE The chosen motor has the reference RF-300EA-1D390. All the relatives technical information about this one can be found on the datasheet in the annex. The motor has been drawn under SOLIDWORKS with all its quotations. The blueprint of the motor with all the quotations can be found in the following figure. 53
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 24: Blueprint of the DC motor via Solidworks 54
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 4.2.2 SPARKFUN Qwiic motor driver The Qwiic motor driver is used to pass the command from the arduino microprocessor to the motor. A motor driver is something that makes the motor move as per the given instructions. It listens to the low voltage from the microprocessor and control the motor which needs high input voltage. In simple words, a motor driver controls the direction and the speed of the motor based on the commands it receives from the controller. Microprocessor operate on low level of voltage unlike the motor that operate on higher voltage. The Qwiic motor driver can drive two different motors and is designed to communicate via I2C bus. It operates from 3V to 11V with an absolute maximum of 12V. [25] 4.2.3 Reaction wheel The reaction wheel has been designed in a way to fit on the PCB. The reaction wheel will be placed on the bottom part of the board in order to have more space and create a wheel big enough to have a sufficient torque. The reaction wheel should be fixed to the axis of the motor with 2 screws. This operation is quite complex as the axis of the motor is very small and has a very thin diameter. We could connect the motor to the reaction wheel by inserting the motor shaft into the central hole of the reaction wheel. But the problem is that it requires a very accurate printing which is not available at the university laboratory. Moreover, this type of connection can lead to a lot of vibration when the motor is running at high speed. Those vibrations must be minimize at maximum because they may damage other components of the PCB and distort the desired results when controlling the attitude. The reaction wheel has been drawn under SOLIDWORKS with all its quotations. The blueprint of the reaction wheel with all the quotations can be found in the following figure. 55
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 62
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 5 Results of the experiments 5.1 Tests with the air bearing The following tests have been made in UPC’s laboratory with an air bearing. An air bearing is a system where a very thin air film separates two surfaces in order to avoid any frictions. In UPC laboratory, the air bearing is used for floating a bowl without having any rubs just as a CubeSat would be in space. The air is put under pressure by an air compressor and then sent through tubes until they reach the exit holes. There is two type of air bearing output piece at UPC’s laboratory: one with large holes and one with very small holes as it can be seen in Figure 31. Figure 31: Air bearing empty with two different type of holes The CubeSat itself is stuck inside the bowl as it can be seen on Figure 32. The bowl can also be closed by another semi-sphere to create a ball. Figure 32: Air bearing with a CubeSat at UPC’s laboratory This system allows us to experiment different cases of study to see the problems or limitations of our control program. The tests have mainly been drive during the last day before submitting this 63
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE report, which means that most of the problem encountered couldn’t have been resolved for lack of time. The goal of those experiment is to test the 4 modes of the controlling program which are: •READ IMU: The goal of is the mode is too check that the values of the IMU are coherent. •MOTOR ON OFF: This mode is just a test to see if the motor respond to a specific impulse. The motor is triggered or stopped when the user want. •COARSE POSITIONING: This mode is the coarse positioning function that is used to reach an angle that is superior to 5°. The coarse positioning can end in a fine positioning in the desired angle is not exactly reached. •FINE POSITIONING: This mode is the fine positioning function that is used to reach an angle smaller than 5°. Each one of these mode have been tested to see how the program would respond and how the inertia of the motor and the reaction wheel could affect the results. To have different case study, twelve tests have been realized in the laboratory. Those tests have been realized with a PCB that doesn’t have the magnetorquer components as we wanted just to test the reaction wheel system. The PCB used can be seen in Figure 33. Figure 33: PCB used for the testing The most important tests for each mode are presented in the following. 64
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 5.1.1 MODE 1: READ IMU Three tests have been run with this mode. The features of each test are presented in the following tables. TEST 1 Mode Size of air bearing Desired turn angle READ IMU only Small air bearing holes - Table 7: MODE READ IMU - Features of Test 1 The first test was made for testing only the reading of the IMU data to see if the values are coherent and if the IMU reacts well when the CubeSat turns. The test showed a problem as the CubeSat was turning without giving any specific impulse to the motor. The CubeSat’s weight was approximately equilibrated so the problem couldn’t come from this. We deduced that the air bearing might be broken as an hole of the outputn piece seemed to be blocked. We decided to change it and do the rest of the tests with large holes air bearing. TEST 2 Mode Size of air bearing Desired turn angle READ IMU only Large air bearing holes - Table 8: MODE READ IMU - Features of Test 2 The second test shows us that the problem was still there but the CubeSat was turning less quickly than with the previous test. The CubeSat had to be stopped with the hand. TEST 3 Mode Size of air bearing Desired turn angle READ IMU only Large air bearing holes - Table 9: MODE READ IMU - Features of Test 3 The third test has shown that even when the air bearing is started slowly, a little impulse is given to the CubeSat and the problem is still there as it can be seen in Figure 34. We deduced that the problem should come from the distribution of the weight inside the CubeSat that isn’t perfect. 65
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 34: Evolution of yaw, pitch and roll for READ IMU mode 5.1.2 MODE 2: MOTOR ON OFF Three tests have been run with this mode. The goal of this mode is to test the motor and the reaction wheel and to see how the system reacts to a specific impulse. The features of each test are presented in the following tables. In this mode, the user can send a value to the Serial1 monitor to start the motor or send another value to stop it. Mode Size of air bearing Desired turn angle MOTOR ON OFF Large air bearing holes - Table 10: MODE MOTOR ON OFF - Features of Test 1,2 and 3 The three tests can be resumed in one table for this mode as we used the same features for each test. In those tests, we just turn the motor on and then we turn it off to see if the CubeSat stays still and how the system reacts. The observation is that when the motor is turned off the CubeSat starts to rotate in the opposite sense as it was turning before. For example, if the CubeSat was turning in a counter clockwise sense, when the motor is turned off the CubeSat starts turning in a clockwise sense. This occurence can be seen in Figure 36, the yaw angle decreases after the stop of the motor. The deduction from this observation is that the CubeSat wants to compensate the angular momentum of the reaction wheel that has stopped suddenly. 66
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 35: Evolution of yaw, pitch and roll for MOTOR ON OFF mode Figure 36: Evolution of the acceleration along x and y for MOTOR ON OFF mode 5.1.3 MODE 3: COARSE POSITIONING Three tests have also been run with this mode. The goal of this part is to reach a desired turn angle that would be superior to 5°. The features of each test are presented in the following Table 11. In this mode, the user send the desired in the Serial1 monitor. It is important ot notice that the coarse positioning can result in a fine positioning if the angle reach at the end is not precise enough. 67
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Mode Size of air bearing Desired turn angle COARSE POSITIONING Large air bearing holes 100° Table 11: MODE COARSE POSITIONING - Features of Test 1,2 and 3 The first test hasn’t shown great results has it didn’t turn like it should have for a coarse positioning. The second didn’t get good results too just like the first one. The observation made was that the values of the IMU weren’t good enough to get a good coarse positioning. The values of the IMU weren’t evolving coherently over the time which didn’t allow the program to know when it had to stop the acceleration ramp and start the waiting mode or the deceleration ramp. This problem is mainly due to the fact that when the IMU is used during a long time (few hours) it gets decalibrated and the values goes wrong especially when the CubeSat is turning fast. After a calibration of the IMU, the third test went better and the program did the acceleration ramp, the waiting mode and the deceleration ramp. After that, the program entered in the fine positioning mode as it can be seen in Figure 37. Figure 37: Evolution of yaw, pitch and roll for COARSE POSITIONING mode The tests have shown some problems that couldn’t be fixed because of a lack of time. The observation made was that the acceleration ramp stops almost when it started but the motor doesn’t stop its acceleration. Then the deceleration ramp is done too late which leads to a wrong final position of the CubeSat. The data from the IMU (Figure 38) shows that the acceleration is zero and the 68
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE speed is different to zero so the program considers that the acceleration has stopped right at the beginning while it hasn’t. This is mainly due to the fact that the IMU reading is not precise enough. Figure 38: Evolution of the acceleration along x and y for COARSE POSITIONING mode A solution to avoid this problem would be to get a more precise reading of the IMU by either adjusting the tolerance of this one, either changing sensors. Another solution would be to change this specific impulse by a defined ramp so that the program doesn’t need to read the IMU to know when the acceleration stops. 5.1.4 MODE 4: FINE POSITIONING ONLY Two tests have been run with fine positioning only. The goal of this part is to reach a desired turn angle that would be inferior to 5°.The features of each test are presented in the following Table 12. In this mode, the user enter the desired angle through the Serial1 monitor. Mode Size of air bearing Desired turn angle FINE POSITIONING only Large air bearing holes 4° Table 12: MODE FINE POSITIONING - Features of Test 1 and 2 The observation of the fine positioning mode has revealed some problems too. The first test showed that the motor didn’t turn at all which means that the impulse given might have been to small to get the reaction wheel turn. The second test showed that when we perturbate the Cubesat by giving it an initial movement, the program send an impulse sufficient enough to make the motor turns. 69
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Figure 39: Evolution of yaw, pitch and roll for FINE POSITIONING mode The other problem is that the PD controller does not stabilize to the desired setpoint. The figure 40 shows that the CubeSat keeps accelerating in both sense which means that it never reaches the desired angle. Figure 40: Evolution of the acceleration along x and y for FINE POSITIONING mode This is due to the fact that the values of the proportionnal gain Kpand derivative gain Kdhave not been studied because of a lack of time. Those values have to be find by doing many tests of the fine positioning which cannot be done within the allotted time. 70
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 71
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 8.2 Future projects This tesis was part of a first project of integration of reaction wheel in an attitude control system for a CubeSat. In parallel with this project, other tesis have been made to implement magnetorquers in the attitude control system. The first sketch of a PCB containing both magnetorquers and reaction wheel has occured at the end of this project. The project isn’t finished yet and a lot of improvements could be brought by future projects. First of all, we have seen that the controlling program for the reaction wheel system isn’t working good enough and requires some improvements to have a reliable functioning. This could also include using a better IMU sensor to improve the global quality of the system. The actual IMU requires a quite heavy calibration that has to be done The choice of the DC motor could also improve a lot the operation of the reaction wheel to get much more precise pointing. The second step could be to put in common the control program of magnetorquers and reaction wheel. Having a single program able to control the attitude over the 3 degrees of liberty could be interesting in order to have a simple and efficient way to change the orientation of the CubeSat at any time. Another problem that hasn’t been cited but that could be quite disturbing is the fact that the reaction wheel has a small precession due to the fact that it isn’t well fixed to the axis of the motor. Fixing the reaction wheel to this axis is quite complicated as the axis is very small in size and diameter so it is an important point to find a solution for this issue in the future. This would improve also the rotational motion of the reaction wheel and so the global pointing precision of the system. Another further improvement for this project would be to develop an interface to visualize in real time the data received from the IMU. This would help understand better the motion of the satellite for the user and understand any problem that could occurs when controlling the attitude of it. 78
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 79
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE References [1] S. Lee, A. Hutputanasin, A. Toorian, W. Lan, R. Munakata, J. Carnahan, D. Pignatelli, and A. Mehrparvar, “Cubesat design specification,” The CubeSat Program. [2] M. Swartwout, “The first one hundred cubesats: A statistical look,” JoSS, vol. 5, pp. 213–233, 2013. [3] https://www.nanosats.eu/, April 2021. Accessed on 2021/03/12. [4] W. A. Shiroma, L. K. Martin, J. M. Akagi, J. T. Akagi, B. L. Wolfe, B. A. Fewell, and A. T. Ohta, “Cubesats: A bright future for nanosatellites,” ResearchGate, March 2011. [5] S. Gao, M. U. K. Clark, J. Zackrisson, W. Shiroma, J. M. Akagi, K. Maynard, P. Garner, L. Boccia, G. Amendola, G. Massa, C. Underwood, M. Brenchley, M. Pointer, and M. Sweeting, “Antennas for modern small satellites,” 2009. [6] A. M. Rawls, “Cubesat general subsystem performance specification,” The Faculty of the Department of Aerospace Engineering San Jose State University, May 2014. [7] N. Ahmad, R. A. R. Ghazilla, and N. M. Khairi, “Reviews on various inertial measurement unit (imu) sensor applications,” International Journal of Signal Processing Systems, vol. 1, December 2013. [8] Y. A. I. Humad, A. TagElsir, and M. M. Daffalla, “Design and implementation of communication subsystem for israsat1 cube satellite prototype,” ResearchGate, January 2017. [9] L. T. LUMBWE, “Development of an onboard computer (obc) for a cubesat,” Cape Peninsula University of Technology, May 2013. [10] “History of the microprocessor.” https://meetingtomorrow.com/blog/ history-of-the-microprocessor/. Accessed on 2021/05/15. [11] S. Campbell, “Basics of the i2c communication protocol.” https://www.circuitbasics. com/basics-of-the-i2c-communication-protocol/. Accessed on 2021/03/17. [12] D. S. Patel, P. Talati, and S. Gandhi, “Design of i2c protocol,” International Journal of Technical Innovation in Modern Engineering & Science (IJTIMES), vol. 5, March 2019. [13] Javi, “Plataforma integrada de simulaci´on hardware in th loop para comunicaciones opticas en nanosat´elites,” June 2021. [14] A. Owen-Hill, “Robot euler angles: The essential primer.” https://robodk.com/blog/ robot-euler-angles/, April 2018. Accessed on 2021/03/13. [15] I. Bonev, “How is orientation in space represented with euler angles?.” https://www. mecademic.com/en/how-is-orientation-in-space-represented-with-euler-angles, July 2017. Accessed on 2021/04/08. 80
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE [16] R. Goldman, “Understanding quaternions,” Elsevier, March 2011. [17] A. Buchmann, “A brief history of quaternions and of the theory of holomorphic functions of quaternionic variables,” 2011. [18] BuildYourCNC, “3. how to set up the st-link v2 programmer tutorial for arm microcontrollers,” April 2015. Accessed on 2021/02/29. [19] “Introduction to the stm32 blue pill (stm32duino).” https://predictabledesigns.com/ introduction-stm32-blue-pill-stm32duino/. Accessed on 2021/04/02. [20] R. Watson, “How to program the stm32 blue pill with arduino ide.” https://maker.pro/ arduino/tutorial/how-to-program-the-stm32-blue-pill-with-arduino-ide, July 2019. Accessed on 2021/02/25. [21] “What is an imu.” https://www.vectornav.com/resources/what-is-an-imu, March 2020. Accessed on 2021/03/25. [22] H. to Mechatronics, “How mems accelerometer gyroscope magnetometer work & arduino tutorial,” November 2015. Accessed on 2021/03/22. [23] “Arduino drone v2.0 - full angle + filter.” https://electronoobs.com/eng_robotica_ tut9_code5.php. Accessed on 2021/03/02. [24] E. Oland and R. Schlanbusch, “Reaction wheel design for cubesats,” ResearchGate, June 2009. [25] “Sparkfun qwiic motor driver.” https://www.sparkfun.com/products/15451, September 2019. Accessed on 2021/04/02. 81
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE A Control program variables 82
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Name Description Type Units Ambit LEDPIN Integrated LED of the Bluepill #define - Bluepill configuration CS1 STM32 NCS Chip select (SPI mode only) pin #define - Bluepill configuration STM32 CLOCK Internal STM32 Clock #define kHz Bluepill configuration PI Number PI #define - Math values Rad to deg Convert radians to degrees #define - Math values Deg to rad Convert degrees to radians #define - Math values Final pointing tolerancy Tolerancy for final pointing #define Deg (º) Tolerancies Pointing mode tolerancy Tolerance for selecting pointing mode #define Deg (º) Tolerancies Accel Tolerance Tolerance for acceleration measurement #define m/s2Tolerancies Gyro Tolerance Tolerance for gyro measurement #define Deg/s Tolerancies DriverOne Driver Object definition SCMD - Object initiations IMU MPU Object definition MPU9250 - Object initiations IMU accel data X Values of local IMU accelerometer along X axis float m/s2IMU Values IMU accel data Y Values of local IMU accelerometer along Y axis float m/s2IMU Values IMU accel data Z Values of local IMU accelerometer along Z axis float m/s2IMU Values IMU gyro data X Values of local IMU gyroscope along X axis float Deg/s IMU Values IMU gyro data Y Values of local IMU gyroscope along Y axis float Deg/s IMU Values 83
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE IMU gyro data Z Values of local IMU gyroscope along Z axis float Deg/s IMU Values IMU mag data X Values of local IMU magnetometer along X axis float uT IMU Values IMU mag data Y Values of local IMU magnetometer along Y axis float uT IMU Values IMU mag data Z Values of local IMU magnetometer along Z axis float uT IMU Values Pitch deg Pitch angle float Deg (º) Orientation angles Roll deg Roll angle float Deg (º) Orientation angles Yaw deg Yaw angle float Deg (º) Orientation angles Accel total vector modulus Accelerometer total vector magnitude float m/s2Angles determination Accel pitch deg Accelerometer Pitch angle float Deg (º) Angles determination Accel roll deg Accelerometer Roll angle float Deg (º) Angles determination Gyro pitch deg Gyroscope Pitch angle float Deg (º) Angles determination Gyro roll deg Gyroscope Roll angle float Deg (º) Angles determination Gyro Accel sync Check if Gyroscope and Accelerometer are synchronized bool - Angles determination Mag X calc Calculated Magnetometer value along X axis float uT Angles determination Mag Y calc Calculated Magnetometer value along Y axis float uT Angles determination 84
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE Mag X corrected Corrected Magnetometer value along X axis float uT Angles determination Mag Y corrected Corrected Magnetometer value along Y axis float uT Angles determination Pitch rad Pitch angle float rad Angles determination Roll rad Roll angle float rad Angles determination RW speed Value of Reaction Wheel speed int - Motor values OBC mode value Value of mode sent by the On Board Computer int - OBC readings OBC data value Value of turn sent by the On Board Computer int Deg (º) OBC readings Stop State Check if an Emergency Stop is performed int Deg (º) OBC readings PID error Proportional error from PID double - Fine Positioning (PID) PID last error Previous proportional error from PID double - Fine Positioning (PID) PID cumulative error Cumulative (Integral) error from PID double - Fine Positioning (PID) PID rate error Rate (Derivative) error from PID double - Fine Positioning (PID) kp Proportional constant double - Fine Positioning (PID) ki Integral constant double - Fine Positioning (PID) 85
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE kd Derivative constant double - Fine Positioning (PID) Deg to reach Setpoint angle float Deg (º) Fine Positioning (PID) Zero state Check if PID encompass yaw of 0 degrees bool - Fine Positioning (PID) PID output Output value of the PID int bytes Fine Positioning (PID) RW direction Direction of the Reaction Wheel bool - (Inside functions) Motor settings New RW speed Speed to set on the Reaction Wheel int bytes (Inside functions) Motor settings Acc ramp time duration Duration of ramp int s (Inside functions) Motor settings RW ramp speed reach Final speed reached int bytes (Inside functions) Motor settings Acc Dec state Check wether in acceleration or deceleration state bool - (Inside functions) Motor settings dT Time step of each interrupt, calculated from Timer float s (Inside functions) IMU reading and Fine Positioning (PID) Table 18: Variable and definitions of the controlling code 86
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE B General flowchart of the controlling program 87
Start of waiting Is the Reaction Wheel rotating counterclockwise? No Compute the start of the deceleration angle (CubeSat rotates clockwise) Compute the start of the deceleration angle (CubeSat rotates counterclockwise) Read IMU Does the trajectory passes through the 0º angle? Does yaw angle increments? Yes Add a lap to yaw angle from IMU reading Yes Sustract a lap to yaw angle from IMU reading No Is Yaw angle from IMU reading bigger than the start of deceleration angle? Start of deceleration No No Read IMU Does the trajectory passes through the 0º angle? Does yaw angle increments? Yes Sustract a lap to yaw angle from IMU reading Yes Add a lap to yaw angle from IMU reading No Is Yaw angle from IMU reading smaller than the start of deceleration angle? No No Generate deceleration ramp Read IMU to get yaw angle after deceleration Calculate the total variation of angle (CubeSat rotates clockwise) Is the Reaction Wheel rotating counterclockwise? Yes Calculate the total variation of angle (CubeSat rotates counterclockwise) No Is the variation of angle negative? Add 360º to maintain positive value Yes Is the difference between the total variation angle and the total turn angle within the pointing tolerance? End of Coarse Pointing Yes Enter to OBC Waiting mode End of Coarse Pointing No Enter to Fine Pointing mode Yes
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE E MPU6050 Datasheet 95
InvenSense Inc. 1197 Borregas Ave, Sunnyvale, CA 94089 U.S.A. Tel: +1 (408) 988-7339 Fax: +1 (408) 988-8104 Website: www.invensense.com Document Number: PS-MPU-6000A-00 Revision: 3.4 Release Date: 08/19/2013 1 of 52 MPU-6000 and MPU-6050 Product Specification Revision 3.4
MPU-6000/MPU-6050 Product Specification Document Number: PS-MPU-6000A-00 Revision: 3.4 Release Date: 08/19/2013 2 of 52 CONTENTS 1 REVISION HISTORY ................................................................................................................................... 5 2 PURPOSE AND SCOPE ............................................................................................................................. 6 3 PRODUCT OVERVIEW ............................................................................................................................... 7 3.1 MPU-60X0 OVERVIEW ........................................................................................................................ 7 4 APPLICATIONS ........................................................................................................................................... 9 5 FEATURES ................................................................................................................................................ 10 5.1 GYROSCOPE FEATURES ..................................................................................................................... 10 5.2 ACCELEROMETER FEATURES ............................................................................................................. 10 5.3 ADDITIONAL FEATURES ...................................................................................................................... 10 5.4 MOTIONPROCESSING ......................................................................................................................... 11 5.5 CLOCKING ......................................................................................................................................... 11 6 ELECTRICAL CHARACTERISTICS ......................................................................................................... 12 6.1 GYROSCOPE SPECIFICATIONS ............................................................................................................ 12 6.2 ACCELEROMETER SPECIFICATIONS ..................................................................................................... 13 6.3 ELECTRICAL AND OTHER COMMON SPECIFICATIONS ............................................................................ 14 6.4 ELECTRICAL SPECIFICATIONS, CONTINUED ......................................................................................... 15 6.5 ELECTRICAL SPECIFICATIONS, CONTINUED ......................................................................................... 16 6.6 ELECTRICAL SPECIFICATIONS, CONTINUED ......................................................................................... 17 6.7 I2C TIMING CHARACTERIZATION.......................................................................................................... 18 6.8 SPI TIMING CHARACTERIZATION (MPU-6000 ONLY) ........................................................................... 19 6.9 ABSOLUTE MAXIMUM RATINGS ........................................................................................................... 20 7 APPLICATIONS INFORMATION .............................................................................................................. 21 7.1 PIN OUT AND SIGNAL DESCRIPTION .................................................................................................... 21 7.2 TYPICAL OPERATING CIRCUIT ............................................................................................................. 22 7.3 BILL OF MATERIALS FOR EXTERNAL COMPONENTS .............................................................................. 22 7.4 RECOMMENDED POWER-ON PROCEDURE ........................................................................................... 23 7.5 BLOCK DIAGRAM ............................................................................................................................... 24 7.6 OVERVIEW ........................................................................................................................................ 24 7.7 THREE-AXIS MEMS GYROSCOPE WITH 16-BIT ADCS AND SIGNAL CONDITIONING ................................ 25 7.8 THREE-AXIS MEMS ACCELEROMETER WITH 16-BIT ADCS AND SIGNAL CONDITIONING ........................ 25 7.9 DIGITAL MOTION PROCESSOR ............................................................................................................ 25 7.10 PRIMARY I2C AND SPI SERIAL COMMUNICATIONS INTERFACES ............................................................ 25 7.11 AUXILIARY I2C SERIAL INTERFACE ...................................................................................................... 26
MPU-6000/MPU-6050 Product Specification Document Number: PS-MPU-6000A-00 Revision: 3.4 Release Date: 08/19/2013 3 of 52 7.12 SELF-TEST ........................................................................................................................................ 27 7.13 MPU-60X0 SOLUTION FOR 9-AXIS SENSOR FUSION USING I2C INTERFACE .......................................... 28 7.14 MPU-6000 USING SPI INTERFACE ..................................................................................................... 29 7.15 INTERNAL CLOCK GENERATION .......................................................................................................... 30 7.16 SENSOR DATA REGISTERS ................................................................................................................. 30 7.17 FIFO ................................................................................................................................................ 30 7.18 INTERRUPTS ...................................................................................................................................... 30 7.19 DIGITAL-OUTPUT TEMPERATURE SENSOR .......................................................................................... 31 7.20 BIAS AND LDO .................................................................................................................................. 31 7.21 CHARGE PUMP .................................................................................................................................. 31 8 PROGRAMMABLE INTERRUPTS ............................................................................................................ 32 9 DIGITAL INTERFACE ............................................................................................................................... 33 9.1 I2C AND SPI (MPU-6000 ONLY) SERIAL INTERFACES .......................................................................... 33 9.2 I2C INTERFACE .................................................................................................................................. 33 9.3 I2C COMMUNICATIONS PROTOCOL ...................................................................................................... 33 9.4 I2C TERMS ........................................................................................................................................ 36 9.5 SPI INTERFACE (MPU-6000 ONLY) .................................................................................................... 37 10 SERIAL INTERFACE CONSIDERATIONS (MPU-6050) .......................................................................... 38 10.1 MPU-6050 SUPPORTED INTERFACES ................................................................................................. 38 10.2 LOGIC LEVELS ................................................................................................................................... 38 10.3 LOGIC LEVELS DIAGRAM FOR AUX_VDDIO = 0 .................................................................................. 39 11 ASSEMBLY ............................................................................................................................................... 40 11.1 ORIENTATION OF AXES ...................................................................................................................... 40 11.2 PACKAGE DIMENSIONS ...................................................................................................................... 41 11.3 PCB DESIGN GUIDELINES .................................................................................................................. 42 11.4 ASSEMBLY PRECAUTIONS .................................................................................................................. 43 11.5 STORAGE SPECIFICATIONS ................................................................................................................. 46 11.6 PACKAGE MARKING SPECIFICATION .................................................................................................... 46 11.7 TAPE & REEL SPECIFICATION ............................................................................................................. 47 11.8 LABEL ............................................................................................................................................... 48 11.9 PACKAGING ....................................................................................................................................... 49 11.10 REPRESENTATIVE SHIPPING CARTON LABEL ................................................................................... 50 12 RELIABILITY ............................................................................................................................................. 51 12.1 QUALIFICATION TEST POLICY ............................................................................................................. 51
MPU-6000/MPU-6050 Product Specification Document Number: PS-MPU-6000A-00 Revision: 3.4 Release Date: 08/19/2013 4 of 52 12.2 QUALIFICATION TEST PLAN ................................................................................................................ 51 13 ENVIRONMENTAL COMPLIANCE ........................................................................................................... 52
MPU-6000/MPU-6050 Product Specification Document Number: PS-MPU-6000A-00 Revision: 3.4 Release Date: 08/19/2013 5 of 52 1 Revision History Revision Date Revision Description 11/24/2010 1.0 Initial Release 05/19/2011 2.0 For Rev C parts. Clarified wording in sections (3.2, 5.1, 5.2, 6.1-6.4, 6.6, 6.9, 7, 7.1-7.6, 7.11, 7.12, 7.14, 8, 8.2-8.4, 10.3, 10.4, 11, 12.2) 07/28/2011 2.1 Edited supply current numbers for different modes (section 6.4) 08/05/2011 2.2 Unit of measure for accelerometer sensitivity changed from LSB/mg to LSB/g 10/12/2011 2.3 Updated accelerometer self test specifications in Table 6.2. Updated package dimensions (section 11.2). Updated PCB design guidelines (section 11.3) 10/18/2011 3.0 For Rev D parts. Updated accelerometer specifications in Table 6.2. Updated accelerometer specification note (sections 8.2, 8.3, & 8.4). Updated qualification test plan (section 12.2). 10/24/2011 3.1 Edits for clarity Changed operating voltage range to 2.375V-3.46V Added accelerometer Intelligence Function increment value of 1mg/LSB (Section 6.2) Updated absolute maximum rating for acceleration (any axis, unpowered) from 0.3ms to 0.2ms (Section 6.9) Modified absolute maximum rating for Latch-up to Level A and ±100mA (Section 6.9, 12.2) 11/16/2011 3.2 Updated self-test response specifications for Revision D parts dated with date code 1147 (YYWW) or later. Edits for clarity Added Gyro self-test (sections 5.1, 6.1, 7.6, 7.12) Added Min/Max limits to Accel self-test response (section 6.2) Updated Accelerometer low power mode operating currents (Section 6.3) Added gyro self test to block diagram (section 7.5) Updated packaging labels and descriptions (sections 11.8 & 11.9) 5/16/2012 3.3 Updated Gyro and Accelerometer self test information (sections 6.1, 6.2, 7.12) Updated latch-up information (Section 6.9) Updated programmable interrupts information (Section 8) Changed shipment information from maximum of 3 reels (15K units) per shipper box to 5 reels (25K units) per shipper box (Section 11.7) Updated packing shipping and label information (Sections 11.8, 11.9) Updated reliability references (Section 12.2) 8/19/2013 3.4 Updates section 4
MPU-6000/MPU-6050 Product Specification Document Number: PS-MPU-6000A-00 Revision: 3.4 Release Date: 08/19/2013 6 of 52 2 Purpose and Scope This product specification provides advanced information regarding the electrical specification and design related information for the MPU-6000™ and MPU-6050™ MotionTracking™ devices, collectively called the MPU-60X0™ or MPU™. Electrical characteristics are based upon design analysis and simulation results only. Specifications are subject to change without notice. Final specifications will be updated based upon characterization of production silicon. For references to register map and descriptions of individual registers, please refer to the MPU-6000/MPU-6050 Register Map and Register Descriptions document. The self-test response specifications provided in this document pertain to Revision D parts with date codes of 1147 (YYWW) or later. Please see Section 11.6 for package marking description details.
MPU-6000/MPU-6050 Product Specification Document Number: PS-MPU-6000A-00 Revision: 3.4 Release Date: 08/19/2013 7 of 52 3 Product Overview 3.1 MPU-60X0 Overview MotionInterface™ is becoming a “must-have” function being adopted by smartphone and tablet manufacturers due to the enormous value it adds to the end user experience. In smartphones, it finds use in applications such as gesture commands for applications and phone control, enhanced gaming, augmented reality, panoramic photo capture and viewing, and pedestrian and vehicle navigation. With its ability to precisely and accurately track user motions, MotionTracking technology can convert handsets and tablets into powerful 3D intelligent devices that can be used in applications ranging from health and fitness monitoring to location-based services. Key requirements for MotionInterface enabled devices are small package size, low power consumption, high accuracy and repeatability, high shock tolerance, and application specific performance programmability – all at a low consumer price point. The MPU-60X0 is the world’s first integrated 6-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, and a Digital Motion Processor™ (DMP) all in a small 4x4x0.9mm package. With its dedicated I2C sensor bus, it directly accepts inputs from an external 3-axis compass to provide a complete 9-axis MotionFusion™ output. The MPU-60X0 MotionTracking device, with its 6-axis integration, on-board MotionFusion™, and run-time calibration firmware, enables manufacturers to eliminate the costly and complex selection, qualification, and system level integration of discrete devices, guaranteeing optimal motion performance for consumers. The MPU-60X0 is also designed to interface with multiple noninertial digital sensors, such as pressure sensors, on its auxiliary I2C port. The MPU-60X0 is footprint compatible with the MPU-30X0 family. The MPU-60X0 features three 16-bit analog-to-digital converters (ADCs) for digitizing the gyroscope outputs and three 16-bit ADCs for digitizing the accelerometer outputs. For precision tracking of both fast and slow motions, the parts feature a user-programmable gyroscope full-scale range of ±250, ±500, ±1000, and ±2000°/sec (dps) and a user-programmable accelerometer full-scale range of ±2g, ±4g, ±8g, and ±16g. An on-chip 1024 Byte FIFO buffer helps lower system power consumption by allowing the system processor to read the sensor data in bursts and then enter a low-power mode as the MPU collects more data. With all the necessary on-chip processing and sensor components required to support many motion-based use cases, the MPU-60X0 uniquely enables low-power MotionInterface applications in portable applications with reduced processing requirements for the system processor. By providing an integrated MotionFusion output, the DMP in the MPU-60X0 offloads the intensive MotionProcessing computation requirements from the system processor, minimizing the need for frequent polling of the motion sensor output. Communication with all registers of the device is performed using either I2C at 400kHz or SPI at 1MHz (MPU-6000 only). For applications requiring faster communications, the sensor and interrupt registers may be read using SPI at 20MHz (MPU-6000 only). Additional features include an embedded temperature sensor and an on-chip oscillator with ±1% variation over the operating temperature range. By leveraging its patented and volume-proven Nasiri-Fabrication platform, which integrates MEMS wafers with companion CMOS electronics through wafer-level bonding, InvenSense has driven the MPU-60X0 package size down to a revolutionary footprint of 4x4x0.9mm (QFN), while providing the highest performance, lowest noise, and the lowest cost semiconductor packaging required for handheld consumer electronic devices. The part features a robust 10,000g shock tolerance, and has programmable low-pass filters for the gyroscopes, accelerometers, and the on-chip temperature sensor. For power supply flexibility, the MPU-60X0 operates from VDD power supply voltage range of 2.375V-3.46V. Additionally, the MPU-6050 provides a VLOGIC reference pin (in addition to its analog supply pin: VDD), which sets the logic levels of its I2C interface. The VLOGIC voltage may be 1.8V±5% or VDD. The MPU-6000 and MPU-6050 are identical, except that the MPU-6050 supports the I2C serial interface only, and has a separate VLOGIC reference pin. The MPU-6000 supports both I2C and SPI interfaces and has a single supply pin, VDD, which is both the device’s logic reference supply and the analog supply for the part. The table below outlines these differences:
MPU-6000/MPU-6050 Product Specification Document Number: PS-MPU-6000A-00 Revision: 3.4 Release Date: 08/19/2013 8 of 52 Primary Differences between MPU-6000 and MPU-6050 Part / Item MPU-6000 MPU-6050 VDD 2.375V-3.46V 2.375V-3.46V VLOGIC n/a 1.71V to VDD Serial Interfaces Supported I2C, SPI I2C Pin 8 /CS VLOGIC Pin 9 AD0/SDO AD0 Pin 23 SCL/SCLK SCL Pin 24 SDA/SDI SDA
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 34 35 SCMD DriverOne ; // D r i v e r Object d e f i n i t i o n 36 MPU9 25 0 IMU( SPI , CS1) ; // MPU o b j e c t d e f i n i t i o n 37 38 // GLOBAL VARIABLES 39 float IMU accel data X , IMU accel data Y , IMU accel data Z ; // Values o f l o c a l IMU accelerometer (m/ s ˆ2) 40 f l o a t IMU gyro data X , IMU gyro data Y , IMU gyro data Z ; // Values of l o c a l IMU gyros co pe ( d eg re es / s ) 41 float IMU mag data X , IMU mag data Y , IMU mag data Z ; // Values of l o c a l IMU magnetometer (uT) 42 float Pitch deg , R oll deg , Yaw deg = 0;// Pitch , R o l l and Yaw ( de gr e es ) 43 44 // Dec lar e v a r i a b l e s o ut si de IMU , s i n ce v a r i a b l e s i n i t i a t e s to 0without d e f i n i n g them i n f u n c t i o n 45 float A c c e l t o t a l v e c t o r m o d u l u s ; // A cc ele rom et e r t o t a l v e c t o r magnitude (m / s ˆ2) 46 f l o a t A c c e l p i t c h d e g , A c c e l r o l l d e g ; // A cc e le ro me t er p i t c h and r o l l a n g l e s ( de gr e es ) 47 f l o a t Gyr o p itc h d eg , G y r o r o l l d e g ; // Gyroscope p it c h and r o l l a ng le s ( de gr e es ) 48 bool Gy r o A c ce l sy n c = f a l s e ; // Check i f Gyroscope and Acc ele rom ete r are synchronized 49 f l o a t Mag X calc , Mag Y calc ; // C a l c u l a t e d Magnetometer v al u e (uT) 50 f l o a t Mag X corrected , Mag Y corrected ; // Co rre ct ed v a l ue Magnetometer va l ue ( with damping ) (uT) 51 f l o a t P it ch r ad , R o l l r a d ; // P it ch and R o l l a n g l e s ( rad ) 52 53 i n t RW speed = 0 ; // Value of R eaction Wheel speed [ from −255 to 255] 54 i n t OBC mode value = 0 ; // Value of On Board Computer mode ( wai ti ng , p o s i t i o n i n g , detumbling , e tc . ) 55 i n t OBC data value = 0; // Value of On Board Computer data ( d e s i r e d an gle turn , et c . ) 56 i n t S t o p s t a t e = 0 ; // I f S t o p s t a t e != 0 , motor s t op s r o t a t i n g 57 58 // PID c o n t r ol d e f i n i t i o n s 59 double P ID error , P I D l a s t e r r o r ; // I n i t i a l i z e e r r o r and p r e v i o u s E r r o r 60 double PI D c u m ul a t iv e e r r or , P I D r a t e e r r o r ; // I n i t i a l i z e the cum ula ti ve E r r o r ( I n t e g r a l ) and the r a t e of E r ro r ( D e r i v a t i v e ) 61 f l o a t Current Yaw deg = 0 ; // A d dit io n o f 180 deg to a l l v a l u e s . The e r r o r i s a s u bs tr ac t , so the d i f f e r e n c e i s the same 62 63 dou ble kp = 1 ; // P r o p o r t i o n a l c o n t r i b u t i o n 64 double k i = 0 ; // I n t e g r a l c o n t r i b u t i o n 65 double kd = 1 ; // D e r i v a t i v e c o n t r i b u t i o n 66 67 f l o a t Deg to r each = 0 ; // S e t po i n t a ngl e ( d eg re e s ) 68 bool Z e r o s t a t e = f a l s e ; // Check i f PID encompass yaw o f 0 d e gre es ( to tur n the va l u e to a workable zone ) 69 i n t PID output = 0; // Output va lue of the PID [ from 0 to 255] 110
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 70 71 // FUNCTIONS 72 // GENERAL USE FUNCTIONS 73 // OBC Func tio ns 74 voi d OBC mode receive ( ) 75 { 76 /∗ 77 Function to s et the B l u e p i l l to r e c e i v i n g mode . Uses Timer CH3.Serial1as UART communication 78 79 INPUT : None , but g e ts mode from User Serial1input 80 OUTPUT: None , but sa v es OBC mode value 81 ∗/ 82 83 // Check i f UART S e r i a l 1 i s a v a i l a b l e 84 read IMU () ; 85 86 i f ( S e r i a l 1 . a v a i l a b l e () >0) 87 { 88 S tr i n g b u f f e r S t r i n g = ””; // S t r in g f o r b u f f e r of S e r i a l 1 89 // Keep s a v i n g i n p u t prompt 90 w hi l e ( S e r i a l 1 . a v a i l a b l e () >0) 91 { 92 b u f f e r S t r i n g += ( char ) S e r i a l 1 . read ( ) ; // Adds c ha rs to the S e r i a l 1 b u f f e r 93 } 94 // C on vers io n from S t r i n g to i n t 95 OBC mode value = b u f f e r S t r i n g . t o I n t ( ) ; 96 S e r i a l 1 . p r i n t (”Mode Number : ”) ; 97 S e r i a l 1 . p r i n t l n ( OBC mode value ) ; 98 } 99 } 100 101 voi d OBC data receive () 102 { 103 /∗ 104 Function to s et the B l u e p i l l to r e c e i v i n g data mode . Uses Timer CH3.Serial1 as UART communication 105 106 INPUT : None , but g e ts data from User Serial1input 107 OUTPUT: Save OBC data value 108 ∗/ 109 read IMU () ; 110 // Check i f UART S e r i a l 1 i s a v a i l a b l e 111 i f ( S e r i a l 1 . a v a i l a b l e () >0) 112 { 113 S tr i n g b u f f e r S t r i n g = ””; // S t r in g f o r b u f f e r of S e r i a l 1 114 // Keep s a v i n g i n p u t prompt 111
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 115 w hi l e ( S e r i a l 1 . a v a i l a b l e () >0) 116 { 117 b u f f e r S t r i n g += ( char ) S e r i a l 1 . read ( ) ; // adds ch ar s to the S e r i a l 1 b u f f e r 118 } 119 OBC data value = b u f f e r S t r i n g . t o I n t ( ) ; // C onversion from S t r in g to i n t 120 } 121 } 122 123 void EmergencyStop () 124 { 125 /∗ 126 Function to STOP the motor from r o t a t i n g . 127 128 INPUT : None , but g e ts data from User Serial1input 129 OUTPUT: Save OBC data value 130 ∗/ 131 132 // Check i f UART S e r i a l 1 i s a v a i l a b l e 133 i f ( S e r i a l 1 . a v a i l a b l e () >0) 134 { 135 S tr i n g b u f f e r S t r i n g = ””; // S t r in g f o r b u f f e r of S e r i a l 1 136 // Keep s a v i n g i n p u t prompt 137 w hi l e ( S e r i a l 1 . a v a i l a b l e () >0) 138 { 139 b u f f e r S t r i n g += ( char ) S e r i a l 1 . read ( ) ; // adds ch ar s to the S e r i a l 1 b u f f e r 140 } 141 S t op s ta te = b u f f e r S t r i n g . t o I n t ( ) ; // Co nvers ion from S t r i ng to i n t 142 S e r i a l 1 . p r i n t (” Emergency Stop a c t i v a t e d ”) ; // I n t h i s case turn , but can be what i s needed 143 } 144 145 // Timer1 . a t t a c h I n t e r r u p t (TIMER CH4 , read show IMU ) ; 146 // read show IMU () ; 147 // mode Select ( OBC mode value ) ; 148 149 i f ( S t o p s t a t e != 0) 150 { 151 // I f i t stopped 152 s e t i m p u l s e ( 0 , 0) ; 153 S e r i a l 1 . f l u s h () ; 154 OBC data value = 0; 155 mode OBC Input Wait ( ) ; 156 } 157 } 158 159 // D r i v e r F un cti ons 160 vo id s e t i m p u l s e ( bool RW direction , i n t New RW speed ) 161 { 162 /∗ 163 Function to s et the motor at a f i x e d d i r e c t i o n and speed (B = po rt 1, A = po rt 0) 112
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 164 165 INPUT : 166 RW direction : Reaction Wheel d i r e c t i o n [ Cl ock wise or Counter Cloc kwis e ] i n A 167 New RW speed : New r e a c t i o n wheel speed [ from 0to 2 55 ] 168 OUTPUT: 169 None , but sa v es speed of the Reaction Wheel 170 ∗/ 171 172 // Account f o r change i n d i r e c t i o n 173 // I f motor ’ s z−a x i s d i r e c t i o n i s c o i n c i d e n t with CubeSat ’ s z−a x i s d i r e c t i o n 174 /∗ ∗ 175 ∗RW direction == t r u e −−−>CounterClockwise , motor d i r e c t i o n = 0 176 ∗RW direction == f a l s e −−−>Clockwise , motor d i r e c t i o n = 1 177 ∗ 178 ∗ ∗ / 179 // I f motor ’ s z−a x i s d i r e c t i o n i s CONTRARY to CubeSat ’ s z−a x i s d i r e c t i o n 180 /∗ ∗ 181 ∗RW direction == t r u e −−−>CounterClockwise , motor d i r e c t i o n = 1 182 ∗RW direction == f a l s e −−−>Clockwise , motor d i r e c t i o n = 0 183 ∗ 184 ∗ ∗ / 185 186 i f ( RW direction ) // Reaction Wheel Counter Clock Wise 187 { 188 DriverOne . s e t D r iv e (1 , 1 , New RW speed ) ; // Change d i r e c t i o n depending on motor connection 189 RW speed = New RW speed ; 190 } 191 e l s e // Reaction Wheel Clock Wise 192 { 193 DriverOne . s e t D r i v e ( 1 , 0 , New RW speed ) ; 194 RW speed = −New RW speed ; 195 } 196 } 197 198 voi d generate ramp ( bool RW direction , i n t Acc ramp time durat ion , i n t RW ramp speed reach , bool Ac c Dec s tat e ) 199 { 200 /∗ 201 Functi on to ge ne rat e ramps . I n t h i s cas e i t i s a S i n g l e Im pulse . 202 As we dont know the time i t l a s t s , we have to see i f speed changes on the cubes at . That i s the use of the w h i l e . 203 204 INPUT : 205 RW direction : Reaction Wheel d i r e c t i o n [ Cl ock wise or Counter Cloc kwis e ] 206 Acc ram p ti me d ura ti on : Duration o f ramp 207 RW ramp speed reach : F i n a l speed reached 208 Acc D ec st ate : Check wether in a c c e l e r a t i o n s t a t e ( ’ 1 ’ ) or deceleration state ( ’ 0 ’ ) 209 OUTPUT: 210 None 211 ∗/ 212 113
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 213 S e r i a l 1 . p r i n t l n (”Ramp S t a r t ”) ; 214 bo ol w a i t i n g = t r u e ; 215 216 s e t i m p u l s e ( RW direction , RW ramp speed reach ) ; 217 218 Timer1 . a t t a c h I n t e r r u p t (TIMER CH4 , read show IMU ) ; 219 w a i t i n g = t r u e ; 220 221 w h i l e ( w a i t i n g ) 222 {// Range of t o l e r a n c e 223 if (Acc Dec state) 224 {// If accelerating 225 i f ( abs ( IMU gyro data Z ) >G y r o t o l e r a n c e ) 226 {// I f gyro i s not 0 or so , means i t has co nsta nt speed of r o t a t i o n 227 i f ( abs ( IMU accel data X ) <Accel tolerance) 228 {// Stop of a c c e l e r a t i o n 229 w a i t i n g = f a l s e ; 230 } 231 } 232 } 233 e l s e 234 {// If decelerating 235 i f ( abs ( IMU gyro data Z ) <G y r o t o l e r a n c e ) 236 {// I f gyro i s not 0 or so , means i t has co nsta nt speed of r o t a t i o n 237 i f ( abs ( IMU accel data X ) <Accel tolerance) 238 {// Stop of a c c e l e r a t i o n 239 w a i t i n g = f a l s e ; 240 } 241 } 242 } 243 d e l ay ( 1) ; // Delay f o r e n s u r i n g g e t t i n g i n s i d e the w h i l e loop 244 } 245 w a i t i n g = t r u e ; 246 Timer1 . d e t a c h I n t e r r u p t (TIMER CH4) ; 247 } 248 249 // IMU F unc tions 250 voi d read IMU ( ) 251 { 252 /∗ 253 Function to read IMU Data ( and r e f r e s h e s the g l o ba l v a r i a b l e s f o r IMU data ) . 254 255 INPUT : 256 None 257 OUTPUT: 258 None , but sa v es IMU v a r i a b l e s and Roll , Pitc h and Yaw 259 ∗/ 260 261 // Begin r e ad i n g IMU and pitc h , yaw , r o l l 262 IMU . re ad S en s or ( ) ; 263 114
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 264 // A c c e l e r a t i o n s 265 IMU acce l da ta X = IMU . g etAccelX m ss ( ) ; 266 IMU acce l da ta Y = IMU . g etAccelY m ss ( ) ; 267 IMU a cc el d at a Z = IMU . getA cc elZ mss ( ) ; 268 // Gyroscope 269 IMU gyro data X = (IMU . ge tG yr oX rads ( ) ∗Rad to deg ) ; 270 IMU gyro data Y = (IMU . ge tG yr oY rads ( ) ∗Rad to deg ) ; 271 IMU gyro data Z = (IMU . g etGyr oZ r ad s ( ) ∗Rad to deg ) ; 272 //Magnetometer 273 IMU mag data X = IMU . getMagX uT ( ) ; 274 IMU mag data Y = IMU . getMagY uT ( ) ; 275 IMU mag data Z = IMU . getMagZ uT ( ) ; 276 277 // GetTime of IRS , i n case v al u e i s c o r r e c t i f ti mer d e f i n i t i o n changes . 278 // The dT i s the time s tep of each i n t e r r u p t , thus , each read o f the IMU 279 // F i r s t d i v i s i o n of c l o c k by p r e e s c a l e r ( f r eq ue ncy of ti me r ) , then i n v e r s i o n ( p e r i o d of ti mer ) , then m u l t i p l i c a t i o n by ov e r f l o w ( p e r i o d of channel ) 280 f l o a t dT = ((1 / ( ( float)STM32 CLOCK / ( f l o a t ) Timer1 . g e t P r e s c a l e F a c t o r ( ) ) ) ∗ Timer1 . getOver flow () ) ∗0 . 0 0 1 ; // dT i n s ec on ds 281 282 // Get the an gle Pi tc h and R o l l a ng le (w = w0 + dT∗angular vel) 283 Gy r o p i t ch de g += dT ∗(IMU . g et Gy ro Y rads ( ) ) ∗Rad to deg ; 284 Gyro roll deg += dT ∗(IMU . ge tG yr oX rads ( ) ) ∗Rad to deg ; 285 286 // Gimbal l o c k compensati on 287 Gy ro p it ch d eg = Gy ro p it ch d eg + G y r o r o l l d e g ∗s i n (dT ∗(IMU . getG yr oZ r ads ( ) ) ) ; 288 Gyro roll deg = Gyro roll deg −Gyro pitch deg ∗s i n (dT ∗(IMU . getG yr oZ r ads ( ) ) ) ; 289 290 // Modulus of the a c c e l e r a t i o n ve ctor , c a l c u l a t e the t o t a l (3D) v e c t o r 291 A c c e l t o t a l v e c t o r m o d u l u s = s q r t ((IMU. getAccelX mss ( ) ∗IMU . g etA cce lX ms s ( ) ) + (IMU . g etA cce lY ms s ( ) ∗IMU . getAcc elY mss ( ) ) + (IMU . g etAcc elZ mss ( ) ∗IMU . getAccelZ mss ( ) ) ) ; 292 A c c e l p i t c h d e g = a s i n ( ( f l o a t )IMU . getAccelX mss ( ) / A c c e l t o t a l v e c t o r m o d u l u s ) ∗Rad to deg ; // C a l c u l a t e t he p i t c h a n gl e from a c c e l e r o m e t e r 293 A c c e l r o l l d e g = a s in (( float)IMU . get Acc elY mss ( ) / A c c e l t o t a l v e c t o r m o d u l u s ) ∗ Ra d to de g ; // C a l c u l a t e t he r o l l an gl e from a c c e l e r o m e t e r 294 295 /∗Acc ele rom ete r c a l i b r a t i o n ∗/ 296 297 // To c a l i b r a t e t he a c cel er ome te r , put the v a l u e s 0 . 0 i n the v a r i a b l e s and uncomment the 3 S e r i a l 1 . p r i n t s 298 // When c om piling , l e a v e the IMU im mobile so t ha t th e a c c e l e r o m e t e r c a l i b r a t e s p r o p e r l y . 299 // Once the v a l u e s are obt ained , they ar e noted and i t i s r eco mp ile d as i t had been b e f o r e . 300 301 Accel pitch deg −= 0 . 1 0 ; 302 Accel roll deg −= 3 . 0 6 ; 303 304 // S e r i a l 1 . p r i n t ( A c c e l p i t c h d e g , 6 ) ; 305 // S e r i a l 1 . p r i n t (”\t ”) ; 115
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 306 // S e r i a l 1 . p r i n t l n ( A c c e l r o l l d e g , 6 ) ; 307 308 // I f gy ro sco pe and a c c e l e r o m e t e r a re s y n c h r o ni z e d 309 i f ( Gy ro A c ce l sy n c ) 310 { 311 // −−−−− Gyro & a c c e l have been s yn c hr on i ze d 312 Gyro pitch deg = Gyro pitch deg ∗0.95 + A c c e l p i t c h d e g ∗0 . 0 5 ; // C o rre ct th e d r i f t of the gyro p i t c h a ng le wi th the a c ce l e r om e t e r p i t c h a ng le . O r i g i n a l v a l u es were 0.9996 and 0.0004m, r e s p e c t i v e l y . 313 Gyro roll deg = Gyro roll deg ∗0.95 + A c c e l r o l l d e g ∗0 . 0 5 ; // C or re ct th e d r i f t o f the g yro r o l l a n gl e with t he a c c e l e r o m e t e r r o l l a n g le 314 } 315 e l s e 316 {// The 0. 98 and 0.0 2 v a l u e s a re taken from http : // www. p i e t e r −j an . com/node/11 e l s e { 317 // −−−−− S yn chr oni ze gyro & a c c e l 318 G yr o p i tc h d eg = A c c e l p i t c h d e g ; // Set the gyro p i t c h a ng le equa l to the a c c e l e r o m e t e r p i t c h a n gl e 319 G y r o r o l l d e g = A c c e l r o l l d e g ; // Set the gyro r o l l ang le equal to the a c c e l e r o m e t e r r o l l a ng le 320 Gy ro Ac ce l sy nc = t ru e ; // Set the IMU s t a r t e d f l a g 321 } 322 323 // F i n a l c o r r e c t e d P itch and R o l l a ngl e ( d eg re es ) 324 Pi tc h deg = Pi tc h deg ∗0.9 + G y r o p i t ch de g ∗0 . 1 ; 325 R o l l d e g = R o l l d e g ∗0.9 + Gyro roll deg ∗0 . 1 ; 326 327 // F i n a l c o r r e c t e d P itch and R o l l a ngl e ( r a d i a n s ) 328 P i t c h r a d = −R o l l d e g ∗Deg to rad ; 329 R o l l r a d = Pi tch deg ∗Deg to rad ; 330 331 // C a l c u l a t e d v a l u e s o f Magnetometer a lo ng X and Y a x i s 332 Mag X calc = IMU . getMagX uT ( ) ∗cos ( P i t c h r a d ) + IMU . getMagY uT ( ) ∗s i n ( R o l l r a d )∗s i n ( P i t c h r a d ) −IMU . getMagZ uT ( ) ∗cos ( R o l l r a d ) ∗s i n ( P i t c h r a d ) ; 333 Mag Y calc = IMU . getMagY uT ( ) ∗cos ( R o l l r a d ) + IMU . getMagZ uT () ∗s i n ( R o l l r a d ) ; 334 335 // C o rr e ct d r i f ( same as P it ch de g ) 336 Mag X corrected = Mag X corrected ∗0. 9 + Mag X calc ∗0 . 1 ; 337 Mag Y corrected = Mag Y corrected ∗0. 9 + Mag Y calc ∗0 . 1 ; 338 339 // The magnetic north has been modified , o r i g i n a l l y , i t was from X to Y ( towards which the r ea d i ng 0 was 90 d e g re es o f f s e t ) and w it ho ut t he n e g a t i v e s i g n o f th e b eg in ni ng ( towards which the re a di n g would add the a ng l e s c o u n t e r c l o c k w i s e i n s t e a d of c l o c k w i s e ) . 340 341 Yaw deg = −atan2 ( Mag Y corrected , Mag X corrected ) ∗Rad to deg ; 342 343 // I f you want to be p r e c i s e , add the d e c l i n a t i o n of the g e o g r a p h i c a l p l ac e where you are ( ht t p s : // www. ign . es /web/gmt−declinacion−magnetica) 344 // Yaw deg += D e c l i n a t i o n ; 345 346 // The next two l i n e s c o nt a i n the va lu e of Yaw deg between 0 and 360 d eg r ee s . 116
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 347 i f ( Yaw deg <0) 348 Yaw deg += 360; 349 i f ( Yaw deg >= 360) 350 Yaw deg −= 360; 351 } 352 353 voi d show IMU ( ) 354 { 355 /∗ 356 Function to show IMU Data on the Serial1Monitor 357 358 INPUT : 359 None 360 OUTPUT: 361 None 362 ∗/ 363 364 // P r i n t a c c e l e r o m e t e r v a l u e s 365 // S e r i a l 1 . p r i n t (” Acc : ”) ; 366 // S e r i a l 1 . p r i n t ( IMU accel data X , 4) ; 367 // S e r i a l 1 . p r i n t ( ’\t ’) ; 368 // S e r i a l 1 . p r i n t ( IMU accel data Y , 4) ; 369 // S e r i a l 1 . p r i n t ( ’\t ’) ; 370 // S e r i a l 1 . p r i n t ( IMU accel data Z , 4 ) ; 371 // S e r i a l 1 . p r i n t l n (””) ; 372 373 // P r i n t Gyro v a l u e s 374 // S e r i a l 1 . p r i n t (” / G: ” ) ; 375 // S e r i a l 1 . p r i n t ( IMU gyro data X , 4 ) ; S e r i a l 1 . p r i n t ( ’\t ’) ; 376 // S e r i a l 1 . p r i n t ( IMU gyro data Y , 4 ) ; S e r i a l 1 . p r i n t ( ’\t ’) ; 377 // S e r i a l 1 . p r i n t ( IMU gyro data Z , 4 ) ; S e r i a l 1 . p r i n t ( ’\t ’) ; 378 // S e r i a l 1 . p r i n t ( g y r o Z o f f s e t e d , 4 ) ; 379 // S e r i a l 1 . p r i n t l n (”” ) ; 380 381 // P r i n t Mag v a l u e s 382 // S e r i a l 1 . p r i n t ( ”MAGS: ” ) ; 383 // S e r i a l 1 . p r i n t ( IMU mag data X , 4 ) ; S e r i a l 1 . p r i n t ( ’ ; ’ ) ; 384 // S e r i a l 1 . p r i n t ( IMU mag data Y , 4 ) ; S e r i a l 1 . p r i n t ( ’ ; ’ ) ; 385 // S e r i a l 1 . p r i n t ( IMU mag data Z , 4 ) ; 386 // S e r i a l 1 . p r i n t l n ( ”” ) ; 387 388 // P ri nt o r i e n t a t i o n a ng l e s 389 S e r i a l 1 . p r i n t ( ” / D: ”) ; 390 S e r i a l 1 . p r i n t ( Pitch deg , 4) ; 391 S e r i a l 1 . p r i n t ( ’ ; ’ ) ; 392 S e r i a l 1 . p r i n t ( Ro ll d eg , 4) ; 393 S e r i a l 1 . p r i n t ( ’ ; ’ ) ; 394 S e r i a l 1 . p r i n t ( Yaw deg , 4) ; 395 S e r i a l 1 . p r i n t l n (””) ; 396 } 397 398 voi d read show IMU ( ) 399 { 117
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 400 /∗ 401 Function to both read and show IMU Data . 402 403 INPUT : 404 None 405 OUTPUT: 406 None , but sa v es IMU v a r i a b l e s and Roll , Pitc h and Yaw 407 ∗/ 408 409 read IMU () ; 410 show IMU ( ) ; 411 } 412 413 // PID F unc tio ns 414 voi d computePID ( ) 415 { 416 /∗ 417 Function to c a l c u l a t e PID 418 419 INPUT : 420 None 421 OUTPUT: 422 None , but s av es PID v a l u e s 423 ∗/ 424 425 // Time ste p 426 f l o a t dT = ((1 / ( ( float)STM32 CLOCK / ( f l o a t ) Timer1 . g e t P r e s c a l e F a c t o r ( ) ) ) ∗ Timer1 . getOver flow () ) ∗0 . 0 0 1 ; // i n s ec on ds 427 428 read show IMU () ; 429 430 Current Yaw deg = Yaw deg ; 431 432 // Check i f PID pa s s es through 0 d e gr e es 433 if (Zero state) 434 { 435 // Saves i f the pid pass through 0 , i f i t does i t moves the zone away from 0 436 // New v a r i a b l e to not modify the Yaw deg v a lu e 437 Current Yaw deg = Yaw deg + 180; // A d dit io n o f 180 deg to a l l v a l u e s . The e r r o r i s a s u b st r a c t , so the d i f f e r e n c e i s the same 438 } 439 440 i f ( Current Yaw deg >= 360) 441 Current Yaw deg −= 360; // One of them w i l l i n c r e a s e ove r 360 , i t i s a c o r r e c t i o n 442 443 // Percentage 444 v o l a t i l e f l o a t Yaw deg perc = ( Current Yaw deg −360) / (−3 6 0 )∗1 00 ; 445 446 // Transform an gl e to p er ce nt a ge ( D eg t o r each == s e t P o i n t ) 447 volatile float D e g t o r e a c h p e r c = ( D eg t o r eac h −36 0 )/ ( −360) ∗100; 118
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 448 449 // E r r o r s 450 P I D e r r o r = D e g t o r e a c h p e r c −Yaw deg perc ; // C a l c u l a t e e r r o r ( Proportional) 451 P I D c u m u l a t i v e e r r o r += P I D e r r o r ∗dT ; // C a l c u l a t e the c umu lat ive e r r o r ( I n t e g r a l ) 452 P I D r a t e e r r o r = ( P ID e rr or −P I D l a s t e r r o r ) / dT ; // C a l c u l a t e the r a t e o f e r r o r ( D e r i v a t i v e ) 453 454 // PID C on tr ol 455 float PID P = kp ∗PID error ; // Proportional 456 float PID I = k i ∗PID cumulative error ; // Integral 457 float PID D = kd ∗P I D r a t e e r r o r ; // Derivative 458 459 /∗ 460 // Lim it 461 // Ensure not o v e r f l o w 462 i f ( PID P >255) 463 PID P = 255; 464 i f ( PID P <−255) 465 PID P = −255; 466 i f ( PID I >255) 467 PID I = 255; 468 i f ( PID I <−255) 469 PID I = −255; 470 i f ( PID D >255) 471 PID D = 255; 472 i f ( PID D <−255) 473 PID D = −255; 474 ∗/ 475 476 PID output = PID P + PID I + PID D ; // PID c o n t r o l 477 478 // Pre ve nt o v e r f l o w 479 i f ( PID output >2 55 ) 480 PID output = 2 55 ; 481 i f ( PID output <−25 5 ) 482 PID output = −25 5 ; 483 484 bool RW direction = t r u e ;// t r u e=p o s i t i v e ( Counter Clockwi se ) , f a l s e=n e g a t i v e ( Clo ckwi se ) 485 486 i f ( PID output <0) 487 { 488 PID output = −PID output ; 489 RW direction = f a l s e ; 490 } 491 492 s e t i m p u l s e ( RW direction , PID output ) ; 493 494 // Save c u r r e n t e r r o r and time f o r next iteration 495 P I D l a s t e r r o r = P I D er r or ; // Save c u r r e n t e r r o r 496 } 119
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 762 {// i f i t i s almost e x a c t l y 0then most p ro ba bly t h e r e i s a d i s c o n n e c t i o n . Clos e numbers sho uld not t r i g g e r i t . 763 } 764 e l s e i f (Check Yaw deg −Prev Yaw deg >+1 80 ) 765 {// Checks f o r a heavy change ( g r e a t e r than h a l f tu rn ) . Done by changes i n 0, l i k e jumping from 3 5 9 to 0. ( Not p o s s i b l e i n theory , as i t d ecre ases , but d e v i a t i o n s cou ld mess i t up ) 766 o v e r l a p c o u n t += 1;// adds a la p 767 } 768 e l s e i f (Check Yaw deg −Prev Yaw deg <−180 ) 769 {// Checks f o r a heavy change ( g r e a t e r than h a l f tu rn ) . Done by changes i n 0, l i k e jumping from 0to 3 59 . 770 o v e r l a p c o u n t −=1;// substracts a lap 771 }// i f n e i t h e r a re t r i g g e r e d , change has been sa ma ll or no change has been done yet 772 773 Prev Yaw deg = Check Yaw deg ; 774 Check Yaw deg = Check Yaw deg + (36 0 ∗o v e r l a p c o u n t ) ; // Rewriting of va l u e . I t does not add i t s e l f as i t ge ts the read va lu e i n each i t e r a t i o n . In ot he r words , i t w i l l not go through the i t e r a t i o n with numbers o u t s i d e 0and 3 60 range 775 i f (Check Yaw deg <D eg r e e s t op w a i t ) 776 {// As i t i s CCW, de gree i n c r e a s e s . When r ea di n g i s >to stop value , e x i t s the w h i l e 777 w a i t i n g = false ;// exit condition 778 } 779 delay(1) ; // To s o l ve e r r o r s 780 // No w r i t i n g of read IMU as i t i s a l r e a d y done by a t im er . Ju st to remind Yaw deg i s c o n s t a n t l y r e ad i ng v a l u e s . 781 } 782 Timer1.detachInterrupt(TIMER CH4) ; 783 } 784 } 785 786 // −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−DECELERATION 787 Serial1.print(”ID : ” ) ; 788 Serial1.print(Final IMU degree value); 789 Serial1.print(” / ED: ” ) ; 790 Serial1.println( D e g re e s t o p w ai t ) ; 791 792 // In i t ia l R W S p e ed r e t ur n s speed to o r i g i n a l v a l ue i n s t e a d of 0 793 generate r am p ( RW d ire cti on , i n i t i a l R W s p e e d , 0,0) ; 794 // This i s to a s s u r e th e im pu ls e i s the same , as i f t h e r e i s some momentum accumulation , r e t u r n i n g to 0would be a d i f f e r e n t imp ulse 795 // 0w i l l not be used as we dont d e f i n e the time the motor l a s t s to do an impulse . 2 5 5 i s the max value 796 // This v a l ue s w i l l be s u b s t i t u t e d by how we want the time and speed to reach i n the ramp . 797 798 read show IMU () ; 799 Final IMU degree value = Yaw deg; // can be o v e r w r i t t e n , f i n a l d egre e o f manoeuvre 800 i f (RW direction) 126
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 801 { 802 D el t a d e gr e e r a mp = F i n a l I M U d e g r e e v a l u e −I n i t i a l I M U d e g r e e v a l u e ; // Should be p o s i t i v e 803 } 804 e l s e 805 { 806 Delt a deg ree r amp = I n i t i a l I M U d e g r e e v a l u e −Final IMU degree value ; // Should be p o s i t i v e 807 } 808 i f ( De lta d egr ee ram p <0) 809 {// can be o v e r w r i t t e n , r e a l t ur n o f manoeuvre 810 Delt a deg ree r amp += 36 0 ;// I n case i t s n e g a t i v e adds 3 60 811 // Negative c as e s : changes goes by 0. EX: 3 30 to 30 when CCW ( s houl d be 60 but c a l c u l u s i s 30−3 30=−300 ) 812 // EX : 30 to 33 0 when CW ( should be 60 but c a l c u l u s i s 30−3 30=−300 ) 813 } 814 815 Serial1.print(”ID : ” ) ; 816 Serial1.print( D e g re e s t o p w ai t ) ; 817 Serial1.print(” / T: ” ) ; 818 Serial1.print( D elta d egr ee ra mp ) ; 819 Serial1.print(” / ED: ” ) ; 820 Serial1.println(Final IMU degree value); 821 822 i f (( De lta d egre e ram p −degree turn value) <Final pointing tolerance && ( Delt a d egr ee r amp −degree turn value) >Final pointing tolerance) 823 { 824 // Detach EmergencyStop 825 Timer1.detachInterrupt(TIMER CH3) ; 826 827 // Real turn vs wanted turn , checks i f i t i s c o n s i d e r e d good 828 mode OBC Input Wait ( ) ; // V al id p o s i t i o n 829 } 830 e l s e 831 { 832 // R e c a l c u l a t e the OBC data value for PID 833 OBC data value = OBC data value −D elt a degr ee ra mp ; 834 positioning Fine(); // Correction 835 } 836 } 837 838 voi d positioning Fine() 839 { 840 /∗ 841 1 . 2 . Mode P o s i t i o n i n g Fine : PID 842 843 INPUT : 844 None 845 OUTPUT: 846 None , but e x i t s to mod e s el ec t 847 ∗/ 848 127
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 849 Serial1.println(”Mode P o s i t i o n i n g Fine ” ) ; 850 851 bo ol w a i t i n g = t r u e ; 852 853 Deg t o reac h = OBC data value + Yaw deg ; // Get v al u e to reach , c o n ta in ed i n 3 60 854 i f ( De g to reac h <0) 855 { 856 Deg to re ach += 3 6 0 ; 857 Zero state = t r u e ;// Used to s t o r e i f it passes 0. 858 // A PD p a s s i n g throu gh 0coul d g i v e g r e a t problems , as i t has a v e ry b ig change i n v a l u e . F ur th e r used i n computePID ( ) 859 } 860 e l s e i f ( D eg to rea ch >=3 6 0 ) 861 { 862 Deg to re ach −=3 60 ;// These two l i n e s c o n ta i n the va lu e of the Yaw deg i n 0− 36 0 de gr e es . 863 Zero state = t r u e ; 864 } 865 e l s e 866 { 867 Zero state = f a l s e ; 868 } 869 870 i f (Zero state) 871 { 872 Deg to re ach + 1 80 ; 873 i f ( De g to reac h >=36 0 ) 874 Deg to re ach −=3 60 ; 875 } 876 877 Timer1.attachInterrupt(TIMER CH4, computePID) ; 878 w h i l e ( w a i t i n g ) 879 {// Range o f t o l e r a n c e 880 i f (abs ( IMU gyro data Z ) <G y r o t o l e r a n c e && abs ( IMU accel data X ) < Accel tolerance && abs( Deg t o reach −Yaw deg ) <Final pointing tolerance) 881 {// we c o n s i d e r i t i s stopped , modify v a l u e s to be a c cu r at e 882 w a i t i n g = false ; 883 } 884 delay(1) ; // Change 885 } 886 w a i t i n g = t r u e ; 887 Timer1.detachInterrupt(TIMER CH4) ; 888 889 // At e x i t , RW speed c ou ld not be 0 890 OBC data value = 0; 891 Serial1.println(”End of manoeuvre ” ) ; 892 893 // Detach EmergencyStop 894 Timer1.detachInterrupt(TIMER CH3) ; 895 896 mode Select ( OBC mode value ) ; 897 } 898 128
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 899 voi d mode IMU reading ( ) 900 { 901 /∗ 902 2−IMU r e a d i n g (TEST PURPOSE F un ct io n ) 903 904 INPUT : 905 None 906 OUTPUT: 907 None , but sa v es IMU v a r i a b l e s and Roll , Pitc h and Yaw 908 ∗/ 909 910 OBC mode value = 0; 911 Timer1.attachInterrupt(TIMER CH4, read show IMU ) ; 912 Timer1.attachInterrupt(TIMER CH3, OBC data receive ) ; 913 w h i l e ( OBC data value == 0) 914 { 915 delay(1) ; // I f not used the w h i l e f u n c t i o n does not work 916 } 917 Timer1.detachInterrupt(TIMER CH3) ; 918 Timer1.detachInterrupt(TIMER CH4) ; 919 OBC data value = 0; 920 mode Select ( OBC mode value ) ; 921 } 922 923 voi d mode motor on off () 924 { 925 /∗ 926 3−Motor ON/OFF (TEST PURPOSE Function ) 927 928 INPUT : 929 None 930 OUTPUT: 931 None 932 ∗/ 933 934 Timer1 . a t t a c h I n t e r r u p t (TIMER CH4 , read show IMU ) ; 935 936 OBC mode value = 0; 937 s e t i m p u l s e ( 0 , 100) ; 938 Timer1 . a t t a c h I n t e r r u p t (TIMER CH3 , OBC data receive ) ; 939 w h i l e ( OBC data value == 0) 940 { 941 d el ay (1) ; // I f not used the w h i le f u n c t i o n does not work 942 } 943 Timer1 . d e t a c h I n t e r r u p t (TIMER CH3) ; 944 s e t i m p u l s e ( 0 , 0) ; 945 OBC data value = 0; 946 mode OBC Input Wait ( ) ; 947 } 948 949 // VOID SETUP 129
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 950 voi d setup ( ) 951 { 952 de l a y (1000) ; // wait to l e t open the s e r i a l 953 // Timers 954 Timer1 . pause ( ) ; 955 Timer1 . s e t P r e s c a l e F a c t o r (7200) ; // 72MHz Clock / 7 20 0 =10KHz tim er 956 Timer1. s e tO ve r fl ow ( 1 00 0 ) ; // Overflow o cc ur s at 1 00 0 , each 1 00 ms t im er r e s t a r t s 957 958 Timer1. setMode (TIMER CH3, TIMER OUTPUT COMPARE) ; // C on f ig ur e channel to OUTPUTCOMPARE: Channel for OBC r ead v a l u e s 959 Timer1. setMode (TIMER CH4, TIMER OUTPUT COMPARE) ; // Channel f o r IMU read v a l u e s 960 Timer1. setCompare (TIMER CH3,1) ; // Phase v a lu e i n Over flow range 961 Timer1. setCompare (TIMER CH4,1) ; 962 963 Timer1. r e f r e s h ( ) ; // Re fr es h t ime r and s t a r t over 964 Timer1. resume () ; 965 966 // Initiations 967 Serial1.begin(9 60 0 ) ; 968 SPI . begin ( ) ; 969 970 Serial1.println(”START” ) ; 971 972 // Setups 973 974 pinMode(LEDPIN , OUTPUT) ; // Integrated LED 975 pinMode(CS1,OUTPUT) ; // NCS Pin d e f i n i t i o n 976 977 // D r i v e r Setup 978 Serial1.println(” C o n f i g u r i n g D r i v e r . . . ” ) ; 979 DriverOne . s e t t i n g s . commInterface = I 2C MODE; // D r i v e r Comm Mode 980 DriverOne . s e t t i n g s . I 2CAddress = 0x5D; // D r i v e r Addr ess ( 0x5D by De f au lt ) 981 982 w h i l e (DriverOne . begin( ) != 0xA9) 983 {// D r i v e r wait f o r i d l e 984 Serial1.println(”ID Mismatch” ) ; 985 delay(2 0 0 ) ; 986 } 987 Serial1.println(”ID Match” ) ; 988 989 Serial1.println(” Waiting f o r enumeratio n ” ) ; // D r i v e r w ai t f o r peripherals 990 w h i l e ( DriverOne . ready () == f a l s e ) 991 ; 130
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 992 Serial1.println(”Ready”) ; 993 994 w h i l e ( DriverOne . busy ( ) ) 995 ;// D r i v e r e n abl e 996 DriverOne . e na ble ( ) ; 997 Serial1.println(” D r i v e r Ready to Use ! ” ) ; 998 999 // IMU Setup 1000 Serial1.println(” C o n f i g u r i n g MPU9250 . . . ” ) ; 1001 i n t s t a t u s = IMU . begin () ; 1002 i f ( s t a t u s <0) 1003 { 1004 Serial1.println(”IMU i n i t i a l i z a t i o n u n s u c c e s s f u l ” ) ; 1005 Serial1.println(” Check IMU w i r i n g or t r y c y c l i n g power ” ) ; 1006 Serial1.print(” S tat us : ” ) ; 1007 Serial1.println( s t a t u s ) ; 1008 w h i l e (1) 1009 { 1010 } 1011 } 1012 1013 IMU . setGyroRange (IMU . GYRO RANGE 5 00DPS) ; 1014 1015 // IMU C a l i b r a t i o n 1016 // Use f o r g e t ti n g the v a lu e s on c a l i b r a t i o n s e t t i n g below 1017 1018 // To c a l i b r a t e the magnetometer or the compass , e v e r y t h i n g i s commented ex ce pt the l a s t 3l i n e s . 1019 // I t moves i n the shape of an e i g h t a pp ro xi mat el y 2min . I t i s recommended to c a rr y out s e v e r a l tim es u n t i l the measurements are f i n e −tuned . 1020 // Uncomment e v e r y t h i n g and e n t e r the v a l u e s obtained from the MagBias and Sc a l e Fa c t o r to view the r e s u l t s of the magnetometer . 1021 // 1022 // IMU . c al ib ra t eM ag ( ) ; 1023 // Serial1.println(”Done” ) ; 1024 // 1025 // Serial1.print(IMU . getMagBiasX uT ( ) ) ; 1026 // Serial1.print(” , ” ) ; 1027 // Serial1.print(IMU . getMagBiasY uT ( ) ) ; 1028 // Serial1.print(” , ” ) ; 1029 // Serial1.println(IMU . getMagBiasZ uT ( ) ) ; 1030 // 1031 // Serial1.print(IMU. getMagScaleFactorX ()) ; 1032 // Serial1.print(” , ” ) ; 1033 // Serial1.print(IMU. getMagScaleFactorY ()) ; 1034 // Serial1.print(” , ” ) ; 1035 // Serial1.println(IMU. getMagScaleFactorZ ()) ; 1036 131
Project of an attitude control system for nanosatellites Due to 22th June 2021 MASE 1037 IMU. setMagCalX(17 .9 6 ,0 .7 9 ) ; // The f i r s t v a l ue c or r e sp o nd s to the MagBias , and the second the S c a l eF a c t or . 1038 IMU. setMagCalY(6 .5 2 ,1 .6 0 ) ; 1039 IMU . setMagCalZ(−38 .4 1 ,0 .9 0 ) ; 1040 1041 Serial1.println(”MPU9250 Ready to Use ! ” ) ; 1042 1043 Serial1.println(” Reading mode from OBC” ) ; 1044 mode OBC Input Wait ( ) ; 1045 } 1046 1047 // VOID LOOP 1048 voi d loop ( ) 1049 { 1050 } 132