element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Smarter Life
  • Challenges & Projects
  • Design Challenges
  • Smarter Life
  • More
  • Cancel
Smarter Life
Blog PSoC 4 Tricopter (Smarter Life Challenge) part #7
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: yuritikhonov
  • Date Created: 8 Dec 2013 1:14 PM Date Created
  • Views 914 views
  • Likes 2 likes
  • Comments 4 comments
  • RoadTest
  • tricopter
  • psoc4
  • Multiwii
  • smarter_life_challenge
  • smarter_life
  • smart_tricopter
  • smart_control_and_diagnostics
  • arduino
  • quadcopter
Related
Recommended

PSoC 4 Tricopter (Smarter Life Challenge) part #7

yuritikhonov
yuritikhonov
8 Dec 2013

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

 

Good day comrades!

This week I've devoted all my free time to the project, to complete its programming part.

 

So this week I've done the following:

  • connected indication led (now - RGB, in a future - 3 independent leds);
  • connected avionics (IMU): Gyro - L3G4200D, Accelerometer - ADXL345;
  • PID-regulators, complimentary filter etc.

 

Now my stand looks like this:

image

 

New components:

  1. Gyro L3G4200D
  2. Accelerometer ADXL345

 

Let's look at the final PSoC schematics:

image

Red-module consists of 3 leds:

  • stablePin = red led: ON - horizon hold mode, OFF - acrobatic mode;
  • buzzerPin = green led: BLINK in some service functions (gyro-calibration, EEPROM write, etc);
  • ledPin = blue led: ON - armed mode (propellers are spining), OFF - disarmed mode (propellers are stoped).

 

Configuration of the led:

image

To realise this functions I use the next code:

 

//green
#define BUZZERPIN_PINMODE { buzzerPin_Write(0x01); }
#define BUZZERPIN_TOGGLE { led_state ^=  0x01; buzzerPin_Write(led_state & 0x01); }
#define BUZZERPIN_ON    { led_state &= ~0x01; buzzerPin_Write(led_state & 0x01); }
#define BUZZERPIN_OFF    { led_state |=  0x01; buzzerPin_Write(led_state & 0x01); }

//blue
#define LEDPIN_PINMODE { ledPin_Write(0x01); }
#define LEDPIN_TOGGLE { led_state ^=  0x02; ledPin_Write((led_state & 0x02)/2); }
#define LEDPIN_ON    { led_state &= ~0x02; ledPin_Write((led_state & 0x02)/2); }
#define LEDPIN_OFF    { led_state |=  0x02; ledPin_Write((led_state & 0x02)/2); }

//red
#define STABLEPIN_PINMODE { stablePin_Write(0x01); }
#define STABLEPIN_TOGGLE  { led_state ^=  0x04; stablePin_Write((led_state & 0x04)/4); }
#define STABLEPIN_ON      { led_state &= ~0x04; stablePin_Write((led_state & 0x04)/4); }
#define STABLEPIN_OFF    { led_state |=  0x04; stablePin_Write((led_state & 0x04)/4); }

 

Some comments:

  • PINMODE - initialization diode;
  • ON - enabling diode;
  • OFF - off diode;
  • TOGGLE - change led status from ON to OFF and viseversa.

 

Orange-module: my gyro and accelerometer use I2C interface and  to work with them I need two functions:

 

1. Write data to register of the I2C slave device:

void i2c_writeReg(uint8_t add, uint8_t reg, uint8_t val)
{
    I2Csys_I2CMasterSendStart(add/2,0); // I2C write direction
    I2Csys_I2CMasterWriteByte(reg);    // register selection
    I2Csys_I2CMasterWriteByte(val);    // value to write in register
    I2Csys_I2CMasterSendStop();
}

 

2. Read data from the I2C slave device:

void i2c_getSixRawADC(uint8_t add, uint8_t reg)
{
    while (I2Csys_I2CMasterStatus() & I2Csys_I2C_MSTAT_XFER_INP);

    if ( I2Csys_I2CMasterSendStart(add/2,0) != 0)
    {
        i2c_errors_count++;
        return;
    }
    if ( I2Csys_I2CMasterWriteByte(reg) != 0)
    {
        i2c_errors_count++;
        return;
    }
    I2Csys_I2CMasterReadBuf( add/2, rawADC, 6, (I2Csys_I2C_MODE_REPEAT_START | I2Csys_I2C_MODE_COMPLETE_XFER) );

    while (I2Csys_I2CMasterStatus() & I2Csys_I2C_MSTAT_XFER_INP);
}

 

I2C configuration:

image

It was'nt very good, so, if in case of MultiWii the failure of one of sensors does not prevent the tricopter from continuing its flight with what is left, in my solution it is not currently supported. I just contacted Cypress, in order to find together the best solution, however, it is not a matter of first importance.

 

If you read carefully, you probably have already noticed, that the tricopter has two modes of flight: the so-called acro (acrobatic) and the stable (hold horizon). I want to dwell on them in more detail:

image

  • acro mode uses only gyroscope. In this mode we stabilise angular speeds of the ROLL, PITCH and YAW . This is the most difficult flight mode, but it makes it possible to perform aerobatics;
  • stable mode uses gyro and accelerometer. In this mode the tricopter tries to maintain a horizontal position, i.e. the regulation is carried out by the angular of YAW speed and the angular deviation of the ROLL and PITCH. In this mode, the pilot may relaxe a bit image
  • magnetometer (MAG) is used for stabilization of the angular deviations by YAW;
  • altitude hold mode uses altimeter to stabilize the altitude of the tricopter's flight  (hold the Z-coordinate);
  • GPS is often used to hold the X and Y coordinates.

 

And now we make important conclusions:

  • gyro only: the machine can rotate at a constant speed on a ROLL, PITCH and YAW. The driver controls the ROLL, PITCH, YAW, X, Y and Z;
  • acc and gyro: the machine can rotate in YAW and move on axes X, Y and Z. The driver controls the YAW, X, Y and Z;
  • mag, acc and gyro: the machine can move along the axes X, Y and Z. All angular speeds are stable. The driver controls the X,Y and Z;
  • altimeter, mag, acc and gyro: the machine can move along the axes X and Y. The driver controls the X and Y;
  • gps, altimeter, mag, acc and gyro: the device can be operated completely independently.

 

Comments:

  • there is a mode (which uses mag), in which the control YAW is left for the pilot, automation seeks to YAW angular speed to zeros only in those moments when you want to manage this axis;
  • GPS has a low resolution and does not work indoors, so for fully autonomous flight are also used other sensors: echo sounders and optical rangefinders;
  • classic altimeter uses baro-sensor for accurate positioning, the echo sounder and the optical rangefinders are also used;
  • megnetometer is just an electronic compass! It is very sensitive and not only to the magnetic field of the earth, but also to the magnetic field created by electrical wires (which abound on tricopters);
  • I chose the most simple and adequate solution and I use two modes: arco mode (aerobatics) and stable mode (for daily use).

 

I took PID-regulators, complimentary filter and other magic system from MultiWii. As soon as I finished writing, it appeared that my program took up more memory than you had in PSoC! The reason was the use of library <math.h>, which "eat" all of the memory. In this connection, I had to implement a variety of mathematical functions: sin, cos, abs etc. After that, my program finally "got" in PSoC!

image

 

Lastly I want to show you the interface of the MultiWii GUI nowaday:

image

 

I put the stand at an angle of 45 degrees, so you can see how the stabilization system works: "virtual tricopter" tilted to the left, thus stabilizing system took a decision to decrease throttle of the right front motor and increase throttle of the front left motor. Everything is very simple, and logical what is most important!

 

Now, I encountered a small problem, I have no special programmer for PSoC and I have to get out somehow to flash a single microcontroller. However, no sooner than I thought about this,  Gagan sent me a gift! Thank you very much, now No need now to make PCB for experiments, that  will accelerate considerably the development!

image

 

I'm still waiting for a parcel from HobbyKing. I began to get a bit nervous, because if it does not come I can not finalize my project:(

However, I hope for their decency and until announce the stage of writing the firmware closed! The next step - fabrication of PCB of the flight controller and construction of the tricoter frame (I have already started searching for the necessary wooden and aluminum components in local stores).

 

See you next week!

                                                                                                                                              

#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" image

  • Sign in to reply

Top Comments

  • jesusantoniocar
    jesusantoniocar over 11 years ago +1
    Hello Yuri. Great Project, thanks for share this with us. I am sure that you will end this on time. Best regards, Jesus
  • DAB
    DAB over 11 years ago +1
    Very good update Yuri. Just focus on the features you can get done. A mostly working project always beats one that does nothing well. DAB
  • vsluiter
    vsluiter over 11 years ago +1
    Hi Yuri, Let's hope you'll get your stuff in time, and very nice of Cypress to send you a gift. Could you clarify a bit of the 'stable' mode? If you're taking off and landing, or going around a corner…
  • yuritikhonov
    yuritikhonov over 11 years ago in reply to vsluiter

    Hi Victor! About your question: in stable mode you control pitch and roll angles  in a very little range and you can't control pitch and roll speed! So it looks like X and Y movement. Example of the pitch speed control: dead loop (You can do it only in acro mode).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vsluiter
    vsluiter over 11 years ago

    Hi Yuri,

     

    Let's hope you'll get your stuff in time, and very nice of Cypress to send you a gift.

    Could you clarify a bit of the 'stable' mode? If you're taking off and landing, or going around a corner, you'd be changing tilt and roll aswell, wouldn't you? Can you explain how that works in your controller?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 11 years ago

    Very good update Yuri.

     

    Just focus on the features you can get done.  A mostly working project always beats one that does nothing well.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jesusantoniocar
    jesusantoniocar over 11 years ago

    Hello Yuri.


    Great Project, thanks for share this with us.

    I am sure that you will end this on time.

     


    Best regards,

    Jesus

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube