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
Cypress Kits
  • Products
  • Dev Tools
  • Cypress Kits
  • More
  • Cancel
Cypress Kits
Forum PSOC 4 Ball and Beam Control System, identification toolbox.
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Cypress Kits to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 33 replies
  • Answers 2 answers
  • Subscribers 28 subscribers
  • Views 4249 views
  • Users 0 members are here
  • psoc4
  • ballandbeam
  • identification
  • controlsystem
  • uart
  • pid
Related

PSOC 4 Ball and Beam Control System, identification toolbox.

juanes.pazj
juanes.pazj over 10 years ago

Short Review:

I have been working on this model for a while now, I was having some trouble with the sensor data but all of that is good now,

Here is how the system works every command is fed through the UART interface as well as data read from sensors or input data.

I managed to control angle only (motor position) although I am not very happy with it is somewhat unstable...

The trouble I am facing is controlling the ball position, the simpler control system I could come up was a cascade PID, the problem is I cant get both plants right for simulation Voltage-Angle and Angle-Position, I wanted to get them with identification toolbox in matlab (I have a transfer function for the angle-position plant it is :.

Since the motor was originally scrap from a printer I cant really get its parameters on a datasheet I know it is a Jhonson Motor, 36mm diameter 56mm length, 3mm shaft there are this numbers printed on it I can't seem to find any relation to a motor model. 65791, c5324-60024, 392361

image

image

 

I am not sure if the following procedure should have been the way to go for identification.

I made a Matlab Script that would read a word of data sent by the psoc through UART, in this format "a#p#t#x#f" so I get current angle, motor power (voltage%), current position, and time.

working with the time vector I managed to extract an average sampling time of 0.005s,

I had to create a PRBS signal to command the motor so I did it internally with two alternate power settings that are outputed on a random time (The plot doesnt make it a square wave but all the points are on +18 or -18.)

image

image

After this I went into Ident toolbox

after removing Means, trends and filtering and separating the data for evaluation and validation, I got a 97% fit with a box Jenkins (1 1 3 3 0) which should make a reliable model for simulation but If I used the PID parameters on the PSOC It would diverge every time I cant seem to find a solution.

 

I appreciate your help,

some questions..

the embedded system (PSOC) is very fast (the actual sampling time is 0.004s approximately, should I slow it down for the control system to work?? it Doesn't seem right.

All the theory says the PRBS signal should be 1,-1 signal How do I know if the PRBS signal's amplitude and width is good enough for identification??

 

I would like to try other control methods (non-linear) (State space) but I cant seem to get the models from identification.

 

I am not sure if the files are of any use without the model.. If you want to see them let me know.

Attachments:
RBBv2.cywrk.zip
  • Sign in to reply
  • Cancel

Top Replies

  • DAB
    DAB over 10 years ago +1
    Hi Juan, You are probably experiencing data lag time. When you try to correct something dynamic by using a measured position, you have to account for the movement of the object while you are calculating…
  • michaelkellett
    michaelkellett over 10 years ago in reply to juanes.pazj +1 suggested
    Do you have Simulink - if so you can model you controller and the system and the delays in the PSOC - this might be the quickest way to develop an algorithm/controller that works. MK
  • DAB
    DAB over 10 years ago +1
    Juan, I just remembered that the PSOC has an analog comparator as part of its programmable hardware. You can use that to provide near instantaneous correction for the balance circuitry. DAB
Parents
  • DAB
    0 DAB over 10 years ago

    Hi Juan,

     

    You are probably experiencing data lag time.

    When you try to correct something dynamic by using a measured position, you have to account for the movement of the object while you are calculating your next change.

    Essentially the small time error keeps adding until your system is just too far out of balance to work.

     

    Take a look at your rate of change data.  You can also try running a predictive model that makes the adjustment for where the ball will be instead of where it was.

     

    One trick I learned was to double the correction value off the measurement.  It is a crude approach, but if you have a well behaved system it can keep you out of the too late correction problem.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • juanes.pazj
    0 juanes.pazj over 10 years ago in reply to DAB

    Hi DAB,

    I have been trying to work arround this problem I made a predictor of the ball position using the physical equation in discrete form, in that way the measured point gets in a previous state, and with that and some angle info I estimate the current position,

    but I think a bigger issue is the comunication to the PC the UART on the PSOC is able to reach 1Msps but the windows setup only allows 120ksps I managed to get an average sampling rate of 0.0036s

    can it be that the processor is not fast enough for the job? I have a Psoc 5 board I was working on making the same program for it but it will have to change a lot should I go for it??

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • DAB
    0 DAB over 10 years ago in reply to juanes.pazj

    I do not know.

    You can work it out by calculating how fast the ball moves within your sampling/correction calculation time.

    I think the actual processor is fast enough, but you might need to go to assembly language programming to get the response you need.

    If you are off loading the decision software to your PC and then relying on a serial link to run the messages, that is probably not going to work.

     

    Think about implementing a state machine within the Psoc 5 using an interrupt driven algorithm.  That change might buy you enough time to get your correction loop working in real time.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to juanes.pazj

    Do you have Simulink  -  if so you can model you controller and the system and the delays in the PSOC -  this might be the quickest way to develop an algorithm/controller that works.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to juanes.pazj

    Do you have Simulink  -  if so you can model you controller and the system and the delays in the PSOC -  this might be the quickest way to develop an algorithm/controller that works.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
  • juanes.pazj
    0 juanes.pazj over 10 years ago in reply to michaelkellett

    Hi Michael,

    I was working with Simulink but I cant get the model right, It works on the model but it the controller on the model just wont work on the actual system I don't now why there is so much lag,

    The modes are chosen on a Switch loop,

    the identification mode feedbacks data to the pc

    the control mode can run without feedback messages (less processing to do) but I just cant get it to work as in the model.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to juanes.pazj

    Do you want to post your model - I have Simulink but not the System ID or Control toolbox.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • juanes.pazj
    0 juanes.pazj over 10 years ago in reply to michaelkellett

    I uploaded the model, there is a script BJ, it has the transferfunction of an identified block,there is SS block as well, you can erase that one, the control system on the bottom is just angle control, the one on top is the complete cascade system.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to juanes.pazj

    Sorry, ss.m won't run without the Control System Toolbox.

     

    The Simulink model won't run with the following warnings:

     

     

    Invalid setting in 'tunning/Discrete Transfer Fcn1' for parameter 'Denominator'.

     

     

     

    Error evaluating parameter 'Denominator' in 'tunning/Discrete Transfer Fcn1'

     

     

    Undefined function or variable 'F'.

    Component: Simulink | Category: N.A.

     

     

    Invalid setting in 'tunning/Discrete Transfer Fcn2' for parameter 'Denominator'.

     

     

    Error evaluating parameter 'Denominator' in 'tunning/Discrete Transfer Fcn2'

     

     

    Undefined function or variable 'F'.

    Component: Simulink | Category: N.A.

     

     

    I don't understand your model - I'm looking for things like angle, g, sensor gain/'offset/error but I can't see any of this.

     

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • juanes.pazj
    0 juanes.pazj over 10 years ago in reply to michaelkellett

    Hi  Mike, please erase the State Space block, there are two transfer functions the one depending on the BJ script is the Voltage Angle transfer function (I got it form identification), the other one is the trasferfunction for angle - ball position.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to juanes.pazj

    I can't run the script (don't have the Control Toolbox)  - can you enter the values into the Simulink model and then it could run without the script.

     

    BTW - I think you modelling approach, although common, tends to hide all the insights that modelling can provide.

     

    You should make an actual Simulink model of the physical system, where the angle of tilt applies acceleration to the ball, and then you integrate to get velocity, and again to get displacement.

     

    The model can attempt to model the sensors correctly and ultimately you can include the resolution and lag of the ADC and the time step of the control loop.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • juanes.pazj
    0 juanes.pazj over 10 years ago in reply to michaelkellett

    Can you work with simscape I can model it there I did it once.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to juanes.pazj

    I don't have Simscape.

    But you can model this system without.

    Actually there are 2 double integrators (Bob Pease simplifies his description a bit and puts a servo loop round the motor which he doesn't discuss much)  - you have the motor - gearbox - beam system - your beam looks very massive so you need to take this into account. The second loop is the beam angle to the ball position.  So you have 4 integrators between the ball position and the motor pwm, and some delay in you control loop and some quantisation in the ADC.

     

    Your step 1 model is 4 integrators  - nice and simple in Simulink - work out how to control that and your half way there.

     

    I would almost certainly start (on the physical system) by making two control loops - one to control the beam angle and the second to control the ball by demanding beam angle.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • juanes.pazj
    0 juanes.pazj over 10 years ago in reply to michaelkellett

    Awesome Ill work on it and get back to you!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • 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