If you like my project vote for "A Smarter Tricopter - Yuri Tikhonov"

 

Good day comrades!

Unfortunately my previous posts have not received special attention of the community. This time, I will try to improve and make a post more extensive and interesting!

As you probably already knew - we are going to talk today about the system of motor control. However this week has been more fruitful for several reasons:

 

1. I finally got the first package from HobbyKing:

one 2200mAh 3S LiPo. Other details are taking long time to arrive, I hope to get them soon.

02_lipo.jpg

2. I got the final package from Farnell: Arduino Yun! I worked a little bit with it and I can say that this is a great device, and it will find it's place in my tricopter! Thanks again to Farnell for such generous gifts.

01_yun.jpg

 

3. When working on the project, I bypassed the main task: the construction of tricopter. It is tri, not the quad! This week I have made a number of modifications to make it's firmware compatible with quadcopter and tricopter.

 

So, a bit of theory. As it is known I use BLDC's in my copter and they require specialized control system. I went the easy way out and decided to buy such a system from HobbyKing, however, there is a small problem: I have not BLDC motors and I have not ESC's (motor control systems) However, I worked previously with such systems when I built my helicopter:

03_hely.jpg

 

To control ESC I need a PWM signal of a certain frequency (I don't know exactly, what is the perfect frequency for my ESC's). Control is carried out as follows:

  1. At the time of startup, you should briefly send to the motor signal "maximum throttle", and then go to the "minimum throttle" this is the initialization.
  2. Speed control is performed by changing the pulse duration of the PWM signal.
  3. Ideally, tricopter should "hang" with the average signal level (50% of full throttle).

 

I don't claim the above to be 100% truth, however, a few years ago I wrote a diploma in multicopters and there,  these principles were used for motor control.

Servo control is by analogy, but it uses a different frequency of PWM and do not require the initialization procedure.

Let's consider 'PSoC Schematics' obtained at a given time :

04_psoc.jpg

 

As you can see I have not used UDB-blocks, because they ended

 

Purple module:

  • PWM_FL - front left motor (for quad and tri);
  • PWM_FR - front right motor (for quad and tri);
  • PWM_RL - rear left (for quad) or rear (for tri) motor;
  • PWM_RR - rear right motor (for quad) or YAW servo (for tri).

 

The configuration of each PWM unit was left by default:

05_pwm.jpg

 

I don't want to show all of the code of the motors and servo control system, I'd better say in words how a copter works:

06_types.png

Quadcopter:

  • Right/Left (ROLL): increase/decrease motors 1 and 4 power, decrease/increase motors 2 and 3 power.
  • Forward/Backward (PITCH): increase/decrease motors 3 and 4 power, decrease/increase motors 1 and 2 power.
  • Turn clockwise/counterclockwise (YAW): increase/decrease motors 1 and 3 power, decrease/increase motors 2 and 4 power.
  • Up/Down (THORTLE): increase/decrease all motors power.

I think, it's very simple and clear.

 

Tricopter:

- Right/Left (ROLL): increase/decrease motor 1 power, decrease/increase motor 2.

- Forward/Backward (PITCH): increase/decrease motor 3 power, decrease/increase motors 1 and 2 power.

- Turn clockwise/counterclockwise (YAW): by servo.

- Up/Down (THORTLE): increase/decrease all motors power.

 

As you might have guessed, this week has implemented mixing of channels, and now, I can try to configurate my sistem on a real copter, but unfortunately I haven't got it yet...

 

For example, I made a few screanshoots of MultiWii GUI and the testimony of the oscilloscope in one of the channels:

 

Thorttle = 0:

07_motor_1.jpg

 

Throttle > 0:

08_motor_2.jpg

 

I also measured the signal using oscilloscope from the YAW-output (servo), in the case of tricopter configuration:

09_servo.jpg

 

Finally, code:

 

1. Configuration of the motors PWM's:

void initOutput(void)
{
    pwmClock_Start();
    PWM_RL_Start();
    PWM_RR_Start();
    PWM_FR_Start();
    #if (NUMBER_MOTOR > 3)
        PWM_FL_Start();
    #endif








 

2. Configuration of the servo PWM:

#if defined(SERVO)
void initializeServo(void)
{
    PWM_FL_Start();
    PWM_FL_SetPrescaler(PWM_FL_PRESCALE_DIVBY8);
    PWM_FL_WritePeriod(30000);
    PWM_FL_WriteCompare(30000);
    //#define SERVO_CHANNEL OCR0A
    //#define SERVO_1K_US 250
}
#endif








 

3. Writing the signal from the motor[] array in to the motors (EXT_MOTOR_RANGE is using for DC motors):

void writeMotors(void) // [1000;2000] => [32000;64000] * 256 (~190Hz motors!)
{
    #ifndef EXT_MOTOR_RANGE
        PWM_RR_WriteCompare( motor[0] << 5 ); //  Rear Right (Tri: Rear)
    #else
        PWM_RR_WriteCompare( (motor[0] << 6) - 64000 );
    #endif
    #ifndef EXT_MOTOR_RANGE
        PWM_FR_WriteCompare( motor[1] << 5 ); //  Front Right (Tri: Top Right)
    #else
        PWM_FR_WriteCompare( (motor[1] << 6) - 64000 );
    #endif
    #ifndef EXT_MOTOR_RANGE
        PWM_RL_WriteCompare( motor[2] << 5 ); //  Rear Left (Tri: Top Left)
    #else
        PWM_RL_WriteCompare( (motor[2] << 6) - 64000 );
    #endif
    #if (NUMBER_MOTOR > 3)
        #ifndef EXT_MOTOR_RANGE
            PWM_FL_WriteCompare( motor[3] << 5 ); //  Front Left
        #else
            PWM_FL_WriteCompare( (motor[3] << 6) - 64000 );
        #endif
    #endif
}








 

4. Writing the same signal to the all motors:

void writeAllMotors(int16_t mc)
{
    uint8_t i;
    for (i=0; i<NUMBER_MOTOR; i++)
        motor[i]=mc;
    writeMotors();
}








 

5. Writing the singnal from the servo[] array to the YAW servo:

#if defined(SERVO)
void initializeServo(void)
{
    PWM_FL_Start();
    PWM_FL_SetPrescaler(PWM_FL_PRESCALE_DIVBY8);
    PWM_FL_WritePeriod(30000);
    PWM_FL_WriteCompare(30000);
}
#endif








 

I hope today's post can seem you more interesting than the previous. Write your comments and suggestions on the project!

 

The next two weeks I'm going to devote to the completion of the frimware, and then - as soom as I receive all components the decisive stage of the project will begin : building of the the machine!

 

See you next week!

10_bear.png

                                                                                                                                              

#linkdescription
1PSoC 4 Tricopter Part #1Introduction
2PSoC 4 Tricopter Part #2Purchase of components from Farnell and HobbyKing
3PSoC 4 Tricopter Part #3PSoC firmware: upTime & Rx
4PSoC 4 Tricopter Part #4PSoC firmware: UART & MultiWii GUI
5PSoC 4 Tricopter Part #5PSoC firmware: EEPROM emulation
6PSoC 4 Tricopter Part #6PSoC firmware: Servo & ESC control
7PSoC 4 Tricopter Part #7PSoC firmware: IMU, LED's & PID
8PSoC 4 Tricopter Part #8Hardware: PCB
9PSoC 4 Tricopter Part #9Hardware: tricopter's frame
10PSoC 4 Tricopter Part #10Hardware: YAW mechanics & motors
11PSoC 4 Tricopter Part #11Hardware: ESC's, wires & misc
12PSoC 4 Tricopter Part #12Final: The first fly

 

If you like my project vote for "A Smarter Tricopter - Yuri Tikhonov"