●●● 3. Controlling Robot Car by ●●●● ●●●●● ●●●● ●●●●● Wireless sensor ●●●● o The ultimate objective of the project is to control the car motion using the steering wheel o The only connection between the steering wheel and car racing system is the wireless marker attached to it o We have to make use of the marker data to control the car motion Reference: 1.J.M. Hart, Windows System Programming, 3rd Ed, Addison-Wesley, 2005,Ch.7,12 Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Controlling Robot Car by Wireless Sensor by Dr Daniel Lun
1 3. Controlling Robot Car by Wireless Sensor ⚫ The ultimate objective of the project is to control the car motion using the steering wheel ⚫ The only connection between the steering wheel and car racing system is the wireless marker attached to it ⚫ We have to make use of the marker data to control the car motion Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Controlling Robot Car by Wireless Sensor by Dr Daniel Lun Reference: 1. J.M. Hart, Windows System Programming, 3rd Ed., Addison-Wesley, 2005, Ch.7, 12
●●● Problem of the previous ●●●● ●●●●● ●●●● ●●●●● Program ●●●● e The markers data are obtained by calling the function Latus: UpdatePO ( o In the previous program, Latus:: UpdatepO ( are called inside the functions EIE330ProjectApp: renderInfo and EIE330ProjectApp: process Calculation) The above 2 functions will be called by ogre only when it updates the le screen If the graphics is complex, the update rate can be very slow, e.g. 20 frames/sec or slower It means that the markers data can only be obtained in such a slow rate Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Controlling Robot Car by Wireless Sensor by Dr Daniel Lun
2 Problem of the Previous Program ⚫ The markers’ data are obtained by calling the function Latus::UpdatePO() ⚫ In the previous program, Latus::UpdatePO() are called inside the functions EIE330ProjectApp::renderInfo and EIE330ProjectApp::processCalculation() ⚫ The above 2 functions will be called by Ogre only when it updates the screen ⚫ If the graphics is complex, the update rate can be very slow, e.g. 20 frames/sec or slower ⚫ It means that the markers’ data can only be obtained in such a slow rate Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Controlling Robot Car by Wireless Sensor by Dr Daniel Lun
●●● ●●●● ●●●●● Update ●●●● Ogre main ●●●●● screen ●●●● program process Calculation If the screen is mLatus:: UpdatePO () updated once per 100ms. markers data can only be renderInfo o) obtained in the same rate, i. e mLatus:: UpdatePO( once per 100ms Finish update Department of ELECTRONIC AND INFORMATION ENGINEERING screen 3. Controlling Robot Car by Wireless Sensor by Dr Daniel Lun
3 Ogre main program processCalculation() { : mLatus::UpdatePO() : } Update screen renderInfo() { : mLatus::UpdatePO() : } Finish update screen : If the screen is updated once per 100ms, markers’ data can only be obtained in the same rate, i.e. once per 100ms Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Controlling Robot Car by Wireless Sensor by Dr Daniel Lun
●●● ●●●● ●●●●● Solution -Multithreading ●●●● ●●●●● ●●●● Get Markers Ogre main Update data program screen UpdatePOO proces s calculation o renderInfoo Routine and b ru at the Routine B same time Routine a (virtually) Finish update screen
4 Solution - Multithreading Ogre main program processCalculation() { : } Update screen Finish update screen : renderInfo() { : } Routine A UpdatePO() { : } Get Markers’ data Finish : Routine B Routine A and B run at the same time (virtually)
●●● ●●●● ●●●●● ●●●● ●●●●● Processes and threads ●●●● ●●●● In Windows, usually a process will be generated when an application is executed When an application is executed m times, m processes will be generated, each with a different process ID A Windows process contains its own independent virtual address space with both code and data Each process contains one or more independently execution unit, called threads The Windows thread is the basic executable unit A process can Create new threads within the processes Create new, independent processes Manage communication and synchronization between these objects Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Controlling Robot Car by Wireless Sensor by Dr Daniel Lun
5 Processes and Threads ⚫ In Windows, usually a process will be generated when an application is executed ⚫ When an application is executed m times, m processes will be generated, each with a different process ID ⚫ A Windows process contains its own independent virtual address space with both code and data ⚫ Each process contains one or more independently execution unit, called threads ⚫ The Windows thread is the basic executable unit ⚫ A process can ⚫ Create new threads within the processes ⚫ Create new, independent processes ⚫ Manage communication and synchronization between these objects Department of ELECTRONIC AND INFORMATION ENGINEERING 3. Controlling Robot Car by Wireless Sensor by Dr Daniel Lun