Hardware-in-the-Loop Simulation
EE199 Directed Research Progress Report
1. IntroductionThe objective of this project is to explore how the performance of control systems is affected by closing the control loops over wireless networks. This portion of the project, developed throughout six months of undergraduate research, focuses on the implementation of hardware-in-the-loop simulation, in which the plant is modeled and simulated in MATLAB Simulink while the communication is implemented over a real network consisting of several Mica motes. [top]2. System OverviewThe following Simulink model depicts a control system with a feedback loop closed over Mica motes with wireless communication: The sensor and actuator blocks call MEX functions to control Mica motes. Corresponding TinyOS programs are installed on the respective motes. Tha author uses the following hardware/software:
[top]3. TinyOS Applications for the MoteBackground KnowledgeTinyOS InstallationInstalling TinyOS 2.0.2 : Official guideline Installing TinyOS on Windows Vista (pdf) : The author's troubleshooting notes for installing TinyOS with Cygwin on Windows Vista. However, due to further compatiblity issues with lcc, MATLAB's linker on Windows for MEx-files, the author recommends using Linux-based machines for this project. TinyOS ProgrammingTinyOS Programming by Philip Levis (pdf) : Explains fundamental concepts of TinyOS and nesC programming. TinyOS Tutorials : Step-by-step tutorials that give instructions on building and using specific applications. 1.3 Mote-mote radio communication and 1.4 Mote-PC serial communication and SerialForwarder are particularly helpful for this project. TinyOS Data Communication Protocolmessage_t : Describes the TinyOS 2.x message buffer. Serial Communication : Explains the TinyOS 2.x serial communication system for mote-to-PC data exchange. Packet Protocols : Documents the interfaces used by packet protocol components in TinyOS 2.x. TinyOS ApplicationsSensorBaseStation ActuatorActuatorC.nc, ActuatorP.nc, Makefile [top]4. C Applications and MEX-files on the ComputerBackground KnowledgeC Application Compilation(1) In a terminal window, change the directory to where the source file is: (2) Compile the source file. The author uses gcc as the compiler. MEX-file ProgrammingMEX-files Guide : Official documentation MEX-file Compilation(1) Choose the compiler by typing the following in MATLAB command window: (2) Compile the source code by typing the following in MATLAB command window: MEX-file Execution(1) Change the directory to where the MEX file is. (2) Call the MEX-file as a function. C Applications and MEX-filesThere are several useful C applications in
A simple way to find out the name of the serial port to which the mote is connected is to list out the contents of the dev directory: SensorserialsendMEX.c : MEX-file version of serialsend.c used in MATLAB. Sends out one packet via serial communication to the connected mote. Actuatorsf.c : Serial forwarder provided in qrMEX.c : Modified MEX-file version of sfsend.c and sflisten.c combined, but only sends out the query packet that contains the number 126, and then listens for one packet returned by the mote, both via the serial forwarder. OthersThe following MEX-files and C applications were written to aid the developement of the final MEX-files used in the project: queryMEX.c : Sends the query packet (packet with a single number 126 as the payload) to a mote via the serial forwarder. receiveMEX.c : Modified MEX-file version of sflisten.c. Listens for and returns one packet from a mote via the serial forwarder. querypacket.c : C version of queryMEX.c. receivepacket.c : C version of receiveMEX.c. [top]5. SimulationThe applications above are the keys to constructing blocks representing the sensor and the actuator in MATLAB Simulink. The sensor and actuator blocks are both Embedded MATLAB Function blocks that call the MEX-files functions serialsendMEX and qrMEX, respectively. Their functions were tested together in a simple system and proved to be working accordingly. sensor.mdl : Simulink block of the sensor. actuator.mdl : Simulink block of the actuator. whole.mdl : Simple system that tests both blocks, as shown below: [top]6. DownloadsTinyOS 2.0.2 related files All source files mentioned above Sample Simulink models [top]Last Updated: 2009/9/2. Questions or comments? Please email Annie I-An Chen |