1 2 Previous Next 15 Replies Latest reply on Oct 20, 2015 4:40 AM by userc_40766

    Real time robot control



      My current challenge is a real time (or as close as I can get to one) autonomous robotic controller. The PSoC should be capable of doing this but I am looking for some ideas or feedback on my approach: 


      I need to: 


      Read analog (16 ch ADC) and digital (I2C) sensors and process them


      Publish sensor and motion(speed, direction etc) data on I2C bus 


      Receive commands from I2C bus


      Control motors based on the commands. Whilst motor control is ongoing, data must still be collected from sensors - especially digital ones: Accelerometer, Magneto and others. Motor control is based on trapezoidal profiles generated using ISRs.




      How do you see this best implemented? 




      My current implementation is based on a huge main loop and different ISR for functions. The problem is that during trapezoidal generation I can't get any data, during I2C transfers I can't get any motor control and so on. 


      I am thinking of fixing the execution time for each loop and force certain functions to not execute if there isn't enough time. This is similar to an RTOS so probably the most complicated solution. What would be the best way to fix the program execution time or is there another way?


      Another option would be to do all the ADC sampling, trapezoidal generation and whatever else I can in hardware + DMA - I think this would work and be easier to implement? 


      Looking forwad to any ideas :) 



        • 1. Re: Real time robot control

          Let's sort out:


          Anything that runs on hardware saves CPU.


          With the newly introduced Callback macros it is easier to react to events occurring.


          Cypress demonstrated BLC motor control running mostly in hardware a few years ago, I suppose you might find some of that code.


          A choice can be to use an RTOS to have all your different tasks running.


          I would suggest you to use a CY8CKIT-059 Prototyping Kit which has got lots of internal hardware for you to use.





          • 2. Re: Real time robot control

            Hi Bob, 


            Agreed, the more stuff runs in HW the better.  


            I have the big brother of that - the Cy xxxx 50  - large size board with all bells and whistles :) 

            • 3. Re: Real time robot control

              What is the projected size of the robot? You can run 10 PSoC 5 for the price of your CY8CKit-050 when using the -059 ;-)


              The one and only downgrade is: The (snap-offable) KitProg runs from USB-5V, so when using 3.3V peripherals as I2C devices you will have to disconnect them during programming and debugging or you'll have to take other provisions.





              • 4. Re: Real time robot control

                Well... it's not the size constrain rather than doing everything on one IC. 


                I also considered a distribuited approach but I thought it's almost childish and probably would just mask my lack of real time embedded system design. 


                But since you pointed at it, is it a bad idea or something worth investigating? I think with two or three ICs it can be made into a monster project. 


                This does come with inherent issues like sync and distributed tasking but I'm keen to know your thoughts on the matter :) 





                • 5. Re: Real time robot control

                  You can think of an IC as a controller doing its job, as to control one  motor. A communication interface (I2C) can be used to feed that controller with the required data (speed, position timing...). So the controller ICs look the same for every motor, but could be initialized with different motor parameters.


                  When that works, you may consider implementing more than 1 motor controller into the chip until you get to a limit.





                  • 6. Re: Real time robot control

                    Yeah, I did exactly this. I laid my system out ( to occupy the digital resources) and only worked on the relevant part for one motor. 


                    The problem is integrating motor control with the rest of the software - ADC and I2C comms. Because they all call different ISRs and block the CPU more or less. 


                    So what is the best way to mitigate this? Distribute the resource in two different SoCs - one for motor control exclusively and one for sensors, IOs etc? 

                    • 7. Re: Real time robot control

                      Try compiling in "Release" mode, the code size/time reduction is dramatic, debugging gets difficult.


                      The CPU power of a PSoC5 usually allows for multiple ISRs, a chance that you do too much? Clocks at max?





                      • 8. Re: Real time robot control

                        I will try this. Don't think I am doing too much as it's not even maxed out on digital resources yet :D 


                        Probably will need to sort the ISR priority out. 


                        When you say multiple ISR is that in consecutive order or first come first served? 


                        (I'm just exploring the vast ISR resources available at the moment) 





                        • 9. Re: Real time robot control

                          What I wanted to point to: I recently wrote a program that handled > 1000 interrupts per second and still did had time for serving UART, CapSense, ADC and I2C. And that was "only" a PSoC4 with an M0 processor running at 48MHz, a PSoC5 even will be a bit faster.





                          • 10. Re: Real time robot control

                            AndreiRadu brought a good point of where PSoC is positioned among other uC. I was very impressed that Cypress' BLDC motor example executes interrupt at the rate of 10'000/sec on PSoC4 for real-time control. But coexistence of several processes on single core is problematic, especially of slow (UART) and fast ones (BLDC). The old 8-core Propeller would handle such tasks without interference. I am looking to make an array of -059's, it seems that it would be possible to stack them on one side as a bus plane, leaving all analog and some digital inputs available on the other side. I have in mind real-time PID control of a galvo motor, with loop speed approx. 100 kHz. So the ultimate goal is to implement it through ADC-DMA-DFB-DMA-DAC, leaving CPU for UART, GUI and handshaking.     

                            • 11. Re: Real time robot control

                              That seems the first thing that comes to mind for real time systems - DMA, DFB etc. 


                              However, for slower systems - under 100Hz it should not be as bad - 100KHz is indeed super fast but well suitable for PID and other controllers. 


                              But Bob, can you share more details on the project? Some guidelines would be amazing. 

                              • 12. Re: Real time robot control

                                The project is a simple RTOS with a switching frequency of 1kHz generated by the M0 tick-counter. The RTOS leaves all interrupts (Example project additionally uses 6 different interrupts) open for the tasks running. Each tick-counter int causes a second (software) interrupt, so the real rate is more than 2k interrupts per second. And there is still time to run more than 15 tasks in parallel on a PSoC4-M. Powerful chip!!!





                                • 13. Re: Real time robot control

                                  Bob, this sounds like what I need. Not sure it can cover 100KHz for odissey1 but it's worth trying. 


                                  What RTOS are you using? Anything available or custom written code? And what example project did you refer to? 


                                  Thanks for the help and input. 

                                  • 14. Re: Real time robot control

                                    Since my self-written RTOS is still under development and target is (at this time) PSoC4-M I am not quite sure if I will be of any help for you. Did you already had a look at FreeRTOS which is used quite frequently?


                                    When you are really interested in my elaborate, contact me per email under //email address removed // (I will remove that later to prevent me from getting spammed)





                                    1 2 Previous Next