Home

LTU - EX - - 05/157 -

image

Contents

1. clear the shared memory area memset dev shmem area 0 dev shmem size the two memory buffers are now ready to be used return 0 103 G 7 pcm3718 c Initializes the DMA controller Input dmaChan the Dma channel to be used startAdress A memory buffer to store the incoming data transferCount Number of bytes to transfer before resetting the buffer autoInitMode A boolean 0 1 telling if the Controller should reinitialize the buffer after transfer completion dir Tells the dma controller if we want to do reading or writing to from the buffer ey int DMASetup int dmaChan void startAddress unsigned int transferCount unsigned int autoInitMode unsigned int dir Note This function uses some fancy low level programming techniques which I don t have time to explain y unsigned char lsb msb page lont hocnt dmaMode off t addr Physical Memory location also called memory offset of StartAdress unsigned int maxTransferCnt if mem offset startAddress NOFD 1 amp addr 0 1 return 1 Memory offset fault maxTransferCnt 0x10000 dmaChan lt 4 addr addr gt gt 1 amp Oxffff if transferCount maxTransferCnt return 1 if dmaChan 4 lsb addr msb addr gt gt 8 page addr gt gt 16 else lsb addr gt gt 1 msb addr gt gt 9 page addr gt gt 16 amp Oxfe transferCount lent
2. fclose fp netserver main function ey main int policy struct sched param param pthread t listen thread id send thread id filter thread id pthread attr t attr ThreadCtl NTO TCTL IO 0 Enable this process and it s threads to access the computer hardware This is not required to access the AD Card since it is taken care of using the pcm3718 device manager However this is needed if you are controlling I O ports Initialize the servo controller on Com port 1 if servosservo open dev serl 0 perror servo open pulseprio sched get priority max sched getscheduler 0 1 Select priorities and initialize threads pthread attr init amp attr pthread getschedparam pthread self amp policy amp param pthread getschedparam filter thread id amp policy amp param printf Priority is d n param sched priority pthread attr setinheritsched amp attr PTHREAD EXPLICIT SCHED Create the filter thread param sched priority 12 pthread attr setschedparam amp attr amp param pthread create amp filter thread id amp attr filter thread NULL usleep 5000 Create the Control thread param sched priority 15 pthread attr setschedparam amp attr amp param pthread create NULL amp attr Control thread NULL usleep 5000 Create other non default priority threads here using the 3 lines of code above as a template
3. Figure E 4 MATLAB running rocketclient Make sure the Windows computer and the PC 104 is connected with each other over a local network using either a network switch or a patch cable Now press the connect button in the MATLAB rocketclient program Try pressing the Start AD button the program should behave similar to the one seen in Figure E 4 Numbers should be visible in the first two text boxes on the right side MATLAB automatically saves incoming data in arrays in the MATLAB workspace with names based on the incoming Type IDs lowercase with the characters ID stripped away It is possible to save the MATLAB workspace to file for later use To close the session press the disconnect button and close the window E 6 2 Extending the GUI with a servo controller We will now demonstrate how to add more functionality to the communication system Assume we want to control the position of a servo connected to the PC 104 using MATLAB First we need to add functionality to the program running on the PC 104 Open the header file IDList h on the desktop QNX computer Add a new line in the command section like this Client Commands define ID START AD 1024 define ID STOP AD 1025 define ID SET SERVO 0 1026 lt Add this Line Remark For conformance make sure all Type IDs start with ID As discussed previously the communication protocol supports means of transferring the Type ID names a
4. Create the other threads pthread create NULL NULL ignition thread NULL usleep 5000 pthread create NULL NULL tcpsending thread NULL usleep 5000 pthread create NULL NULL Logging thread NULL usleep 5000 pthread create amp listen thread id NULL tcplistening thread NULL Wait until Listen thread terminates Wait forever pthread join listen thread id NULL 128 G 8 netclient c G 9 netclient c include stdio h include stdlib h include errno h include string h include netinet in h include sys socket h include netdb h include lt sys wait h gt include pthread h include lt sys mman h gt include inttypes h include sys ioctl h include lt sys types h gt include lt sys stat h gt include fcntl h include sched h include time h include unistd h include stddef h include IDList h define PORT 6322 the port client will be connecting to define KEEPALIVEPORT 6323 Port for Keep alive data define MAXDATASIZE 100 max number of bytes we can get at once define MAXSENDSIZE 200 static int clifd nsec maxnprobes nprobes channelid const char HeaderStart 3 0xFF O0xFE O0xFE void Heartbeat thread void arg int sockfd connect on sock fd struct hostent he struct sockaddr in their addr server s address information struct time
5. chid_send memset buffer 0 sizeof buffer if numbytes recv clifd recvbuffer 80 0 lt 0 if numbytes 0 printf Connection lost n close clifd break else if numbytes 1 perror server break else numbytes gt 0 ptr recvbuffer recvbuffer numbytes N0 maxptr ptr tnumbytes printf Received d bytes of data n numbytes while ptr lt maxptr While there is still data left in buffer index 0 Skip ahead to beginning of packet header while ptr HeaderStart index amp amp ptr lt maxptr ptr if ptr maxptr printf Error continue Data packet received but no Packetheader was found Check for correct packetheader 130 G 8 netclient c whil ptr HeaderStart index amp amp ptr maxptr Ttptr if index sizeof HeaderStart break if index sizeof HeaderStart printf Error Data packet received but no correct Packetheader was found continue if ptr lt maxptr 2 We got Packet ID memcpy PacketID asChar ptr 2 ptrt 2 switch ntohs PacketID asUintN THIS IS THE INCOMING PACKET ID INTERPRETER Add your new ID packet interpreters here x x x default printf ID d tValue s n ntohs PacketID asUintN ptr b df Switch If we got packet id else printf Error Data packet received but no Pac
6. qcc netserver c o netserver 1 lib libsocket so We now need to transfer the compiled program netserver to the PC 104 using ftp or sftp see appendix D Remark If the old netserver program is running on the PC 104 we need to close it first by pressing Ctrl c If Ctrl c is pressed while there is an open TCP IP connection it is no longer possible to restart the netserver program until a system reboot has been performed This is a known issue with QNX 6 2 Now go back to the MATLAB environment If running close the rocketclient program and then type guide rocketclient T A new window will open as in Figure E 5 We are now ready to add new components to the GUI rocketclient ET File Edit View Layout Tools Help am E Gar Connect Start AD Channel 0 Disconnect Channel 1 Channel 2 ERN Figure E 5 Guide Window From the menu to the left drag and place a pushbutton and a text box into the GUI area fairly close to each other see Figure E 6 Double click the new pushbutton a property window should appear Find the property name String and replace the text with Set servo Then find the tag name and change it to pushbutton4 Finally close the property window Now double click the edit box Again find the property String but this time replace it with 0 Next find the tag and make sure it is called edit4 Close the property window then click save and close the Guide w
7. else other messages There is only one type of message that can be received by this thread Connect to the filters message channel chid2 ConnectAttach ND LOCAL NODE msg channelinfo pidid msg channelinfo channelid NTO SIDE CHANNEL 0 if chid2 1 Cannot open channel if runmode SILENT fprintf stderr PCM3718 Error attaching channel n status 1 else status 0 filterattached 1 Filter is now attached MsgReply rcvid 0 amp status sizeof status if runmode VERBOSE printf PCM3718 Shutting down Copy thread n InterruptDetach int id timer delete timer id if chid 1 ChannelDestroy chid if chid2 1 ConnectDetach chid2 this is the ISR const struct sigevent isr handler void arg int id Mask the interrupt to prevent the kernel from getting the same interrupt again InterruptMask IRQ5 1 out8 dev iobase PCM3718 CLRINT 0 Clear Interrupt return amp intevent 106 G 7 pcm3718 c fkkk xkxxx x k k k k Device Manager functions N X XXX kk ok kk ke ke ke ke e ke X x x f int handle devctl resmgr context t ctp io devctl t msg RESMGR OCB T ocb int io devctl resmgr context t ctp io devctl t msg RESMGR OCB T ocb int nbytes ret previous retstatus chid2 USE_ IRON double speed union channel setup data t chdata double uint pacerdata atta
8. Wait forever 896 Column 1 f Buffer 2 main Figure D 3 Photon Editor D 2 2 Compiling C programs The C compiler in QNX 6 2 is called qcc It is a wrapper executable for the Gnu C compiler gcc Gcc users will have no problems using qcc since the usage of the two compilers is equivalent Below is an example of a normal compilation command qce netserver c o netserver l lib libsocket so The program above utilizes an external library If possible use so libraries since they are dynamically linked libraries generate small executables To learn more about the C compiler find a good reference on the gcc compiler D 2 3 Using a remote terminal to access a QNX computer QNX computers only require the user to be physically present when working with a graphical environment For text or terminal mode it is possible to work from a remote connection The most common remote terminal program is called telnet and is installed on almost any platform Another program is called ssh Unlike telnet ssh uses an encrypted secure session Openssh a free ssh program has been installed on both the desktop QNX computer as well as the PC 104 computer To start a session from the desktop computer to the PC 104 type ssh 169 254 13 200 or connect The latter is just an executable macro found in the root directory containing the prior line 64 D 2 4 Copying files between two computers using ftp Almost any comp
9. FILTER PULSE CODE The driver has notified us that it is now safe to go get some data memcpy buffer dmabuf bufsize get the raw data pthread rwlock wrlock amp ad data rwl Convert the raw data into actual voltages for ptr buffer ptr bufferend ptr t 2 125 G 8 netserver c channelnr ptr amp 0x0f intval unsigned short ptr 1 4 ptr 4 dval intval 4096 0 rangevalues channel setup data range channelnr if polartype channel setup data range channelnr BIPOLAR dval rangevalues channel setup data range channelnr 2 ad data channel channelnr alphal dval alpha2 ad data channel channelnr pthread rwlock unlock amp ad data rwl Else some other thread is trying to send some message event command else if msg pulse code COMMAND PULSE CODE switch msg pulse value sival_ int case ID START AD if AD is running devctl card fd DEVCTL AD START NULL 0 NULL AD is running 1 break case ID STOP AD if AD is running devctl card fd DEVCTL AD STOP NULL 0 NULL AD is running 0 break else if msg pulse code SHUTDOWN PULSE CODE break else other messages hf tor loop if munmap dmabuf bufsize 1 printf CLIENT Error releasing shared memory in pthread cleanup pop 1 Ignition Thread Once the hardware is ready this thread should contain a
10. Field Effect Transistor FFT Fast Fourier Transform FTP File transfer Protocol GUI Graphical User Interface 1 0 Input Output IDE Integrated Device Electronics IMU Inertial Measurement Unit IRQ Interrupt Request ISA Industry Standard Architecture LAN Local Area Network OS Operating System PC Personal Computer PCI Peripheral Component Interconnect PID Proportional Integral Derivative PWM Pulse Width Modulation RAM Random Access Memory R W Lock Read Write Lock SBC Single Board Computer SCP Secure Copy Protocol SDRAM Synchronous Dynamic Random Access Memory SSH Secure Shell TCP IP Transmission Control Protocol Internet Protocol TTL Transistor Transistor Logic WLAN Wireless Local Area Netwo vi Table of Contents b Introduction codes oe ia Dni eese pat telae esos M Uns etit Uu au gee sir cM pte 1 1 1 R ck t TOQUISS cre lau ciat di nchaluasslcaneed se lap ieit e a eti cepe Man Desc neq ep iUd 1 1 1 1 Rocket castigo c eon rete DA edi a ED TERES d A ae Nadas TE UA ed poA iis 1 1 1 2 Hybrid POCKET MOtOr yore Sanne rode ser eodein ve Sea a vastus tues Sass ded o 2 1 1 3 Inertia measurement 011 tee te umb he e eee esto tee cle aas 2 1 1 4 Attitude and guidance system eie reete rte eere eri rae decus 2 1 1 5 Power supply esurire sitet t e A A E ba umb uate 2 1 1 6 JENE TDL AE R EE A AE E E E OP 3 We PrODIGITESOHWDOEN S esee E E ed etse dE E 3 1 2 1 Propulsion C
11. int numbytes ID t PacketID memcpy buffer HeaderStart sizeof HeaderStart buffert sizeof HeaderStart numbytes sizeof HeaderStart PacketID asUintN htons ID memcpy buffer PacketID asChar 2 puffert 2 numbytes t 2 sprintf buffer 09 6f dvalue numbytest strlen buffer 1 buffert strlen buffer 1 return numbytes TCP IP sending thread Sends data to the client This thread is basically a huge message handler It waits for messages from either other threads or timers It then sends data to the client using tcp ip The type of data depends on what message was received ird void tcpsending thread void arg 121 G 8 netserver c int r value rcvid numbytes nsend i struct sigevent send timerevent struct itimerspec send itime timer t send timer id MSG msg char sendbuffer MAXSENDSIZE char ptr ID t PacketID Create a comm channel so other threads and timers can send message to this thread channelid send ChannelCreate 0 This is how you typically initalizes a timer in QNX send timerevent sigev notify SIGEV PULSE send timerevent sigev coid ConnectAttach ND LOCAL NODE 0 channelid_ send NTO SIDE CHANNEL 0 send timerevent sigev priority sched get priority max sched getscheduler 0 send timerevent sigev code TIMER PULSE CODE timer create CLOCK REALTIME amp send timerevent amp send timer i
12. void Control thread void arg File logging thread This thread demonstrates how a file logging tread can be constructed ur void Logging thread void arg struct sigevent timerevent struct itimerspec itime timer t timer id struct clockperiod clockp oldclock di I int channelid ignition rcvid MSG msg char buffer 80 FILE fp char ptr fp fopen logdata w channelid ignition ChannelCreate 0 timerevent sigev notify SIGEV PULSE timerevent sigev coid ConnectAttach ND LOCAL NODE 0 channelid ignition NTO SIDE CHANNEL 0 timerevent sigev priority sched get priority max sched getscheduler 0 timerevent sigev code TIMER PULSE CODE timer create CLOCK REALTIME amp timerevent amp timer id itime it value tv sec itime it interval tv sec 1 itime it value tv nsec itime it interval tv nsec 0 timer settime timer id 0 amp itime NULL for rcvid MsgReceive channelid ignition amp msg sizeof msg NULL if rcvid 0 we got a pulse if msg pulse code TIMER PULSE CODE pthread rwlock rdlock amp ad data rwl ptr buffer for i 0 i lt 2 i sprintf ptr Channel d 9 6f r n i ad_data channel i ptr strlen ptr 127 G 8 netserver c sprintf ptr r n pthread rwlock unlock amp ad data rwl fprintf fp buffer fflush fp
13. 0 sizeof resmgr attr resmgr attr nparts max 1 resmgr attr msg max size 2048 initialize functions for handling messages iofunc func init RESMGR CONNECT NFUNCS amp connect funcs RESMGR IO NFUNCS amp io funcs initialize attribute structure used by the device iofunc attr init amp attr S IFNAM 0666 0 0 attach our device name id resmgr attach dpp dispatch handle amp resmgr attr resource manager attrs dev PCM3718 device name FTYPE ANY open type 114 G 7 pcm3718 c 0 flags amp connect funcs connect routines amp io funcs I O routines amp attr handle if id 1 amp amp runmode SILENT fprintf stderr Ss Unable to attach name n argv 0 return EXIT FAILURE Register all custom made function to handle device calls io funcs io funcs devctl io funcs write io funcs connect funcs open RE close ocb io close io devctl For handling IO DEVCTL sent by devctl io write io read io open Ei read runmode SILENT printf PCM 3718 Device started n printf Settings used Wn printf B printf printf IRQ printf T alloca ctp start while 1 Re CtP fprintf s return EX dispatch DMA channel printf Internal Clockspeed ase adress xh dev iobase od dev dma channel sdHz d
14. DISABLE dev dma_channel if runmode SILENT printf PCM3718 Releasing DMA memory n if munmap dev dmabuf dev buflsize 1 amp amp runmode SILENT fprintf stderr PCM3718 Error releasing mapped memory Nn if munmap dev shmem_ area dev shmem size 1 amp amp runmode SILENT fprintf stderr PCM3718 Error releasing shared memory n if shm unlink SHM NAME 1 amp amp runmode SILENT fprintf stderr PCM3718 Error unlinking shared memory Nn if oldclock nsec 0 START AD has been called ret ClockPeriod CLOCK REALTIME amp 0ldclock NULL 0 if ret 1 amp amp runmode SILENT printf Error resetting clockperiod n RESET ALL DEVICE PARAMETERS TO DEFAULT VALUES x x x x x base dev iobase dma dev dma channel clk dev CLK speed irq dev IRQ trate dev transfer rate memset amp dev 0 sizeof dev Reset Entire Device structure Reload constant parameters dev iobase base dev dma channel dma dev CLK speed clk dev IRQ irq dev transfer rate trate rwmode RWMODE DIO1 if runmode SILENT printf PCM3718 Connection closedin Reset the state vector status device open 0 status dma set 0 status channel set 0 status pacer set 0 status ad running 0 status filter attached 0 return iofunc close ocb default ctp msg ocb The io read function handles read function c
15. Initailizes the DMA Buffers 102 G 7 pcm3718 c int PCM3718 setupBuffers int speed fd These three lines calculates how many shared memory buffers you can fit into a block of 65536 bytes speed dev CLK speed double dev Cl dev C2 dev shmem size int speed dev transfer rate 2 dev buflsize 65536 65536 dev shmem size Start allocating memory if dev dmabuf mmap 0 dev buflsize PROT READ PROT WRITE PROT NOCACHE Allow the Kernel to map memoryspace which is accessable by the DMA Controller MAP PRIVATE MAP PHYS MAP BELOW16M MAP ANON MAP NOX64K NOFD 0 MAP FAILED if runmode SILENT perror PCM3718 abort DMA buffer allocation OK now create the shared memory area shm unlink SHM NAME Unlinks any previously linked memory areas if d shm_open SHM NAME O CREAT O RDWR O EXCL 0770 1 if runmode SILENT perror PCM3718 close fd abort Expand the memory area to desired size af shm ctl fd SHMCTL GLOBAL SHMCTL ANON 0 dev shm m siz 1 if runmode SILENT perror PCM3718 close fd shm unlink SHM NAME abort map the shared memory area if dev shmem area mmap NULL dev shmem size PROT READ PROT WRITE PROT NOCACHE MAP SHARED fd 0 MAP FAILED if runmode SILENT perror PCM3718 close fd shm unlink SHM NAME abort close fd
16. It provides a graphical interface where systems are built using blocks and connections With none or little modifications we implement our equations as Simulink blocks It is advantageous to represent our system in state space form since this is more suitable for computer implementation The states used are x 0 Xo cur y 76 y 0 a 4 42 z 0 Z 0 a The input signals are the general moments of inertia Mx M and M which in some sense represent the physical relationship with the moving fins placed on the rocket body and the torques they induce on the body itself Unfortunately we are not able to describe this relationship using an analytical formulation Instead we have to rely on wind tunnel tests with the rocket once it has been assembled or finite element simulations When this relationship is better understood it is possible to add it to the model For now we leave these inputs as is and simply refer to them as input signals Uy U and U respectively Using 4 32 and 4 42 we can formulate the state space representation X X He 22 ES i a ds dt 1 d A X y I U a X EE Ia z I a2 4 43 Xy l 1 d Z Z3 Z5 x I v E I f 7 Tz 25 Again the x y and z axes are the roll pitch and yaw axes respectively Also we assume the moments of inertia to lie along the principal axes and that they form an orthogonal system with the x axis i e y Le 4 6 1 Moments of inertia estimator
17. Parachute 1 1 1 Rocket casing The casing of the rocket will consist of a lightweight fibre structure A group of students within RMRL are conducting research in the field of autonomous fibre placement The work is based on a robot arm which automatically places fibres in desired patterns Layers of carbon fibre and epoxy resin are used for forming different geometrical shapes The robot can be seen in Figure 1 1 a in the process of placing fibres onto a cylinder One such cylinder with the appropriate dimensions can be used as rocket casing b Figure 1 1 a robot arm placing fibres onto cylinder b close up of fibre structure 1 1 2 Hybrid rocket motor In a solid propellant rocket motor the propellant and oxidizer are placed in the same container Both are shock sensitive and once fired there is in principle no means for controlling the thrust rate These problems are overcome when using liquid bipropellant motors instead which require separate storing of the propellant and oxidizer resulting in a complex and expensive system The hybrid rocket solution utilizes a solid propellant with a liquid oxidizer It eliminates the shock sensitivity associated with high performance solid propellants by separating the fuel and oxidizer until the firing of the motor The thrust is terminated with the flow of the liquid oxidizer The hybrid rocket motor is simpler than a liquid bipropellant rocket motor but not as simple as a convention
18. numbytes send servfd sendbuffer nsend 0 printf sent IDName with d bytes of data n nsend PacketID asUintN htons ID_IDNAMECOMPLETE ptr sendbuffer strcpy ptr HeaderStart ptrt sizeof HeaderStart memcpy ptr PacketID asChar 2 ptrt 2 ptr 0 nsend int ptr sendbuffer 1 numbytes send servfd sendbuffer nsend 0 printf sent IDNameComplete with d bytes of data n nsend break All the commands above didn t use any parameters except for the fact that a certain event has occured In order to pass more than one parameters to COMMAND PULSE CODE commands you must use the Command data shared memory resource It should be the listen threads job to package the data into this memory area case ID SENDDATA This command sends the transmission package placed in the Command datameory area pthread rwlock rdlock amp Command data rwl PacketID asUintN htons Command data id ptr sendbuffer strcpy ptr HeaderStart ptrt sizeof HeaderStart m p S p emcpy ptr PacketID asChar 2 tr 2 trcpy ptr Command data buffer thread rwlock unlock amp Command data rwl ptr strlen ptr nsend int ptr sendbuffer 1 numbytes send servfd sendbuffer nsend 0 break else other messages ff fort Mutex destroy function 123 G 8 netserver c Called by the filter t
19. we cannot represent the reference voltage exactly regardless of resolution used The converter in this project uses 12 bits rather than 8 bits A 12 bit word has 4096 unique values thus giving the 12 bit converter 16 times the resolution of the 8 bit converter for the same input range 54 B Implementing a PID controller In theory feedback control systems are often easily implemented In reality however the situation is often more problematic In this chapter we try to present some hints and guidelines for how a feedback controller should be implemented taking into consideration the physical limitations of the controlled system We do not want to make the discussion lengthy and will therefore only consider the PID controller Some of the techniques shown here also apply to the state space controller A PID controller is simplest described by the block diagram found in Figure B 1 The control law U is U P I D where P I and D are the three parts of the PID controller The reference is y and the three parameters for the controller are K T and T4 Process Figure B 1 Classic PID controller B 1 Limiting the derivative Assume the reference y follows a step function i e it changes from one value to another during a very short time period In the controller the derivative at the time of reference change can become very large This can disturb the controller to such a degree that it makes the system become unstable The pro
20. 4 9 The internal structure of the controllers is shown in Figure 4 14 We also replace the names of the control signals x y z to Roll Pitch and Yaw respectively A number of new Simulink scopes have also been incorporated into the model see Figure 4 13 Radians to Degrees2 Yaw angle Radians to Degrees Fitch angle Inertial frame Radians to Degrees Roll angle Goto1 Figure 4 12 Transformation to inertial frame i p x2 calculator Omega_x Roll Control signal Rocket Mass Goto4 Omegs_y Inertia estimstor y2 calculstor Lig R2D3 Pitch error Pitch Reference Pitch control signal Goto5 Omega z PID controller1 From11 z2 calculator E i Yaw control signal Ws R2D4 Yaw error Yaw Reference PID controller2 From12 Figure 4 13 PID controlled model with pitch and yaw controllers Integrator Td Derivative Figure 4 14 Internal structure of PID controller 44 We now want to find out if the system shown above in Figure 4 13 is controllable i e if it is at all possible to have separate controllers for each axis even though the system properties are clearly interconnected through cross coupling see 4 32 In our first test we neglect the cross coupled effects of the angular velocities as in section 4 6 4 We thus set the control signal for the x axis to zero Then by tuning the PID parameters we can analyze the step
21. 4 shows the relation between hardware and software in a similar manner as in Figure 3 2 Control Algorithm Servo Control Interface Inertial Measurement T o System Servo Controller Software Hardware Figure 3 4 Attitude amp guidance subsystem 3 3 3 Propulsion control The propulsion control system performs opening and closing of the solenoid valves as well as the on off switching of a glow plug In future designs advanced thrust control will require partial opening of the valves This feature will however not be implemented in this project Valve control cannot be performed directly from the PC 104 but requires electronic components that perform the actual switching We will discuss later how such control circuits can be constructed but let us for the moment assume that we have some switching electronics connected to a digital port of the PC 104 Then from a software perspective the state control of the digital port along with the switching electronics makes up the propulsion controller The high level upper layer of Figure 3 1 propulsion control algorithm can then be instructed to open and close whatever valves necessary 14 Propulsion Control Algorithm Propulsion Control Interface Software Digital Switch Electronics Solenoid Valves Glow plug Figure 3 5 Propulsion subsystem Hardware 3 3 4 Data storage amp communication Inertia
22. A simple method for estimating the moments of inertia is to assume the mass distribution to be homogenous in some simple geometric shape For a rocket a solid cylinder or a solid cone might be a good choice Although the rocket does not resemble a cone by shape its mass distribution can be assumed to have a different form than its physical shape This is especially useful when the cylindrical objects do not have a symmetrical distribution of mass This technique is often used in robotics McK91 Considering the density of the rocket motor and its propellant it is probable that the centre of mass will lie closer to the motor itself rather than at the geometrical centre of the rocket For this reason we will consider both the solid 39 cylinder and the solid cone as possible descriptions of the mass distribution From tables we find the moments of inertia around the centre of mass for a cylinder cone with mass m radius r and length Solid Cylinder ic mr 2 E p 4 44 1 zr 2 is 4 12 Centre of mass 2 Solid Cone l Bd En 4 45 I 1 mr ml 20 80 Centre of mass 4 Using these equations we can create two different block components in Simulink see Figure 4 6 We let the mass m be an input signal to the block subsystem representing the current mass of the system In order to include cross coupling in the model we also pre calculate the two terms I and Izz see 4 43 Gain2
23. ATTACHFILTER Parameter type attach message t defined in pcm3718 h Description For the device driver to send messages to a thread in the client program the client first needs to send enough information to the driver so the driver can find it later This is done by sending an attach message t structure to the driver Unlike all other control commands the device driver gives a reply to the calling thread telling it where to find the raw data and its corresponding size The attach message t union is big enough to fit both the message and the reply The device driver synchronously copies data into the shared memory area accessible by the client and notifies the client by sending a pulse This requires that the calling thread has created a message channel that the pulse can be transmitted in before issuing this command Example attach message t fm int channel id fd unsigned char rawDataBuffer The raw data memory area channel id ChannelCreate 0 fm data channelid channel id fm data pidid getpid devctl card fd DEVCTL ATTACHFILTER amp fm sizeof fm NULL fd shm open fm reply shm name O RDWR 0770 rawDataBuffer mmap NULL fm reply size PROT READ PROT NOCACHE AP SHARED fd 0 F 2 6 DEVCTL AD START Parameter type None Description Starts the onboard pacer which commences the A D conversion This command can only be issued after the following commands have been previously is
24. G 8 netserver c if nprobes gt maxnalarms printf Server Client not responding Nn close heartbeat fd close HBsockfd At this point the client is considered non responding What shall we do about it return break default if n recv heartbeat fd amp c 1 0 lt 0 close heartbeat_ fd close HBsockfd return nprobes 0 send heartbeat fd amp c 1 0 close heartbeat fd close HBsockfd TCP IP cleanup function Note These cleanup functions only gets called when calling ThreadCancel Or if the thread shuts down itself In other words this code is not used However they might become useful at a later stage oy void Listen Cleanup void arg close servfd close sockfd printf Listen thread shutdown correctly n usleep 2000 TCP IP listening thread Receives data from the client over TCP IP network The thread first initializes the TCP IP protocols and binds itself to a network port waiting for incoming connections Then it simply blocks itself on a recv command in an infinite loop When data has been received the QNX OS automatically unblocks the thread and it processes the data before blocking itself again x void tcplistening thread void arg struct sockaddr in my addr my address information struct sockaddr in their addr connector s address information int sin siz
25. GUIDATA oo varargin command line arguments to rocketclient s VARARGIN 9 Choose default command line output for rocketclient handles output hObject set hObject CloseRequestFcn rocketclient_ClosingFcn handles The lines below creates the ActiveX control RocketNetworkProxy The handle COMh is used as a calling handle when issuing commands to the control The size of the window is 350 by 198 pixels starting 40 pixels up and 40 pixels to the right from the lower left corner of the client window AP o0 oe oe oo 133 H 5 rocketclient m The registerevent command registers th venthandlers used by the client handles COMh actxcontrol RocketNetworkproxy InDataControl 40 40 350 198 registerevent handles COMh datarecvd DatarecvdHandler connectionstatus ConnectionstatusHandler ping KeepAliveHandler handles connected 0 9 Update handles structure guidata hObject handles function rocketclient ClosingFcn hObject eventdata handles if isfield handles COMh if handles connected invoke handles COMh Disconnect end unregisterallevents handles COMh delete handles COMh end delete hObject evalin base clear apphandles Outputs from this function are returned to the command line function varargout rocketclient OutputFcn hObject eventdata handles varargout cell array for returning output args see VARA
26. I zz Figure 4 6 Inertia estimator The gains found in Figure 4 6 are set to E for the cone Gainl x 5 r for the cylinder C T 2p for the cone Gain2 o 80 r ES P for the cylinder 12 The output from this block is the moment of inertia based on the current mass This may be used by the rest of the system 40 4 6 2 Angular velocity estimator Next we study the Simulink blocks calculating the states x y and z2 or x and c For x2 there are no cross coupled terms since we assumed that 7 and Z are equal The time derivative of x2 from 4 43 can thus be stated as X v 2 4 46 Derivative dThets dt Product x2 Figure 4 7 Angular velocity estimator without cross coupling U and are both external signals U is the torque acting on the axis is the corresponding moment of inertia The output is obtained after the integrator with output x For the y and z axes the angular velocities depend on the cross coupled terms These are included in the respective estimators An overview of the block calculating y is shown in Figure 4 8 In order to reduce the number of crossed wires the model uses Goto and From blocks allowing information to be transferred between the estimator subsystems Derivative dThets dt Product Integrator Figure 4 8 Angular velocity estimator with cross coupling 4 6 3 Assembly of model We are now able to assemble our physical model As input to
27. ID SET SERVO 0 IDENTRY ID OPEN VALVE 0 s e rir MEE Add this line IDENTRY ID CLOSE VALVE 0 be enone END IDMAP Save and close the file Now open netserver c and find the Type ID interpreter inside the Listen thread Add two new case statements adding control of parallel port output pin 2 case ID OPEN VALVE SetPPin PIN2 1 break case ID CLOSE VALVE SetPPin PIN2 0 break Save and compile the file Then start it on the PC 104 computer Now go back to the machine running MATLAB and start Guide again by typing guide rocketclient Add two new buttons and edit their text strings to read Open valve and Close valve as in Figure E 9 Also set appropriate tag names The tag names in this example are pushbutton8 and pushbutton9 respectively Save and open rocketclient m and locate the code for the new pushbuttons Add the following line for the pushbutton8 callback function invoke handles COMh SendCommand ID OPEN VALVE 0 and to the pushbutton9 function add invoke handles COMh SendCommand ID CLOSE VALVE 0 Remark When invoking the SendCommand method in the proxy we must give both a Type ID and a corresponding data string as parameters If extra data is not required as seen above we simply add an empty string rocketclient fig File Edit View Layout Tools Help eB Ag gt Connect Start AD CeO Disconnect
28. MINAVAIL 2 Send to a thread to safely shut it down define RESET PULSE CODE PULSE CODE MINAVAIL 3 Resets the state of a running thread usually to a non active state define FILTER PULSE CODE PULSE CODE MINAVAIL 4 Used by the PCM3718H driver to inform the thread that filter data is ready for retreival define COMMAND PULSE CODE PULSE CODE MINAVAIL 5 Sent by the Listen thread to other threads when relaying client commands 94 G 5 servocontrol h f kc kx e ke e e e x Servo control functions Ck ckckckck ck kok ck ok sk ke ke ke ke e ke v x f include lt termios h gt Opens the serial servo controller 9600 baud Input devicename a string containing the device to open for example dev serl Output A file descriptor to the servo controller or 1 on an error ii int servo open const char devicename imt fd struct termios tio if fd open devicename O RDWR 0 return 1 cfmakeraw amp tio tio c cflag amp IXON IXOFF tio c cflag CLOCAL CREAD tio c cflag amp PARENB tio c cflag amp CSTOPB tio c cflag amp CSIZE tio c cflag CS8 cfsetispeed amp tio B9600 cfsetospeed amp tio B9600 tcsetattr fd TCSANOW amp tio memset amp tio 0 sizeof tio tcgetattr fd amp tio if cfgetispeed amp tio B9600 return 1 return fd Sets the servo position of a servo Input i fd
29. OxDO define USE IRQ6 OxEO define USE IRO7 OxFO0 For Internal software use define IRQ2 2 define IRQ3 define IRQ4 define IRQ5 define IRQ6 define IRQ7 1 o0 01 5 QC Card control modes define USE PACER 3 define USE SOFT 0 define USE DMA 4 Read Write modes define RW ODE DIO1 0 define RW ODE DIO2 1 define RW ODE ANALOG 2 Name for shared memory area define SHM NAME dev shmem pcm3718 Resource manager run modes define VERBOSE 2 define NORMAL 1 define SILENT 0 Types used when setting up the range of the A D card typedef enum BIPOLAR 5V BIPOLAR 2 5V BIPOLAR 1 25V BIPOLAR 0 625V 96 G 6 pcm3718 h UNIPOLAR 10V UNIPOLAR 5V UNIPOLAR 2 5V UNIPOLAR 1 25V BIPOLAR 10V Rangetype Struct filled by client when setting up the A D card typedef struct devctl channelstruct unsigned char start stop The A D converter starts converting the start channel then for each conversion The converter automatically inrements the current channel by 1 After convering channel stop it automatically starts at channel start again Rangetype range 16 See Rangetype above Note that only the channels between start and stop needs to be fiiled 16 channels is the maximum number of available channels channel setup data t struct used to hold the two numbers used to set the internal pacer clock typedef struct unsi
30. SEE Ex Channel Channel 2 Open valve Close valve Channel 3 EENE Figure E 9 Guide window with added valve controls 8l Save the file and start the program After pushing the connect button it should be possible to remotely control the valve Remark The large text window at the bottom left of the GUI does not get displayed in Guide The window is the Proxy program and since it is not a part of MATLAB it does not materialize until the MATLAB program gets started When designing the GUI make sure to leave enough space for this window to appear and do not place any components inside its area since it will be impossible to access them later 82 F Data acquisition software driver To measure electrical signals the PC 104 computer has been extended with a data acquisition card The card used is of model PCM 3718H manufactured by Advantech Co Ltd A software driver or resource manager has been developed for the QNX 6 2 OS as part of this project The driver follows the QNX 6 2 guidelines for device driver development and implements the following features 12 bit A D conversion Software A D conversion polling A D conversion using onboard pacer and DMA transfer Up to 100 000 samples per second without loss of data 16 bit digital input output Data transfer synchronization with client F 1 Starting the driver The device driver can be started from the console or during system boot The DAQ card can be set up in a
31. a remote computer over the Internet or a local area network The Listen thread receives and acts upon incoming data such as commands sent by an operator 6 TCP IP Send thread Like the Listen thread the Send thread uses TCP IP as communication method It sends feedback data to the remote computer for operation maintenance and analysis 7 Heartbeat thread This thread also uses TCP IP It sends and receives connection status data in order to prevent data loss 8 Startup thread For a real time program to become multithreaded it must begin as a single thread This thread is the C programs main function It basically starts all other threads and then waits indefinitely allowing the other threads to utilize the CPU 68 E 3 Data interchange As stated earlier all threads in a process share the same memory Figure E 1 shows how this memory model is used to transfer measurement data between threads The Raw data a memory area shared between the data acquisition software driver and the Filter thread is converted to meaningful values by the filter These values are placed in a separate memory area Measurement data located inside the process the netserver program for global access by other threads in the process program netserver program Attitude and Raw data guidance control Remote Computer Measurement data area Data acquisition card File logger TCP IP Li
32. estet aea e raa eanta ec ign 83 BQ Controtling the DACOE Qatd a eR OE E E o gie EEEE e iuge 84 F 2 1 DEVCETLSETCHANNE D ee ate a dd a et s a p et Ed 84 E22 DEVCTE SETPACER carta regs teta n as la e tad tan e std etu n petra 85 p 2 3 DEVCTL SET TRANSFER RATE itesccseciedars acarvin Ata rto adios eee d e Ree it 85 F 2 4 DEVETE IMS EN EDS eei notet s ode e e Ree PE Ret sce a 85 F 2 5 DEV GT ATTAGHRAILTER nyororo eat ta aD E DI e tut 86 F 2 6 DEVCTL AD START iouis die io ciiise td dh e rv aides eias 86 F 2 7 DEVCTE AD STOP oia a a EA R E EAE E popali 86 F 2 8 DEVCTE SET READNIODE 5 datus quaa R R REE 87 Go SOULCO DOO ossa testet edt emu tee id et uu ae die e M 89 oEMEE ur WI 90 G2 IDEE coiere de ee da ead earpiece renew tnb au e dae 9 9 7 30D PS Doc oboe ores QU tn esu das a Sota stel dibus tede bte oon a ue 93 3 4 pulsegodes Tic asiento hu educta urs dtu ct tarde ean tes 94 G5 SOEVOCODIEOL herori oinaan it dede diodes Adee ae heetins 95 er ME cubIE E doe eE 96 Ej JSDORISIS 8 siet Nee de UAM ue Eu DRE eM CLE MEE ae 99 C Se NetServer O menee cce Son oi etate xcu tete Sos ce d eto AUS 116 G AVE diano EL RT 129 H Matlab Codes ade iir tec to sete obe dr sts eater eio dE te e direi 133 El AAT ACA MID S d eon t tete desineret in ese sas tebe a a fe Verte uen anus 133 H2 jEeepalivelandlemtus au ioc hern Su eai uud veste aded eru Rs 133 H3 ConnectionstatusHandlerim eiecti eVendi eC ne oce i Ehe a Rene e
33. fixed to the aircraft Vae to the inertial axes Vinertial 1S V Inertia ZYX Vale 4 4 1 By solving for vx vy and v in the inertial frame and integrating the absolute displacement of the rocket may be obtained 4 5 3 Relationship with the IMU The inertial measurement unit uses the mathematics described in the section above for deducing the attitude and position relative to the inertial axes Three accelerometers measure acceleration in each of the principal directions of the aircraft and three gyros monitor e and The transformation and integration concerning the position as well as the attitudes should be performed by the inertial measurement algorithm mentioned in section 3 3 1 Previous research and algorithm design have been performed for the IMU system 38 4 6 Dynamic modelling using MATLAB Simulink Let us now return to section 4 4 where we formulated the equations of motion for a system of non constant mass with six degrees of freedom Equation 4 32 In this section we concentrate on the equations for the moments of inertia aiming at a model of the dynamical behaviour of the rocket attitude In order to better understand the dynamics we need to perform computer simulations and analysis using numerical software For this purpose the MATLAB software suite was used It incorporates a dynamic modelling environment as well as sophisticated tools necessary for this type of analysis The modelling environment is called Simulink
34. generated by another thread When such events occur the acting part sends a pulse to the thread or threads that is dependent on the event A thread waiting for the event then wakes up and performs the appropriate action Note that a thread can wait for multiple events simultaneously If two pulses should arrive at the same time say from a timer as well as some event generated in another thread then the priority of the pulse determines the order of action Pulses have priorities between 1 and 63 exactly the same way as the threads All threads in Figure 3 11 are event driven most of them use timers except the Listen and Heartbeat threads which both of them listen for incoming data on the network link in a way making them event driven as well but they listen for external events rather than internal events 3 5 3 Proposition for a final design The layout found in Figure 3 11 was used for this project As we have previously stated this layout is not final The program is only partially implemented and many more hours of work are needed until it will be complete As a final remark the thread layout of the complete program will be discussed below First assume that we expand the attitude control thread into three separate threads Since the three control threads will literally fight over the control of the manoeuvre fins we will probably need a separate thread with the task to coordinate and optimize the servo movements Further the final r
35. here should be followed for all programs that uses the QNX PCM3718 driver Clear the memory memset amp channel setup data 0 sizeof channel setup data Create a channel so other threads can send messages to this one channelid filt ChannelCreate 0 Sets the speed to 100Khz assuming a 10 MHz external clock pacerdata cl 10 pacerdata c2 10 channel setup data start 0 Start channel for conversion is 0 channel setup data stop 4 Stop channel for conversion is 4 giving a total of 5 channels for i 0 i lt 15 1i Sets all first 16 channels to the same conversion range Note that only channel 0 4 wil be set by the driver because it uses the start stop parameters as boundaries channel setup data range i UNIPOLAR 10V Open the device if card fd open dev PCM3718 O RDWR 1 printf Server unable to open device manager Mn exit 1 124 G 8 netserver c Prepare info for the driver to wake this thread up fm data channelid channelid filt fm data pidid getpid Now set up the card as desired Pacer speed 100 Khz ret devctl card fd DEVCTL SETPACER amp pacerdata sizeof pacerdata NULL Channel ranges ret devctl card fd DEVCTL SETCHANNEL amp channel setup data sizeof channel setup data NULL Transfer speed 2 KHz ret devctl card fd DEVCTL SET TRANSFER SPEED amp filter speed n E sizeof filter speed NU
36. o ru Q Fl a S a S a S a S a C o 108 G 7 pcm3718 c USE IRON USE IRQ7 break If the current clock period is less than required by the filter adjust it to the required speed ClockPeriod CLOCK REALTIME NULL amp clockp 0 if clockp nsec dev transfer timeperiod if runmode VERBOSE printf PCM3718 Updating Realtime clock period n clockp nsec dev transfer timeperiod clockp fract 0 ret ClockPeriod CLOCK REALTIME amp clockp amp 0ldclock 0 if ret 1 if runmode SILENT printf Error setting clockperiod n return EIO Enable DMA channel out8 SNGL MASK reg dev dma_channel ENABLE dev dma channel Setup PCM3718 card out8 dev iobase PCM3718 CONTROL USE IRON USE PACER USE DMA PCM3718 StartPacer dev Cl dev C2 Start the pacer Start the copy MsgSendPulse channelid sched get priority max sched getscheduler 0 RELEASE PULSE CODE 0 status ad running 1 Update status vector break case DEVCTL AD STOP Temporarily halts A D conversion if status ad running if runmode SILENT fprintf stderr PCM3718 cannot stop ad conversion since it s not running Nn return EINVAL if runmode VERBOSE printf PCM3718 Stopping A D conversion n out8 dev iobase PCM3718 CONTROL USE _ SOFT Disable PACER amp DMA am
37. on the data acquisition for two reasons Firstly because no inertial measurement unit was ready for testing and secondly that prior research of the data acquisition hardware was inadequate No software driver for the QNX 6 2 operating system was available which therefore had to be developed 3 4 1 1 Software drivers and resource managers A computer would not be of much use without hardware components connected to it In the case of a PC 104 computer it is the PC 104 bus that extends the system The electrical and 15 functional properties of the PC 104 bus are equivalent to the standard ISA bus found in desktop PCs Computer programs usually never communicate on the bus directly but needs a software driver to which the program sends its requests The driver then interprets these requests and performs the appropriate actions on the card it is assigned to Unlike operating systems such as Linux where drivers are tightly connected to the kernel a QNX driver looks and acts just like any program In QNX drivers can be initiated and terminated at any time while the computer is running which makes it a very flexible OS In QNX the name resource manager is used instead of software driver It will be used for the rest of this chapter As an instructive example Figure 3 6 shows how the resource manager developed for the DAQ card interacts with both the card itself and with programs requesting access to the card The resource manager follows stand
38. response of the yaw and pitch controllers Using the notation of Figure 4 14 the PID parameters is set to K 13 TI 0 7 and Td 0 2 These parameters have been deduced through repeated simulations and produce a satisfactory step response which in turn may be found in Figure 4 15 Examining Figure 4 15 we see that the cross coupling is almost non existent Both the yaw and pitch curves lie on top of each other One can also notice a small roll effect due to the manoeuvres made angle degrees time s Figure 4 15 Model simulation with w 8 1 Uy 0 In order to obtain a better idea of how the controller s would work in a more realistic situation we also perform a stress test of the system Starting at yaw pitch and roll at zero degrees we forced the system into some new position say pitch 45 and yaw 60 We also investigated the effect of a constant torque of typically 10 Nm around the x axis thereby causing roll effects as well acting as a disturbance As we can see in Figure 4 16 the results appear to be quite promising Even though the rocket rolls some 45 degrees neither the yaw nor pitch control signals are affected The overshoot however for both controlled signals increases significantly This is due to the fact that both controllers are performing their manoeuvres simultaneously Increasing the rolling torque around the x axis further causes the system to become unstable after some time of apparen
39. that all words range from 0 to 2 1 where n is the number of bits used for the storage For example the range would become 0 255 if eight bits are being used The most common type of analogue converter cannot fully represent the entire measurement range specified by the manufacturer this is an inherent property of the converter We will show this by an example Suppose we have an 8 bit ADC with input range 0 5 Volts We then have a maximum of 256 unique values for representing the entire interval By dividing the reference voltage by the number of unique values we obtain the resolution 53 re resolution n For a 5V reference the resolution is 5V 256 0 0195V or 19 5mV The 8 bit converter represents the analogue input as a digital word The most significant bit of the word indicates whether the input voltage is greater than half the reference 2 5V with a 5V reference Each succeeding bit represents half the range of the previous bit Table A 1 illustrates this point Adding the voltages corresponding to each set bit in the word 0010 1100 we get 625 1563 0781 859 Volts Table A 1 Digital representation of an 8 bit measurement Bit Bit7 Bit6 BitS Bit4 Bit 3 Bit 2 Bit 1 Bit 0 Volts 2 5 1 25 0 625 0 3125 0 1563 0 0781 0 0391 0 0195 Output Value 0 0 1 0 1 1 0 0 The word 1111 1111 is the number 255 which corresponds to 5 255 256 4 985 Volts Hence
40. the KeepAlive method in order to send these messages to the PC 104 server 74 E 5 5 The GUl interface A simple interface has been created using Guide see Figure E 4 It is called rocketclient and its corresponding source files are rocketclient m and rocketclient fig It comes with three event handlers DataRecvdHandler m ConnectionStatusHandler m and KeepaliveHandler m which handle each of the events in Table E 6 It has connect and disconnect buttons which are invoking the connect and disconnect methods in the proxy Commands are sent to the PC 104 server by adding buttons to the GUI which invokes the SendCommand method Text boxes can also be added to monitor variables of interest such as the autonomous vehicles position velocity and acceleration E 6 Tutorial Using the MATLAB client program To better understand how the communication system works we will demonstrate how to use and expand the MATLAB program First make sure MATLAB 6 5 or later has been installed onto a Windows 2000 or XP computer A Windows NT machine should work as well Also make sure the following files are found in a single folder on the computer ConnectionStatusHandler m DataRecvdHandler m findGuiData m KeepaliveHandler m rocketclient fig rocketclient m RocketNetworkProxy dll E 6 1 Basic operation If running the program for the first time register the dll file by first running cmd Select run from the start menu and type cmd Set the working
41. the filedescriptor obtained from servo open servo An integer containing which servo to move 0 7 pos An integer containing the new servo position 0 254 w void set servo int fd unsigned char servo unsigned char pos int n unsigned char buf 3 0xFF servo pos n write fd buf 3 if n 0 printf write failure n 95 G 6 pcm3718 h G 6 pcm3718 h ifndef PCM3718 define PCM3718 f KK RK e ke e ke e ke e ke e e v PCM 3718H Specific Macros ECKCkck ck ck ck ck ck ck ck ckckckck ck ck ck kk ke x W rite clear INT request define PCM3718 CLRINT 8 R ead return status byte define PCM3718 STATUS 8 R A D high byte W A D range control define PCM3718 RANGE 1 R next mux scan channel W mux scan channel amp range control pointer define PCM3718 MUX 2 R W operation control register define PCM3718 CONTROL 9 W counter enable define PCM3718 PACERENABLE 10 I R low byte of A D W soft A D trigger define PCM3718 AD LO 0 R high byte of A D W A D range control define PCM3718 AD HI 1 R low amp high byte of DI define PCM3718 DIO LO 3 define PCM3718 DIO HI 11 W low amp high byte of DO counters define PC 3718 PACERO 12 define PC 3718 PACER1 13 define PC 3718 PACER2 14 W counter control define PCM3718 PACERCTL 15 IRQ interrupt control values define USE IRQ2 0xA0 define USE IRQ3 OxBO define USE IRO4 OxCO define USE IRQ5
42. the rocketclient handles using the unique tag COMh apphandles hObject findGuidata COMh IDs varargin 3 Values varargin 4 Add value to workspace for i 1 length IDs IDName lower IDs i The name is now in lowercase if IDName 1 3 id IDName IDName 4 length IDName end if evalin base exist IDName evalin base IDName end SIf the data value is a numerical value if length str2num Values i gt 0 evalin base IDName IDName Values i else The data value is non numeric store it in a cellarray evalin base IDName 1 length IDName 1 Values i end SAdd value to GUI if isfield apphandles IDs i if length str2num Values i gt 0 eval set apphandles IDs i String Values i else eval set apphandles IDs i String Values i end guidata hObject apphandles end end 134 H 5 rocketclient m H 5 rocketclient m function varargout rocketclient varargin ROCKETCLIENT M file for rocketclient fig ROCKETCLIENT by itself creates a new ROCKETCLI existing singleton LH NT or raises the H ROCKETCLIENT returns the handle to a new ROCKETCLIENT or the handle to the existing singleton T ROCKETCLIENT CALLBACK hObject eventData handles calls the local function named CALLB
43. to the inertial frame can be calculated using the theory of Euler angles and rotations which we will discuss next 36 4 5 Euler angles Any rotation may be described using three angles If the rotations are written in terms of rotation matrices X Y and Z then a general rotation R can be written as R ZYX 4 33 The three angles needed in the three rotation matrices are known as Euler angles There are several conventions for Euler angles depending on the axes about which the rotations are defined A common way of expressing the Euler angles is the roll pitch yaw convention used as standard practice for aircrafts The three angles are roll pitch 0 and yaw wy which defines the rotations about the x y and z axes respectively FS95 The rotation is expressed in reverse sequence z y x The respective rotation matrices are cosy siny 0 L siny cosy 0 4 34 0 0 1 cos sin 0 Y 0 1 0 4 35 sin cos d 0 1 0 0 X 0 cos sing 4 36 0 sing cos Using standard notation for the elements of a matrix R is defined as rhi Mm Np R 2 r rj r4 4 37 we can express the product R ZYX element by element as follows n cosO cos y r cos Osiny n sin 0 1 sin sin 0 cosy cos sin y hy siny sin sin 9 cos v cos 4 38 h cos Osin d r cos sin 0 cosy sin sin y r4 cos dsin 0 sin y sin cosy 14 cos 0 cos 37 4 5 1 Choice of coordinate set Resorting to aircraft standard
44. transferCount hent transferCount gt gt 8 dmaMode SINGLE ADDR_INC autoInitMode AUTO_INIT ENABLE AUTO_INIT DISABLE dir INPUT WRITE READ SELECT CHAN dmaChan InterruptDisable out8 SNGL MASK reg dmaChan DISABLE dmaChan out8 MODE reg dmaChan dmaMode out8 CLR BYTE PTR reg dmaChan 0 out8 BASE ADDR reg dmaChan Lsb out8 BASE ADDR_reg dmaChan msb out8 PAGE ADDR reg dmaChan page out8 CLR BYTE PTR reg dmaChan 0 out8 COUNT reg dmaChan lcnt out8 COUNT reg dmaChan hcnt InterruptEnable return 0 104 G 7 pcm3718 c f KK Ck kk ke ke ke ke ke ke ke e ke ek Helper thread implementation Ck ckckck ck ok ck ke ko ke ke ke ke e e e kx x This thread automatically copies the most recent data from the DMA buffer into an inter process QNX shared memory area The thread also sends out a wake up signal to the filter process telling new data is available if a filter is attached to this thread that is void copy thread void devicestruct struct sigevent timerevent unsigned char maxbuf unsigned char dmaptr unsigned char filterattached struct itimerspec itime timer t timer id int rcvid chid2 status policy chid2 is the channel id to communicate with the filter chid is for in process comm struct sched param param my message t msg dmaptr dev dmabuf filterattached 0 chid chi
45. two digital ports similar to the parallel port Using one of these ports which remains at a low state during power up will solve the problem Programmatically these ports are as easy to use as the parallel port See the file ioports h for information on how to control them 60 D Using QNX 6 2 QNX is designed to behave like any UNIX environment The differences are found in the internal structure and implementation of the operating system itself This appendix serves as a quick introduction on how to use and develop for the QNX OS D 1 Mini how to For learning more about how to use QNX any good book on UNIX or LINUX will do since most of the material also apply to QNX In order to immediately get started with QNX some hints will be presented in this section The first two subsections are common for all UNIX systems while the others are specific for QNX D 1 1 Often used console commands Is al Lists all files in the directory including sizes and permissions ps Shows all running user processes and their corresponding process id pid kill Terminates a running process by giving the pid see above as an argument amp Can be put at the end of the line when issuing a command or starting a program The program will run in the background as a separate process i e not locking the terminal window In order to execute a program located in the same directory put before the name of the executabl
46. 00 W Richard Stevens UNIX network programming 2nd ed Upper Saddle River NJ Prentice Hall PTR 1998 1999 Michael R Sweet Serial Programming Guide for POSIX Operating Systems 5th ed Online documentation 1999 http www easysw com mike serial William Tyrell Thomson Introduction to Space Dynamics New York John Wiley amp Sons Inc 1961 Andrew W Troelsen Developer s workshop to COM and ATL 3 0 Plano TX Wordware Publishing 2000 52 A Analogue to digital conversion In order to measure and analyze analogue electrical signals in a computer an analogue to digital converter ADC is required During operation the analogue signal is measured for a very short time period usually a few microseconds This is known as sampling the signal and the acquired measurement is called a sample Sampling gives an accurate measurement at the particular time instant where the sample is made By sampling often enough it is possible to fully reconstruct the continuous version of the signal using only the samples This is a direct consequence of the fundamental theorem of sampling There is an important relationship between the sampling frequency f and the maximum frequency of the signal fy f z2fy The frequency f 2fy is known as the Nyqvist frequency and is equivalent to the maximum frequency that can be detected or reconstructed This frequency becomes very important when dimensioning measurement systems The question How often
47. 18 c f X e e KK KK PCM3718H Resource Manager Fe A ck ck ck ckckckock kk ko k e ke x ke x include stdio h include hw inout h include sys mman h include lt sys neutrino h gt include inttypes h include lt sys types h gt include lt sys stat h gt include lt fcntl h gt include pthread h include lt sys netmgr h gt include lt sched h gt include time h include unistd h include errno h include stddef h include stdlib h include lt devctl h gt include sys iofunc h include sys dispatch h include dmadef h include pcm3718 h include pulsecodes h BORK Kk ke ke ek ek ke e e e Resource manager variables Ckckckck ck ke ke ke ke e e e e x x static resmgr connect funcs t connect funcs static resmgr io funcs t io funcs static iofunc attr t attr KK HK KK kCkCkCk kk kk kCkCkck kk kck kk kck kc kckckckckckck I ke ke e I RK KK KK KK Global Variables HK KK KK int runmode The resource manager can be executed in 3 modes SILENT No messages are written to screen NORMAL Only some messages i e errors are written to screen VERBOSE Prints all current operations to screen including errors The channel id to the copy thread see Copy thread int channelid A Structure containing all information about the device PCM3718 PRIVATE dev Structs for changing the realtime clock struct _clockperiod clockp oldclo
48. 2005 157 CIV A Study of Sensory based Control and Mechatronic Systems for Hybrid Rocket Operation CONNY GUSTAFSSON MASTER OF SCIENCE PROGRAMME in Space Engineering Lulea University of Technology Department of Space Science Kiruna UNIVERSITET 2005 157 CIV ISSN 1402 1617 ISRN LTU EX 05 157 SE A Study of Sensory based Control and Mechatronic Systems for Hybrid Rocket Operation Conny Gustafsson Abstract This Master s Thesis concerns the control of a small scale autonomous hybrid rocket It is an investigation of how an onboard computer system can be used for performing the low level activities required for controlling the rocket in flight e g data acquisition inertial navigation propulsion and attitude control The Thesis contains an in depth study of the underlying physics of rocket motion as well as numerical simulations using MATLAB Simulink The simulations indicate that even complex systems such as rocket attitude control can be performed using simple control principles The thesis also explains how to implement the required software elements using the QNX real time operating system and the C programming language MATLAB is a registered trademark of The Mathoworks Inc ili QNX is a registered trademark of QNX Software Systems Ltd Preface and acknowledgements The research leading to this thesis has been performed at the Robotics and Mechatronics Research Laboratory RMRL at Monash
49. ACK in ROCKETCLIENT M with the given input T ROCKETCLIENT Property Value creates a new ROCKETCLIENT or raises the existing singleton Starting from the left property value pairs are applied to the GUI before rocketclient OpeningFunction gets called An unrecognized property name or invalid value makes property application stop All inputs are passed to rocketclient OpeningFcn via varargin See GUI Options on GUIDE s Tools menu Choose GUI allows only one instance to run singleton Begin initialization code DO NOT EDIT gui Singleton 1 gui State struct gui Name mfilename gui Singleton gui Singleton gui OpeningFcn Grocketclient OpeningFocn gui_OutputFen G8rocketclient OutputFcn gui LayoutFcn qui Callback I if nargin amp isstr varargin 1 gui State gui Callback str2func varargin 1 end if nargout varargout 1 nargout gui mainfcn gui State varargin else gui mainfcn gui State varargin end End initialization code DO NOT EDIT oo 9 Executes just before rocketclient is made visible function rocketclient OpeningFcn hObject eventdata handles varargin This function has no output args see OutputFen oo hObject handle to figure eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see
50. AP 0 define IDNAME2IDNR x x define IDENTRY x x IDNAME2IDNR x define ID TEXTMESSAGE 0 Transmits a plain textmessage define ID ROIDNAMES 1 Request id names Client Server define ID TXIDNAME 2 IDName Package Server Client define ID IDNAMECOMPLETE 3 IDName transmission complete Server gt Client define ID SENDDATA 4 Used Internally by the Server to transfer message information define ID USER 10 The first legal User ID END DO NOT EDIT ORK KK KK Ck kk Kk kk kk ECK Ck Kk A kk AA ko kk Ok kk AA A AA ke ee eee ee x x J KCKCKCECk Ck ck kk kk kk kk kk ke ke ke ke ek Type XD hase eK kk kk kk ck ke ek ke ke koe e ee ee x x Always begin your ID s with the characters ID and please use capital letters for conformance define ID CHANO ID _USER 0 Analog Channel 0 define ID CHAN1 ID USERt 1 Analog Channel 1 define ID CHAN2 ID USER 42 Analog Channel 2 define ID CHAN3 ID USER 3 Analog Channel 3 define ID CHANA ID USER 4 Analog Channel 4 define ID CHAN5 ID USER 5 Analog Channel 5 define ID CHAN6 ID _USER 6 Analog Channel 6 define ID CHAN7 ID USER 7 Analog Channel 7 Client Commands define ID START AD 1024 Client Server requests A D conversion to start define ID STOP AD 1025 Client Server requests A D conversion to halt define ID SET SERVO 0 1026 Client requests servo 0 to mov
51. AQ card DAQ card ort pin pin pin pin pin pin pin pin This macros can be used to control the parallell port define PPortOut value out8 PPORT parportstate value Sets the entire Parallelll port This Macro function only sets the desired pin to on 1 define SetPPin pin value out8 PPORT _parportstate amp pin Similar function as above but app define IOPortlow value out8 IOPORTI define IOPortHigh value out8 IOPOR define SetPinLow pin value out8 IOPORTLOW ioportlowstate value gt 0 ioportlowstate pin ioportlowstate amp pin define SetPinHigh pin value out8 IOPOR _ioporthighstate pin ioporthighs L COO 120Y 01 4 CO N25 i or off 0 lU parportstate value gt 0 parportstate pin Ef lies to the PCM3718H digital ports LOW ioportlowtstate value THIGH ioporthightstate value THIGH ioporthighstate value gt 0 tate amp pin 93 G 4 pulsecodes h KOR K kk e ke e ke ke ke e ke e ke ek Pulse Codes CkCkck ck kckck ck kckckckckckckokckokckokckok I x x Pulses are sent to threads for synchronisation These are used by the PCM3718 driver as well Please don t delete the ones you don t use define TIMER PULSE CODE PULSE CODE MINAVAIL 0 Used by various timers define RELEASE PULSE CODE PULSE CODE MINAVAIL 1 Used to activate a non active thread define SHUTDOWN PULSE CODE PULSE CODE
52. ATLAB handles structure with handles and user data see GUIDATA Executes during object creation after setting all properties function edit4 CreateFcn hObject eventdata handles hObject handle to edit4 see GCBO eventdata reserved to be defined in a future version of MATLAB handles empty handles not created until after all CreateFcns called if ispc set hObject BackgroundColor white else set hObject BackgroundColor get 0 defaultUicontrolBackgroundColor end function edit4 Callback hObject eventdata handles hObject handle to edit4 see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA Executes on button press in pushbutton4 function pushbutton4 Callback hObject eventdata handles hObject handle to pushbutton4 see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA invoke handles COMh SendCommand ID SET SERVO O get handles edit4 SEEING yz Executes during object creation after setting all properties function ID CHAN3 CreateFcn hObject eventdata handles hObject handle to ID CHAN3 see GCBO eventdata reserved to be defined in a future version of MATLAB handles empty handles not created until after all CreateFcns calle
53. COM programming COM Common Object Model allows Microsoft Windows programs to communicate and send data to each other while they are executing A C program was thus written which took care of all the networking problems that MATLAB was unable to solve Then by the use of COM technology the C program was used for extending MATLAB with advanced networking capabilities without compromising its own functionality The discussion of COM and network programming under Windows are subjects far too complex to be included in this report For reference see the books from Schildt Sch00 Stevens Ste98 and Troelsen Tro00 What we have achieved by all this is to allow MATLAB running in Windows on a desktop computer to communicate with our program in QNX on the PC 104 computer using the TCP IP network protocol The communication solution described in detail in Appendix E can be used for communication with any computer platform There were plans for developing a graphical control program for the Linux operating system as well but unfortunately this was not allowed within the project time frame A text version for both the QNX and Linux environments exists and can work as a basis for further development of a graphical client Because of POSIX compliance the same program compiles both in Linux as well as in QNX 3 6 1 The MATLAB Graphical User Interface Since most of the time spent on this part of the project was used for developing the communicat
54. Channel 1 Channel 2 Value 13 Name ID_CHAN3 Value 14 Name ID CHAN4 Value 15 Name ID CHANS Value 16 Name ID CHAN6 Value 17 Name ID CHAN Value 1024 Name ID START AD Value 1025 Name ID STOP AD Value 1026 Name ID SET SERVO Sending message with ID ID SET SERVO 0 Value 200 Figure E 7 Rocketclient with servo control E 6 3 Expanding the GUI with new measurement displays The GUI can display data from analogue channels 0 1 and 2 Assume we want to connect some signal on channel 3 measure it using the DAQ module and then display it inside the MATLAB GUI As before we first have to add the functionality on the server side This time we do not have to add a new entry in the ID List or ID Map since the first 8 analogue channels already have been defined Open the file netserver c First make sure the Filter thread is performing A D conversion on channel 3 There should be two lines like this channel setup data start 0 channel setup data stop 4 Make sure that the stop channel is 3 or more as above Next find the Send thread and add the line nsendt addAnalogData2Buffer amp ptr ID CHAN3 ad data channel 3 inside the message handler for TIMER PULSE cope as described in section E 4 7 Compile and make sure the new program file is running on the PC 104 computer as described earlier Now return to MATLAB and start Guide guide rocketclient 79 Examine the edit boxes on
55. D command pulse is received by the Send thread it starts sending measurement data to the remote client In the current implementation it sends measurements every second controlled by a timer The thread uses a wrapper function to add a measurement packet to the current TCP IP send buffer The essential code is found below pthread rwlock rdlock amp ad data rwl nsendt addAnalogData2Buffer amp ptr ID CHANO ad data channel 0 nsendt addAnalogData2Buffer amp ptr ID CHAN1 ad data channel 1 pthread rwlock unlock amp ad data rwl Since the measurement data area see Figure E 1 uses a read write lock it first needs to gain read access to it It then adds A D channels 0 and 1 to the send buffer and finally unlocks the read write lock so other threads can access the area Adding measurement channels is fairly easy For example if something interesting is measured on A D channel 3 then in order to send snapshots of this channel to the remote client add a line with the new channel number inside the Send thread like this pthread rwlock rdlock amp ad data rwl nsendt addAnalogData2Buffer amp ptr ID CHANO ad data channel 0 nsendt addAnalogData2Buffer amp ptr ID CHAN1 ad data channel 1 nsendt addAnalogData2Buffer amp ptr ID CHAN3 ad data channel 3 pthread rwlock unlock amp ad data rwl E 5 Remote platform control The platform can be remotely controlled over the TCP IP network In order for this to work the f
56. DE ANALOG devctl card fd DEVCTL SET READMODE amp mode sizeof mode NULL read cardfd amp reading 2 Make a software A D Remark A better and even simpler method to read and write to the digital I O ports is to use the definitions in ioports h This devctl command exists only to provide meaningful operations for the read and write routines offering an alternative interface for accessing the ports 87 G Source code This section presents the C source code used for this project An index of this chapter is found below in order to help the reader find the different subsections GI ditiadetbltisesee se etate te anta tien obe wx EIS ta tice 90 2 DESI i ext eoe i ou xotat eccL EEE TEE 91 3 MOPOT ESCH rose beste etes dete eee ie etia ecu ete eae s 93 G4 p lsecodes Hsc eoa NT bar won tar Mei eee dim Ne pud 94 GS SBEVOCODUOLTL tecla eth etas abit a aa bene ita fa esu a 95 G5 pem 18 Ban tes eg tee initi olo etsdeeie damental ates do Socks 96 Gr Pem TTS Case ac UPS 99 GS mS 0161 ESI 011 9 Oe Pr eti edet tede T een 116 Cri DAMME aE 0 3 104 nes etes des ome citm vetu d esu a EDU D ET 129 89 G 1 dmadef h Jk RK kk kk kk ke ke ke ke e ke ek DMA SPI ECIFIC MACROS X amp k kk kk ke ke ke ke ke ke e ke e e e kx This file is used by the PCM3718 driver to gain access to the INTEL DMA controller that sits onboard all modern PC s wy unsigned
57. LL Initialize the DMA controller ret devctl card fd DEVCTL DMA INIT NULL 0 NULL Attach this thread to the driver for synchronization ret devctl card fd DEVCTL ATTACHFILTER amp fm sizeof fm NULL The filter is a simple first order low pass filter Also known as exponentially moving average filter N 7 Average over 7 samples some arbitrary number alphal 1 0 N 1 0 Filter parameter alpha2 double N N 1 0 Filter parameter if pthread rwlock init amp ad data rwl NULL EOK fprintf stderr Filter thread Error while initating rwlock n pthread cleanup push amp RW Destroy NULL Clear the analog channel data area pthread rwlock wrlock amp ad data rwl memset ad data channel 0 sizeof ad data channel pthread rwlock unlock amp ad data rwl Prepare the buffer pointers bufsize fm reply size bufferend buffer tbufsize Open the shared memory area if fd2 shm open fm reply shm name O_RDWR 0770 1 fprintf stderr CLIENT ERROR cannot create shmem area close fd2 abort else if dmabuf mmap NULL bufsize PROT READ PROT WRITE PROT NOCACHE MAP SHARED fd2 0 MAP FAILED perror mmap close fd2 abort close fd2 we are now ready to start filtering data for rcvid MsgReceive channelid filt amp msg sizeof msg NULL if rcvid 0 if msg pulse code
58. LYSIS ea once etate troia tele un ae des poti diete nude 29 4 1 Coordinate Systemi cs ruido ent inp th REN plat Jus toate ina ed ek do hae potoit ea RE ima d 29 4 2 Equations of motion for a rocket moving in the plane 29 4 5 A simple attitude control system o e P Ati e ce Re ree Yt eia Pr RAE Vestae E Neige 30 4 3 1 PED GOSEODIG E S oro or euo CMS aA pM LN HM Mai lee m E 31 4 3 2 State space controller with integral action sse 31 4 4 Rocket motion in three dimensions su jac csvacdenvs sages essacde asd adseseaadeen caavgeiadlsavatdacasedes 33 4 4 1 Equations of motion for a rigid body eee te eet estu duet 33 4 4 2 Lagrange s equations for moving coordinates sse 33 4 4 3 Mornmients OE merta ioni db ee ERI RM AD SNR KAERT OLI UII E RTA Ear 34 4 4 4 Equations of motion for a constant mass system ssssssseeeeeee 35 4 4 5 Equations of motion for a variable mass system ssssssseeeeeee 36 a5 Euler angles nsira aa esent d Qoa cbe nen a taut sitter etui 37 4 5 1 Choice of Coordinate Set s ari ice chateau crabe dudas a a 38 4 5 2 Resolving the Euler angles in fHght 2 bet ritate It nba rd aed t ears 38 4 5 3 Relationship with the IMU sincerae t ec ree pitt et et cada ete 38 4 6 Dynamic modelling using MATLAB Simulink esee 39 4 6 1 Moments of inertia eSUTatoP eed te re rua rtr diis dla ia os o bn Nap Eco 39 4 6 2 Angular velocity estimator i
59. MER PULSE CODE else if msg pulse code COMMAND PULSE CODE a COMMAND PULSE CODE means that some other thread is relaying a command to the threads of interest Instead of using some internal message type structure The same structure is used by the tcp communication In most cases the listen thread is the one sending these commands It does this to notify all other threads that a certain event has occured How each thread interprets what to do when these events commands occur is totally indivdual 122 G 8 netserver c switch msg pulse value sival int case ID START AD Start the feedback timer the one generating TIMER PULSE CODE pulses timer settime send timer id 0 amp send itime NULL break case ID STOP AD Resets the feedback timer timer delete send timer id timer create CLOCK REALTIME amp send timerevent amp send timer id break case ID ROIDNAMES This means that the client has requested the names and id number of all members in the IDMAP see IDList h memset sendbuffer 0 sizeof sendbuffer printf Ready to transmit IDs and Names Wn for i 0 i IDMAP SIZE i PacketID asUintN htons ID TXIDNAME ptr sendbuffer strcpy ptr HeaderStart ptrt sizeof HeaderStart memcpy ptr PacketID asChar 2 ptrt 2 sprintf ptr s d IDMAP i ID Name IDMAP i ID Value ptr strlen ptr nsend int ptr sendbuffer 1
60. Make sure the partition is set to bootable a should be present under boot Save the settings and close fdisk A new device dev hd1t77 should now exist Now type dinit h dev hd1t77 QNX automatically mounts all drives under the directory fs filesystem There should be a directory called fs hd1 qnx4 this is where all files will go Using the Filemanager found in Photon locate the following directory fs hd0 dos 2 Program Files qnx boot fs In this directory there should be a number of files qnxbase ifs qnxbase qfs qnxbasedma ifs root qfs Remark On some QNX systems these files are located in boot fs Copy qnxbase ifs and qnxbase qfs to fs hd1 qnx4 Using the Filemanager create the folder fs hd1 qnx4 boot and then create the folder fs hd1 qnx4 boot fs move qnxbase qfs to this directory by typing in the terminal window cd fs hdl qnx4 mv qnxbase qfs boot fs Then type mv qnxbase ifs boot A diskroot file is missing The easiest way to retrieve one is to copy the diskroot file from the desktop PC by typing cp diskroot from the same directory as before Shut down the desktop computer remove the flash card from the holder insert it into the PC 104 and power it up The PC 104 should now boot by itself D 1 5 Disabling Photon boot QNX automatically boots into the Photon windowing system To prevent this do the following From a terminal window type touch etc system conf
61. NDLE T handle void extra int ret if status device open Allow only one open connection to this device if runmode SILENT printf PCM3718 This device is already in use n return EXIT FAILURE First run the default open manager ret iofunc_open default ctp msg handle extra if ret EOK return ret if runmode VERBOSE printf PCM3718 Device opened n status device open 1 Then perform initializations etc SIGEV INTR INIT amp intevent Initialize an interrupt event Used for interrupt handling PCM3718 reset amp dev 110 G 7 pcm3718 c if runmode VERBOSE printf PCM3718 Card has been reset n return ret The io close function handles close calls to this device The QNX OS automatically calls this function when programs closes crashes or whatever So there is no worry about memory leaks It mainly releases all memory allocated by SetupBuffer function and also resets all parameters a Ine io close resmgr context t ctp void msg RESMGR OCB T ocb int base dma clk ret irg trate if runmode VERBOSE printf PCM3718 Closing connection n MsgSendPulse channelid sched get priority max sched getscheduler 0 SHUTDOWN PULSE CODE 0 outs dev iobase PCM3718 CONTROL USE SOFT Disable PACER amp DMA amp IRQ if dev dmabuf NULL DMA Buffers are probably in use out8 SNGL MASK reg dev dma_channel
62. NVAL if runmode VERBOSE printf Channel setup failed n return EINVAL j status channel set 1 break case DEVCTL SETPACER Sets the pacer values C1 and C2 to be used in pacer mode if runmode VERBOSE printf PCM3718 Setting up Pacer values to u and u rx data pacerdata cl rx data pacerdata c2 Check for errors if status dma set if runmode SILENT fprintf stderr An PCM3718 Cannot set clock speed after DMA buffers have been 107 G 7 pcm3718 c created n t close connection before calling SETPACER again n return EINVAL if rx data pacerdata cl 2 rx data pacerdata c2 2 if runmode VERBOSE fprintf stderr PCM3718 Unallowed Pacervalu ntered n return EINVAL dev Cl rx_data gt pacerdata cl dev C2 rx_data gt pacerdata c2 status pacer set 1 break case DEVCTL DMA INIT Initializes the DMA buffers and sets up the DMA controller if dev dmabuf NULL dev shmem_area NULL status dma_set if runmode SILENT fprintf stderr PCM3718 DMA buffers already exists n t close connection before calling START DMA again n return EINVAL if runmode VERBOSE printf PCM3718 Setting up DMA buffers n if PCM3718 setupBuffers amp dev return EINVAL if runmode VERBOSE printf PCM3718 Starting DMA controller on channel d Mn dev dma channel if DMASetup dev dma channel dev dma
63. O z QO s dt Oz Oy OX We partially verify 4 19 in the following example Assume the kinetic energy is defined by T T 4 20 ie we use a two dimensional system for simplicity Note that for a moving coordinate system the potential energy is zero i e V 0 this explains the absence of V in 4 19 Now inserting T in 4 17 we obtain for the linear momentum P pmr oT mv Ov pee any 4 21 y Ov J P 0 The linear momentum is defined as mass times velocity In order to form the cross product between Q and P we assume that the frame rotates around the z axis only i e Q c K mv o QxP mo 4 22 0 After inserting 4 21 and 4 22 into 4 18 we obtain F m mv o F m mv o 4 23 F 0 Note that we have obtained the two dimensional system presented in 4 3 We have confirmed that equation 4 19 applies at least for the two dimensional case We will derive the three dimensional case in section 4 4 4 4 4 3 Moments of inertia In order to form the three dimensional moment equations we will use a similar approach as above extracted from Fortescue and Stark FS95 The moment about the centre of mass C M can be represented by M H OxH 4 24 34 where H is the angular momentum which may be expressed using the inertia matrix Ic H I 4 25 1 Ls T Ic ly Xy yz 4 26 fe yz ZZ It is obvious that H now is DunckT 8rd 0 H 7 0 1 0 1 0 4 27 L
64. RGOUT hObject handle to figure eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA 9 Get default command line output from handles structure varargout 1 handles output Executes on button press in pushbuttonl function pushbuttonl Callback hObject eventdata handles hObject handle to pushbuttonl see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA invoke handles COMh Connect 169 254 13 200 Executes on button press in pushbutton2 unction pushbutton2 Callback hObject eventdata handles hObject handle to pushbutton2 see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA invoke handles COMh Disconnect Fh oe oo oo oo oo Executes during object creation after setting all properties function ID CHANO CreateFcn hObject eventdata handles hObject handle to ID CHANO see GCBO eventdata reserved to be defined in a future version of MATLAB handles empty handles not created until after all CreateFcns called oo Hint edit controls usually have a white background on Windows See ISPC and COMPUTER oo if ispc set hObject BackgroundColor white else set hObject Backgrou
65. Signal U sat V Vmin Vmax Bounded Output Signal I 1I h T U V Corrected Integration Factor Sat V Vmin Vmax is a function calculating the saturated i e bounded signal U from a control signal V in the interval defined by Vmin and Vmax double sat double V double Vmin double Vmax return V lt Vmin Vmin V gt Vmax Vmax V Below is a complete code for a PID control loop It uses two functions AD IN and DA_OUT to receive measurements and signal the actuator We assume all variables to be of type float or double for y AD IN P K yref y D Td D K N y old_y N h Td I I K h Ti yref y V P 1I D U sat V Vmin Vmax DA_OUT U I I h T U V oldy y Wait for next control cycle here 57 C Switch control circuitry When controlling electronic devices using a PC compatible computer additional electronic components are usually required Here we present a circuit diagram for a simple digital switch which can be controlled from a TTL logic connector On a PC the pins of the parallel port are TTL compatible and thus can be used to control the switch presented In this project there are three types of components loads which we want to control Their types and electrical characteristics are found below Table C 1 Electrical characteristics for the loads Required Required Load Potential Current Effect Solenoid valve 12V 1 5A 18W high pressure
66. Solenoid valve 12V 450mA 5 4W low pressure Glow plug 1 25V 3A 3 75W Using this information it has been possible to devise a switching circuit for the first two of the three components The schematics in Figure C 1 is designed to switch a 12V signal on and off for opening and closing the two solenoid valves in Table C 1 Components required e MOSFET transistor type PIGNEOGL from ST electronics e Diode type N4007 e 100 Ohm resistor 12V TIL G Voltage Figure C 1 Circuit diagram The diode is used to prevent damage to the FET in the case of load solenoid valve disconnection A similar digital switch can be built for the glow plug once it is possible to transform the source signal to a low voltage high current output signal according to the specifications in Table C 1 A TTL signal is either 0V which resembles a digital zero or 5V which is equivalent to a digital one Changing the states of the bits corresponding to the pins of the digital I O port will thus open the valve when the state is one and close it when it is zero 39 Important notice about the parallel port The PC 104 computer leaves all the pins of the parallel port in a high state digital one during the first seconds of power up If solenoid valves and or glow plug are connected it will cause all solenoid valves to open and glow plug to heat which may cause undesired effects The data acquisition card connected to the PC 104 has
67. TL ATTACHFILTER DIOTF DCMD MISC CMD CODE 5 attach message t Pd Attaches a filter for synchronization define DEVCTL SET READMODE DIOTF DCMD MISC CMD CODE 6 unsigned char Sets the mode of the read write operations define DEVCTL SET TRANSFER SPEED DIOTF DCMD MISC CMD CODE 7 unsigned int E d Sets the filter wake up speed BOK IK KK Kk kk kk RRA kk kk Ck Kk kk kk hok kk kk kk kk koe kk ok ko ke kk oko ke ke ke e e ee ee x x Internal structure used by Resource manager to manage the status of the card typedef struct int iobase Base adress of device unsigned char dmabuf shmem_area DMA buffer and shared memory area 97 G 6 pcm3718 h unsigned int buflsize shmem size DMA and shared memory buffer sizes Rangetype range 16 The Conversion ranges for each channel unsigned char start channel The Conversion start channel unsigned char stop channel Conversion Stop Channel unsigned char dma channel DMA channel used unsigned int CLK speed External Clock speed unsigned int C1 unsigned int C2 First pacer control value Second pacer control value unsigned char IRQ IRQ used unsigned int transfer rate Filter wake up speed in Hz unsigned int transfer timeperiod Equivalent speed in nanoseconds PCM3718 PRIVATE fendif me cr 98 G 7 pcm3718 c G 7 pcm37
68. University Melbourne Australia from March to August 2003 I would like to thank in particular my supervisor at Monash University Associate Professor Bijan Shirinzadeh for always finding the time and for all the help and insight he provided I also thank Dr Damon Honnery for his help with the hybrid rocket motor and for letting me in to the combustions lab as a visitor at the rocket launches Professor Julio Soria who helped me during those long hours with the Linux operating system and provided me with information on parallel port and real time programming and my supervisor at Lulea Dr Bj rn Graneli for his long patience and for putting confidence in me Special thanks to Sven Molin coordinator of the Lule Monash exchange program who helped me with the preparations before my travel and who offered me a place to stay while in Melbourne Also thanks to everyone at RMRL for their help and for the after hours of socializing at the local pub And thanks to Mark Symmonds for his help with the electronic components Finally I especially want to thank my friends and my family for all their help and support Conny Gustafsson List of Acronyms AID Analog to digital ADC Analog to Digital Converter API Application Programming Interface AT Advanced Technology COM Common Object Model CPU Central Processing Unit DAQ Data Acquisition DHCP Dynamic Host Configuration Protocol DMA Direct Memory Access FET
69. V Set Input range of card ur PCM3718 setrange int n struct timespec ts int se char buffer 20 se in8 dev iobase PCM3718 STATUS amp 0x20 1 0 ts tv sec 0 ts tv nsec 1000000 Check for range consistency if dev start channel dev stop channel return EINVAL if se amp amp dev stop channel 15 return EINVAL else if dev stop channel 7 return EINVAL If range is ok start Setting up the card using the Rangetype array for n dev start channel n dev stop channel ttn if int dev range n gt 8 return EINVAL There are 9 different configurations supported by the card out8 dev iobase PCM3718 MUX n if runmode VERBOSE Rangetype2str dev range n buffer printf PCM3718 Setting channel Sd to mode s n n buffer out8 dev iobase PCM3718 RANGE int dev range n nanosleep amp ts NULL out8 dev iobase PCM3718 MUX dev stop channel 4 dev start channel n in8 dev iobase PCM3718 MUX if se amp amp runmode SILENT printf PCM3718 A D range between d and d has been set up for SE mode n n amp 0xf n gt gt 4 else if runmode SILENT printf PCM3718 A D range between d and d has been set up for DIFF modeWMn n amp Oxf n 4 return 0 Software triggered A D function A 101 G 7 pcm3718 c int PCM3718 software AI unsigned i
70. al solid propellant rocket motor The laboratory rocket motor seen in Figure 1 2 is developed at the Laboratory for Turbulence Research in Aerospace amp Combustion LTRAC also located at Monash University The project is a joint collaboration between the LTRAC and RMRL laboratories The hybrid rocket motor uses a propellant consisting of paraffin wax with carbon powder The carbon powder provides an even burn rate The solid fuel grain in a hybrid rocket motor improves the mechanical properties compared to a solid propellant because of its lower content of solid oxidizer Rocket operation follows a sequence of steps first using a glow plug in order to ignite a mixture of propane and oxygen inside the rocket combustion chamber A high pressure solenoid valve is then opened releasing a flow of oxygen the oxidizer into the chamber The oxygen and the propellant is then consumed inside the motor thus creating the desired thrust Figure 1 2 Test setup for hybrid rocket motor The photo to the far right shows the connections for the propane and oxygen supplies 1 1 3 Inertial measurement unit In order to navigate the rocket an Inertial Measurement Unit IMU is employed The IMU consists of accelerometers and gyros The accelerometers are used for measuring acceleration velocity and position while the gyros are used for measuring the attitude rotation of the rocket Prior research has been performed in this area at RMRL and a functio
71. alls to this device It can perform 3 different operations depending on the Read Write mode of this device The Read Write mode is set by issuing a devctl call with a SET READMODE argument When readmode is RWMODE DIO1 It reads the lower 8 bits of the Digital IO channel 111 G 7 pcm3718 c RWMODE DIO2 It read the higher 8 bits of the Digital IO channel RWMODE ANALOG It issues a manual A D conversion Software mode sy io read resmgr context t ctp io read t msg RESMGR OCB T ocb int status unsigned int data if status iofunc_read verify ctp msg ocb NULL EOK return status if msg gt i xtype amp IO XTYPE MASK IO XTYPE NONE return ENOSYS if rwmode RWMODE DIO1 rwmode RWMODE DIO2 if runmode VERBOSE printf PCM3718 reading from Digital channel n data PCM3718 DIO read else if rwmode RWMODE ANALOG if runmode VERBOSE printf PCM3718 reading from analog channel n data PCM3718 software AI MsgReply ctp gt rcevid EOK amp data sizeof data ocb gt attr gt flags IOFUNC ATTR ATIME return EOK The io write function writes to the Digital IO channel Which part of the channel lower or higher it writes to depends on the value of rwmode see above wy int io write resmgr context t ctp io write t msg RESMGR OCB T ocb int status unsigned int data char buf if sta
72. always NULL rope a There are eight different commands that can be issued in order to control the operation of the DAQ card The control code macros and their description are found below F 2 1 DEVCTL SETCHANNEL Parameter type channel setup data t defined in pcm3718 h Description Sets the voltage input range used for each channel in the DAQ card The DAQ card supports either 8 channels in differential mode or 16 channels in single ended mode jumper setting The driver supports a unique range for each individual channel The ranges supported are Bipolar 10V 5V 2 5V 1 25V 0 625V Unipolar 0 10V 0 5V 0 2 5V 0 1 25V Example include pcm3718 h channel setup data t channel setup data int i card fd card fd open dev PCM3718 O RDWR channel setup data start 0 channel setup data stop 7 for i 20 i 8 i channel setup data range i UNIPOLAR 10V 84 devctl card fd DEVCTL SETCHANNEL amp channel_ setup data sizeof channel setupp data NULL This command uses a special data structure containing information such as which channels to include in the A D conversion loop and the range for each channel used See pcm3718 h for further information F 2 2 DEVCTL SETPACER Parameter type double uint defined in pcm3718 h Description The DAQ card supports a custom pacer rate sampling frequency defined as PacerRate OscillatorFrequency CI C2 wh
73. am has a priority assigned The priority is represented by a numerical value that contains information for the real time scheduler about the relative importance of the thread for accessing the CPU In simple terms the scheduler selects the thread with the highest priority in order to assign which thread will use the CPU during the next timeslot If the thread with the highest priority is suspended e g it is waiting for some event to occur the scheduler will select the thread with the next highest priority If two threads with the same priority are ready to run then an arbitrary thread is chosen or depending on the current scheduling policy two or more threads with the same priority will be executed using a round robin algorithm giving equal amount of time to each thread In QNX priorities can be any number between 1 and 63 where 1 means lowest priority and 63 is highest By default a thread has priority 10 We will now analyze the choice of priorities for our system in Figure 3 11 The attitude control is the most important part of the system If it would be pre empted by some other thread while performing its task a risk of disaster is inevitable Therefore we raise its priority to higher than normal say 15 Without recent data from the inertial measurement unit the attitude control thread cannot execute We cannot however raise the priority of the inertial measurement algorithm higher than that of the attitude control thread and thus ris
74. ame time the results are similar to the one seen in Figure 4 11 The conclusion from these simulations is that rolling should be avoided while performing yaw or pitch manoeuvres During actual rocket flight there should be no need for performing roll manoeuvres 42 y rad s 0 5 10 15 20 25 30 Time s Figure 4 10 Angular velocity for the y axis with Uy 0 5 Nm and U U 0 Nm angular vel rad s time s angular vel rad s time s Figure 4 11 Effects of two input signals U 0 01 Nm U 0 5 Nm U7 0 Nm 4 7 Attitude control system In the previous section we presented the modelling of the physical properties of the rocket dynamics using Simulink In this final section we will study the performance of a PID controller using the model The results presented here can with advantage be reused in the implementation phase for the control software in the rocket First we require a system for making the transformation between the aircraft body frame and the inertial frame Using 4 40 it is straightforward to implement such subsystem in Simulink The resulting subsystem is shown in Figure 4 12 The internal structure of the 43 block is cluttered and is not shown We use conversion from radians to degrees on all Simulink scopes recording angles Next we use two PID controllers for replacing the torque generators for the y and z axes in our original model shown in Figure
75. ard QNX driver design methods Resource Manager Client program requesting data from Software Interface the DAQ hardware Algorithms DAQ hardware Figure 3 6 Overview of data acquisition resource manager software driver 3 4 1 2 Using DMA in data acquisition applications Direct Memory Access or DMA for short is a solution for computer hardware for sending and retrieving data from system memory RAM DMA relieves the CPU from dealing with the incoming data sent from the data acquisition card This means that the DAQ hardware fills a predefined area in the system memory without need for CPU intervention 3 4 1 3 Memory hierarchy In order to better understand how the measured data travel from the DAQ hardware to a client program using the resource manager we need to discuss the different memory areas used in the design A hierarchy is shown in Figure 3 7 and a simple description of how the resource manager operates follows 1 Create a memory buffer in physical memory RAM here called DMA buffer 2 Initiate the DMA controller and supply the memory address of the previously created DMA buffer 3 Initiate A D conversion The A D converter starts filling the DMA buffer with data 4 The resource manager copies the most recent data to a shared memory area when the client requests data The shared memory area is accessible from both the resource manager and the client The client now has a copy of the d
76. at 2A LED2 LED ETHERNET LCD CN1B COM FLOPPY COM2 PCM 3350 PCM 3350 PRINT EDE LOD BACKLIGHT lye VeA POWER CN11 12V CAD GNO o e T a PS2 KB MS Nut PC 104 Figure 2 2 Overview of CPU module Top side left and bottom side right 6 COMPACT FLASH SOCKET Figure 2 3 Photo of CPU module Top side left and bottom side right The CPU module was fitted with 128 MB SDRAM and one 128 MB CompactFlash memory card used as hard disk drive 2 5 2 Data acquisition module The data acquisition module is of model PCM 3718H It offers the following features 16 single ended or 8 differential analogue jumper selectable input channels 12 bit A D converter up to 100 kHz sampling rate with DMA transfer Software programmable gain value for each input channel Software selectable input range for each input channel Two 8 bit digital input output channels TTL compatible Flexible triggering options software trigger programmable pacer trigger and external pulse trigger Data transfer by program control interrupt handler or DMA e Power consumption 5V 180mA typical e Allowable input ranges software programmable Bipolar 10V 5V 2 5V 1 25V 0 625V Unipolar 0 10V 0 5V 0 2 5V 0 1 25V Analog Input Digital I O connector Figure 2 4 Data acquisition module PCM 3718H The PCM 3718H modul
77. ata sent from the ADC A D converter and this completes the transfer cycle 16 Recall from section 3 2 1 that each program has its own memory area The resource manager is in fact a program running in the background This means that the client cannot access the DMA buffer directly since it belongs to the memory area of the resource manager Fortunately the QNX operating system allows programs to share data dynamically using so called shared memory objects By putting data in any such object named Exposed data in Figure 3 7 the measurement data can make its way into the client memory for analysis This model is very safe and minimizes the risk that malicious code on the client side corrupts the behaviour of the resource manager at a cost of a slightly slower system response Client program I memory area I QNX shared l memory area l DMA buffer l area large Resource manager memory l i DMA controller l Figure 3 7 Memory hierarchy for data acquisition 3 4 1 4 Data synchronization Almost every application using data acquisition requires the stream of data to be synchronized Consider for example a feedback control application using the signal from an A D converter as input The feedback control loop is most certainly synchronized using some timer mechanism this is where real time programming is used and most probably it requests new A D data every time the loop is executed This means that data will be requ
78. be of any size and the null character acts as a packet trailer 1 Packet Header Null terminated String i 3 bytes 2 bytes x bytes 1 byte 69 Note that none of the characters in the data is allowed to be the null character This limitation requires all internal types such as int float or double to be converted into plain ASCII text before it is sent over the network If the data is not converted there is a risk of a null character entering the data string ending the packet prematurely Standard functions such as sprintf can be used for this purpose E 4 2 Type IDs The Type ID is a simple unsigned 16 bit value 0 65535 identifying what kind of data the packet contains The number can for example represent a variable value or a command C macros are used to represent these numbers These are defined in the file DList h An example of definitions in this file could look like this A D channels define ID USER 10 define ID CHANO ID_USER 0 define ID CHAN1 ID USER 1 define ID CHAN2 ID USER 2 define ID CHAN3 ID_USER 3 define ID_CHAN4 ID_USER 4 define ID_CHANS ID_USER 5 define ID_CHAN6 ID_USER 6 define ID_CHAN7 ID_USER 7 Client Commands define ID START AD 1024 define ID STOP AD 1025 The numbers between 0 and the macro ID USER i e numbers 0 through 9 are reserved for the internal use of the framework The file defines 8 analogue channels that can be used by the PC 104
79. blem is often solved by using a weight on the derivative part D This bounds the maximum derivative of the control signal to a value N Instead of using D KTis y y as in Figure B 1 above we use KT s D KT s y ys y N for high frequencies 1 The constant yis either 1 servo control or 0 process control Although y 1 often gives a smoother response the case y 0 is more common simpler to implement B 2 Anti windup Windup is perhaps the most important factor to deal with when implementing a feedback controller using integration PID or state space The phenomenon occurs when there is saturation of the control signal This happens when the output of the controlled actuator is limited to a certain interval such as maximum minimum control angle of a servo or a maximum minimum output voltage from a controlled source It can also occur when the control signal is time dependent for example servos that can move only a certain distance degrees per time unit These saturation effects cause the integration part of the controller to misjudge the actual error This can lead to a state where the controller output starts oscillating without control between the minimum and maximum states This is commonly known as windup 55 Since physical devices actuators have a limited interval where they can operate it is obvious that almost any controller should include an anti windup system Here follows a proposal for a commo
80. buf dev buflsize 0 INPUT 0 if runmode SILENT fprintf stderr PCM3718 DMA setup error Mn return EIO if runmode VERBOSE fprintf stderr PCM3718 Starting up DMA copy thread n pthread create NULL NULL copy thread NULL speed dev CLK speed double dev Cl dev C2 if runmode SILENT printf PCM3718 A D Conversion setup at 7 3f Hz n Generating 7 3f bytes of data n speed 2 speed if runmode VERBOSE printf PCM3718 Total DMA buffer d bytes n dev buflsize Create a comm link to copy thread channelid ConnectAttach ND LOCAL NODE 0 chid NTO SIDE CHANNEL 0 status dma_set 1 break case DEVCTL AD START if status channel set amp amp status pacer set amp amp status dma_set amp amp status ad running if runmode VERBOSE fprintf stderr PCM3718 Unable to start AD conversion n t fprintf stderr channel set u n t pacer set u n t dma_set u n t ad running uMn status channel set status pacer set status dma set status ad running return EINVAL if runmode VERBOSE printf PCM3718 Starting A D conversion n switch dev IRQ case IRQ2 USE IRON USE IRQ2 break se IRQ3 IRQN USE IRQ3 break e IRQ4 IRON USE IRO4 break e IRQS IRQN USE IRQ5 break e IRQ6 IRQN USE IRQ6 break e IRQ7 Cid GO Co 0 Bm ouo p
81. ce graph updating it each time new data arrives rocketclient Start AD Channel Disconnect Disconnect Set Servo 0 Channel Channel Channel Connecting to 169 254 13 200 Connection established Requesting ID names Ready to receive server data Stored ID list Value 10 Name ID CHANO Value 11 Name ID CHAN1 Value 12 Name ID CHAN2 VValue 13 Name ID CHANS Value 14 Name ID CHAN4 Walue 15 Name ID CHANS Walue 16 Name ID CHAN6 Figure E 8 Rocketclient with new measurement display E 6 4 Controlling a solenoid valve A solenoid valve can also be controlled from the MATLAB computer Except for the solenoid valve itself this example requires some extra electrical components set up as a digital switch of an external electrical signal see Appendix C If these components exist and have been connected properly we can start adding software for the switching Assume we want to control the solenoid valve using one of the pins of the parallel port say output pin 2 Start by editing DList h Add two new IDs Client Commands define ID START AD 1024 define ID STOP AD 1025 define ID SET SERVO 0 1026 80 define ID OPEN VALVE O0 1027 iff lt Add this line define ID CLOSE VALVE 0 1028 f 5 And this one Also make two new entries in the ID Map IDENTRY ID START AD IDENTRY ID STOP AD IDENTRY
82. ces in the x and y directions and the moment about the centre of mass O can be deduced directly from Figure 4 2 where L and D are the lift and drag components of the induced aerodynamic force Fe is the rocket thrust force and J is the moment of inertia Angular speed and angular acceleration are taken as positive in the clockwise direction 29 YF mgcos0 F D YF mgsind L 4 1a Y M 10 The forces F and F can also be written Y F ma 2 5 ma The sum of moments about O may be replaced by a single torque 7 acting orthogonally with respect to the longitudinal direction of the rocket i e parallel to the y axis 4 1b YM t 4 1c Figure 4 2 Forces acting on the rocket Acceleration of the centre of mass O with the x and y components can be described as a 2 X y 4 2 a 2j XO Combining 4 1 and 4 2 gives the final dynamic formulation of the rocket moving in the plane m X y 0 mgcos0 F D m 4 x 0 mg sind L 4 3 r IO 4 3 Asimple attitude control system Consider the system just described Assume the angle to be an attitude angle measured relative some inertial axis parallel to the gravitational force of the Earth Figure 4 2 By 30 neglecting the aerodynamical and gravitational forces and assuming the thrust F to be constant a simple rocket attitude control system can be formulated Dri96 The part of interest is the last part of equation 4 3 w
83. ch message t amdata unsigned char charvalue unsigned int uintvalue other devctl types you can receive rx data Let common code handle DCMD ALL cases You can do this before or after you intercept devctl s depending on your intentions oy if retstatus iofunc devctl default ctp msg ocb return retstatus retstatus nbytes 0 RESMGR DEFAULT Note this assumes that you can fit the entire data portion of the devctl into one message In reality you should probably perform a MsgReadv once you know the type of message you have received to suck all of the data in rather than assuming it all fits in the message We have set in our main routine that we ll accept a total message size of up to 2k so we don t worry about it D rx data DEVCTL DATA msg i Now check for all user defined messages BORK KK kk kk EK KK ko ko ke ke ek DEVCTL MESSAGE HANDLER ok ck A k ko ke ke ke e ke e e x x switch msg i dcmd The printf commands should keep you updated on what s going on case DEVCTL SETCHANNEL Sets the channelmodes on each channel if runmode VERBOSE printf PCM3718 Setting up channels d through d n rx data chdata start rx data chdata stop dev start channel rx data chdata start dev stop channel rx data chdata stop memcpy dev range rx data chdata range sizeof dev range ret PCM3718 setrange if ret EI
84. ck struct sigevent intevent Predefined Interrupt event used with the DMA buffers int chid int_id Internal variables int rwmode RWMODE DIO1 Current read write mode A bitfieild vector containing the state of the Resource manager Prevents errors like trying to start A D conversion before setting up the card properly struct unsigned device_open 1 unsigned dma set 1 unsigned channel_set 1 unsigned pacer set 1 unsigned ad running 1 unsigned filter attached 1 status A message structure Contains all potential messages used by the program typedef union 99 G 7 pcm3718 c struct pulse pulse attachfiltersend t channelinfo your other message structures would go here too my message t const struct sigevent isr handler void arg int id Detects the PCM 3718 cards returns 0 on success 1 on failure i static int PCM3718 detect int iobase struct timespec ts ts tv sec 0 ts tv nsec 2000000 2 milliseconds out8 iobase PCM3718 MUX 0x00 nanosleep amp ts NULL if in8 iobase PCM3718 MUX 0x00 return 1 there s no card out8 iobase PCM3718 MUX 0x55 nanosleep amp ts NULL if in8 iobase PCM3718 MUX 0x55 return 1 there s no card out8 iobase PCM3718 MUX 0x00 nanosleep amp ts NULL out8 iobase PCM3718 CONTROL 0x18 nanosleep amp ts NULL if i
85. continuously storing all relevant parameters time velocity attitude and so on the entire system can be carefully monitored during operation The stored data can also be accessed later if necessary In some cases we also need to perform processing of the data such as FFT Fast Fourier Transform which can reveal vibration frequencies in the measurements We also need to send commands to the PC 104 computer The control commands sent to the PC 104 could be test commands for use during development For example the ignition process could at first be manually controlled by remotely opening and closing the solenoid valves one by one This approach is recommended before implementing an autonomous algorithm It would likewise be attractive if the monitoring program had a graphical user interface A solution to all of the above is to use MATLAB from The Mathworks Inc It offers advanced functions for storing and processing data as well as capabilities for displaying graphs of the data It also offers an easy to use graphical user interface builder called Guide 25 This builder can be used by anyone familiar with MATLAB for designing graphical user interfaces MATLAB however comes short on one point the ability to communicate over the local area network Actually MATLAB does offer interfaces for this kind of communication but not versatile enough for handling the requirements for our communication solution Fortunately the author was familiar with
86. cose a oer nes teat p d E i 69 E 4 2 TypelDSuuc due cec e ete I MM hU E M P C CLE EA 70 E 4 3 Type UD interpretei hean oe Rv eu Re a RR amie arte ad 70 E 4 4 Thread synehron ization estupenda e auod e UU ask te I ERR DU Rea VR 71 E 4 5 Message passing sneen ted eco stica tive EERE R A 71 E 4 6 Remote command re FAV Tg eese ao ec co epe e tube ern eie diss da un patus T2 E 4 7 Sending measurement data over the TCP IP connection eeeeree 72 Bo Remote pltformeontrol usto onse une tete aii Com d dle ede Be S 73 E 5 1 ON cand Linux eliettzz a nt ai Meade uti aita tu Ra ed 73 E 5 2 Windows CHEN dcr e Syed a n et ob ede c eit eet eS e A R 74 E 5 3 Windows client communication model essen 74 E 5 4 Communication link safety protocol 225 auront ester one rte Ra de Ue nn 74 E 5 5 The UL THIBHEACE o eren eect sd cera e oe eee te tete ela Aet vue rd ocei d 75 E 6 Tutorial Using the MATLAB client program ssseseseeereerenenenenenneenen 75 E 6 1 Basic OpSEdt lof oed er Dueh en AeA adi ce cedet e edle 75 E 6 2 Extending the GUI with a servo controller sssseeeeee 76 E 6 3 Expanding the GUI with new measurement displays sese 79 E 6 4 Controlling a solenoid valve iced tico eO pa eem p eibi dde 80 F Data acquisition software driver ose neon er nenne operae enne YF un eet ones e pane ed ae xa Fran orn 83 F 1 Siar ng the drive uua iss tie eot orani ed be aptas
87. ct sockfd struct sockaddr amp their addr sizeof struct sockaddr 1 perror connect exit 1 clifd sockfd Send Command to server value BuildCommandPacket sendbuffer ID START AD if numbytes send clifd sendbuffer value 0 lt 0 if numbytes 1 perror server if numbytes 0 printf sending error 0 bytes sent n pthread create amp listen thread id NULL tcplistening thread NULL usleep 5000 pthread create amp heartbeat thread id NULL Heartbeat thread he value pthread join listen thread id NULL printf Closed An close sockfd return 0 132 H Matlab Code H 1 findGuidata m function GUIhandles GUIObject findGuidata Tag Finds the guidata handles for a running GUI application oo e Tag is a string containing a UNIQUE name of a known fieldname inside your GUI handle structure o oP oe oo Example Assume that you have a handlefield in your application called handles Myhandlefield Simply write shandles findGuidata Myhandlefield or GUIhandles GUIObject findGuidata Myhandlefield Sif you require the object handle as well 9 9 SRemarks 9 It is important that your tagname is unique 9 Don t search for pushbuttonl or editl or 9 Such names that is common for GUI applications SIf you do you might end up retrieving the handles for the wrong Sappl
88. d send itime it value tv sec 1 send itime it value tv nsec 0 send itime it interval tv sec 1 send itime it interval tv nsec 0 The TCP Send thread is nothing but a message dispatcher for rcvid MsgReceive channelid send amp msg sizeof msg NULL if rcvid 0 we got a pulse if msg pulse code TIMER PULSE CODE The timer in this case is used to send feedback data back to the client memset sendbuffer 0 sizeof sendbuffer ptr sendbuffer nsend 0 pthread rwlock rdlock amp ad data rwl This example sends the values of analog channel 1 and two back to the client You can simply add more channels just by adding lines like the ones below nsendt addAnalogData2Buffer amp ptr ID CHANO ad data channel 0 nsendt addAnalogData2Buffer amp ptr ID CHAN1 ad data channel 1 nsendt addAnalogData2Buffer amp ptr ID CHAN3 ad data channel 3 Jk e kx ek e e e Add more analog channel data here EK KK KK ke ke ke e e e Kk pthread rwlock unlock amp ad data rwl if numbytes send servfd sendbuffer nsend 0 lt 0 if numbytes 1 printf Server Data feedback link aborted n timer delete send timer id timer create CLOCK REALTIME amp send timerevent amp send timer id if numbytes 0 printf sending error 0 bytes sent n printf Sent d bytes of measurement data n nsend End of TI
89. d i irq r datarate n n printf runmodes n n normal mode t default n v verbose mode n s silent mode n printf configuration parameters n printf b IO card baseadress hexadecimal default 210 n printf d DMA channel default 3 Wn printf c External clockspeed default 10 Mhz Nn cf cf printf i Irq used default 5 n printf r Data transfer rate Hertz default 2Khz Nn return EXIT FAILURE Check that no pcm3718 device driver is already handling the dev pcm3718 device fd open dev PCM3718 O RDWR O CREAT O EXCL if errno EEXIST printf Error dev PCM3718 device manager already exists nShutting down n return EXIT FAILURE else if errno ENOENT amp amp runmode SILENT perror PCM3718 return EXIT FAILURE if PCM3718 detect dev iobase if runmode SILENT printf Fatal Error nCard not detected at xh n dev iobase return EIO Reset the state vector status device open 0 status dma_set 0 status channel set 0 status pacer set 0 status ad_running 0 status filter attached 0 initialize dispatch interface if dpp dispatch create NULL amp amp runmode SILENT fprintf stderr Ss Unable to allocate dispatch handle n argv 0 return EXIT FAILURE initialize resource manager attributes memset amp resmgr_ attr
90. d if ispc set hObject BackgroundColor white else set hObject BackgroundColor get 0 defaultUicontrolBackgroundColor end function ID CHAN3 Callback hObject eventdata handles hObject handle to ID CHAN3 see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA oe Executes on button press in pushbutton8 138 H 5 rocketclient m function pushbutton8 Callback hObject eventdata handles hObject handle to pushbutton8 see GCBO eventdata reserved to be defined in a future version of MATLAB handles Structure with handles and user data see GUIDATA invoke handles COMh SendCommand ID OPEN VALVE 0 2 Executes on button press in pushbutton 9 function pushbutton9 Callback hObject eventdata handles hObject handle to pushbutton9 see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA invoke handles COMh SendCommand ID CLOSE VALVE 0 139
91. d2 1 maxbuf dev dmabuft dev buflsize dev shmem size int id InterruptAttach IRQ5 isr handler NULL 0 0 boost this thread s priority pthread getschedparam pthread self amp policy amp param param sched priority sched get priority max sched getscheduler 0 1 pthread setschedparam pthread self policy amp param create a communication channel to be used by the main process chid ChannelCreate 0 JC Ck kk ke ke kk ke ke ke ke e ke ek Create a timer Ck kck ck kckckckckckckokckok ck ok ckok ke ke ke e ke e timerevent sigev notify SIGEV PULSE timerevent sigev coid ConnectAttach ND LOCAL NODE 0 chid NTO SIDE CHANNEL 0 timerevent sigev priority sched get priority max sched getscheduler 0 timerevent sigev code TIMER PULSE CODE timer create CLOCK REALTIME amp timerevent amp timer id dev transfer timeperiod 1000000000 dev transfer rate itime it value tv sec 0 itime it value tv nsec v itime it interval tv sec 0 itime it interval tv nsec dev transfer timeperiod BRK RK Ck Ck kk kk kk kk kk kk kk kk kck kk kck kk kck kc k kck kc k kck kk kck kc kckck ck kckckckckckckokckok sk ke ke e kx if runmode VERBOSE printf PCM3718 Copy thread ready and waiting n transfer timeperiod Qu Main message receive loop for 77 rcvid MsgReceive chid amp msg sizeof msg NULL if rcvid 0 we got a pulse if msg puls
92. der to obtain the equations of motion it is often simpler to start from the kinetic and potential energies of the system and then use Lagrange s equations 4 4 2 Lagrange s equations for moving coordinates Euler Lagrange s formulation of analytical mechanics is fundamental in any advanced approach of problems related to classical mechanics Using the system s potential and kinetic energies the equations of motion can be derived using Lagrange s equation of motion which may be stated as a ue 0 4 15 dt 0qg q where q is a generalized coordinate L is an operator known as the Lagrangian defined by L T V 4 16 where T is the kinetic energy and V is the potential energy For translational coordinates Lagrange s equations take a slightly different form other than the equivalent equations for static coordinates above Tho61 The exact derivation is lengthy and is left out in favour of a brief explanation see the book by Thomson Tho61 for further reference The linear momentum P can be represented by P i jt k 4 17 Since force has the dimension rate of change of the linear momentum we have F P QxP 4 18 where Q i j 0 k represents the angular velocities of the body in its body frame Inserting 4 17 into 4 18 yields the Lagrange equations for the translational movement 33 to o dtox OZ Oy x 2 to zi O oT 4 19 dtOy Oh O Sys d OT T T Sr T o T oT a 5 to
93. directory where the files above have been placed then type regsvr32 RocketNetworkProxy dll If successful start MATLAB Make sure MATLAB s current directory is the directory where the files above are located In MATLAB type rocketclient A window similar to the one in Figure E 4 should appear Open the file rocketclient m and locate the line stating invoke handles COMh Connect 169 254 13 200 This is found inside the function pushbutton Callback The numbers inside the string is the internet address of the PC 104 computer During this project it was set to 169 254 13 200 Make sure that the address in rocketclient m corresponds to the IP address of the PC 104 computer Start the PC 104 computer If screen and keyboard is connected to it login using username root and password root When logged in start the data acquisition driver by typing pcm3718 s amp 75 Then start the real time platform by typing netserver Remark It is also possible to login using a remote connection program such as telnet or ssh See Appendix D for details rocketclient Start AD Channel 0 Disconnect Channel 1 Channel 2 Connecting to 169 254 13 200 Connection established Requesting ID names Ready to receive server data stored ID list Value 10 Name ID CHANO Value 11 Name ID CHAN1 Value 12 Name ID CHAN2 Value 13 Name ID CHAN3 Value 14 Name ID CHAN4 Value 15 Name ID CHANS Value 16 Name ID CHAN6
94. dvantages such as real real time support We have demonstrated how the operating system in conjunction with software can control servos solenoid valves and DAQ hardware A short explanation of how the PC 104 can be monitored and controlled using a remote computer was also presented The solutions are vital pieces of the control program architecture Fitting the pieces together in order to create a single program is the next logical step This program has been partially implemented but some vital parts are still missing such as Inertial measurement algorithm Autonomous propulsion control rocket ignition steps Attitude controller Autonomous guidance controller Parachute release control These parts have to be further analyzed and developed before the rocket control system is ready for testing 28 4 Rocket dynamic analysis In order to control a rocket in flight it is necessary to make a dynamical analysis of its performance This includes formulating the equations of motion accounting for the rigid body motion the excitation of the aerodynamic forces rocket engine thrust misalignments and the coupling of the servo system controlling the stability of the rocket attitude Tho61 It is evident that a full analysis is beyond the scope of this project A simplified model may however be obtained using Newton s laws in combination with Lagrange s equations The model can be used as a primary guideline for the formulation of the rocket a
95. e e g myprogram Ctrl c Aborts a program running in the terminal window use Displays help information about a given command or program D 1 2 Changing permissions for a file to become executable Type chmod 775 filename D 1 3 Automatically start programs at system boot From Photon the QNX windows environment open a terminal window and type ped etc rc d rc local The Photon editor will start Type the desired commands programs in the text file Save the file From a terminal window type cd etc rc d chmod 775 rc local The commands in rc local will now be executed at boot D 1 4 Installing QNX 6 2 on the PC 104 using the desktop computer These steps should only be performed if the installation on the PC 104 has stopped working Remark If there are two hard drives installed in the desktop computer exchange all references to hd1 in the commands below to hd2 With a switched off desktop PC insert the Compactflash card from the PC 104 into the desktop PC card holder Make sure the card holder is connected to the computer s IDE interface Boot QNX on the desktop PC On questions about which libraries to bind make sure it is the local disc hd0 Usually the combination to press is F2 then F1 Once logged in open a terminal window and type 61 dinit dev hdl fdisk dev hdl In fdisk delete all old partitions on the CompactFlash card and add a new one with type 77 QNX4
96. e are necessary in order to add functionality In most cases only one line of code is necessary for each new button The idea is that the communication system and the GUI control should be simple enough for non experts to use and extend Here an interesting option appears Since we use the TCP IP protocol for communication the same protocol used on the Internet this means in theory that a person using MATLAB or any COM enabled program on a desktop computer can monitor and or 26 control the autonomous vehicle from anywhere in the world in real time disregarding the effects of transmission delay of the signals over the Internet rocketclient Connect Start AD Disconnect Set Servo 0 Open valve Close valve Value 14 Name ID_CHAN4 Value 15 Name ID CHANS Value 16 Name ID CHAN6 Value 17 Name ID CHAN7 lValue 1024 Name ID START AD Value 1025 Name ID STOP AD lValue 1026 Name ID SET SERVO 0 Value 1027 Name ID OPEN VALVE O0 Value 1028 Name ID CLOSE VALVE 0 Sending message with ID ID OPEN VALVE 0 Figure 3 14 The PC 104 controlling servo and solenoid valve The connectors for data acquisition are located to the mid right in the picture The network cable is seen in the lower left corner 27 3 7 Chapter summary In this chapter we have discussed how real time components can be used for assembling a control program for the hybrid rocket Using the QNX operating system offers many a
97. e code TIMER PULSE CODE We got a timer pulse time to copy the most recent data out of the buffer memcpy dev shmem area dmaptr dev shmem_ size if filterattached Send a pulse to the process containing a filter thread MsgSendPulse chid2 sched get priority max sched getscheduler 0 FILTER PULSE CODE 0 dmaptrt dev shmem size 105 G 7 pcm3718 c if dmaptr maxbuf If we are at the end of the buffer we must wait for a interrupt signal To synchronize the timer Then copy the last data chunk from the DMA buffer before resetting the timer InterruptWait NULL NULL memcpy dev shmem area dmaptr dev shmem_ size dmaptr dev dmabuf InterruptUnmask IRQ5 1 if filterattached MsgSendPulse chid2 sched get priority max sched getscheduler 0 FILTER PULSE CODE 0 timer settime timer id 0 amp itime NULL The timer signal is supposed to be a bit behind the DMA transfers to guarantee that the transfer really has finished before copying else other pulses else if msg pulse code RELEASE PULSE CODE This activates the copy thread timer settime timer id 0 amp itime NULL else if msg pulse code RESET PULSE CODE timer delete timer id timer create CLOCK REALTIME amp timerevent amp timer id else if msg pulse code SHUTDOWN PULSE CODE break jump out of loop else
98. e is divided into a number of threads A good design strategy is to have many threads each performing a specific task Having a small number of threads performing multiple tasks is often more error prone Below is the thread layout of the program netserver 1 A D Filter thread This is the only thread in the program that has access to the data acquisition card It sits like a gateway between the card and the rest of the real time system and converts raw data ones and zeros produced by the data acquisition card into real numbers such as voltages and currents It also filters the incoming data from measurement noise 2 Attitude control thread This thread is basically a feedback control loop It acts on input from the inertial measurement unit and guides the rocket by moving servo motors connected to external fins attached to the rocket body The thread is not yet implemented 3 Rocket ignition and thrust control thread The rocket engine is controlled by the opening and closing of onboard solenoid valves which in turn are controlled from this thread using digital switching circuitry In the current implementation the code for this thread is not implemented This will have to wait until the electrical system for the engine control has been completely designed 4 File logging thread Saves specified data to local file s onboard the PC 104 5 TCP IP Listen thread The feedback communication system uses TCP IP to connect to
99. e is placed on top of the PC 104 CPU module using the PC 104 bus It does not require external power connectors It draws power directly from the bus 2 6 Typical setup Figures 2 5 and 2 6 shows typical setups used during the project Figure 2 5 shows both modules installed together where they have been placed in a cardboard holder in order to prevent damage Once deployed the dual card module will be fitted inside a specially manufactured cage holder inside the rocket Figure 2 6 shows the system installed with most of the external connectors which may be used for connecting to peripheral equipment such as keyboard monitor printer and network Figure 2 5 PC 104 computer unit without external connectors y i lt L m n Figure 2 6 PC 104 computer with most of its external connectors 3 Software design and implementation The rocket control system puts special requirements on the computer language and operating system In this chapter we begin by explaining real time systems and programming Real time software solutions form an important basis for this project Unfortunately real time programming and analysis is not a subject easily explained It is not possible to cover more than the basics in this report A reference for a complete introduction is the book by Burns amp Wellings BW97 which is warmly recommended 3 1 Real time systems A real time system is any information processing syst
100. e to a new position define ID OPEN VALVE 0 1027 Opens a solenoid valve connected to an I O port define ID CLOSE VALVE 0 1028 Close a solenoid valve connected to an I O port Always remember to update the IDMAP below to mirror all the changes made above y BEGIN IDMAP IDENTRY ID CHANO IDENTRY ID CHAN1 IDENTRY ID CHAN2 IDENTRY ID CHAN3 9 G 2 IDList h _9 _VALVE_0 ID OPEN VALVE ID STOP AD ID SET SERVO 0 ID CLOSE ID CHAN5 ID CHANG ID CHAN7 ID START AD ID CHANA ENTRY ENTRY ENTRY ENTRY ENTRY ENTRY ENTRY ENTRY ENTRY IDI ID ID ID IDI ID ID ID ID END IDMAP F E endif 92 G 3 ioports h Digital port control macros Internal state variables unsigned char parportstate 0 unsigned char ioportlowstate 0 unsigned char ioporthighstate 0 define PCM3718 BASE ADRESS 0x210 The base adress must correspond to the physical adress of the card define PPORT 0x378 Defualt Parallell define IOPORTLOW PCM3718 BASE ADRESS 3 Low IO port define IOPORTHIGH PCM3718 BASE ADRESS 11 High IO p define PIN1 1 port output define PIN2 2 port output define PIN3 4 port output define PIN4 8 port output define PIN5 16 pott output define PIN6 32 port output define PIN7 64 port output define PIN8 128 port output port adress D
101. e value int numbytes index pos struct listen timerevent struct itimerspec listen itime char recvbuffer MAXRECVLENGTH Incoming tcp ip packet buffer char buffer 80 char ptr maxptr endptr ID t PacketID int chid filt chid_send pthread cleanup push amp Listen Cleanup NULL if pthread rwlock init amp Command data rwl NULL EOK fprintf stderr Listen thread Error while initating rwlock n 118 G 8 netserver c connect to filter thread chid filt ConnectAttach ND LOCAL NODE O channelid filt NTO SIDE CHANNEL 0 connect to send thread chid send ConnectAttach ND LOCAL NODE O channelid send NTO SIDE CHANNEL 0 Initialize the TCP IP connection if sockfd socket AF INET SOCK STREAM 0 1 perror socket exit 1 my_addr sin_family AF_INET host byte order my addr sin port htons PORT short network byte order my addr sin addr s_addr INADDR_ANY auto fill with my IP bzero amp my addr sin zero 8 zero the rest of the struct if bind sockfd struct sockaddr amp my addr sizeof struct sockaddr 1 perror bind exit 1 if listen sockfd BACKLOG 1 perror listen exit 1 sin size sizeof struct sockaddr in This loop just waits for connections from clients if connection is closed it returns here for printf Server Waiting
102. em which has to respond to externally generated input stimuli within a finite and specified period often called deadline e The correctness depends not only on the logical result but also the time it is delivered e Failure to respond is as bad as a faulty response If the computer is a component in a larger engineering system it is generally called an embedded computer system BW97 3 1 1 Real time control systems A control system may be divided into three subsystems e Measurement e Feedback control loop e Actuation of hardware Real life systems are continuous This often requires the control system to be as closely continuous as possible It is often desirable to make measurements execute the feedback control loop and perform actions on the system at the same time Since a computer only can perform one task at a time three computers would be needed in order for the three tasks to be performed simultaneously which of course is not economically feasible Instead methods have been invented which allow computers to perform several tasks simultaneously using only one central processing unit CPU The trick is to switch the task currently performed so fast that it appears that the computer is performing all three tasks simultaneously This is the general idea behind real time systems Before proceeding we need to distinguish between four types of real time e Soft real time systems where deadlines are important but which will st
103. en 134 HA Batareevdllandlet it see a dnte obe e AQ ide dise rad dta Ba Gada eG Putus 134 ELS XOC Rete Hentai access p epe s EN AM LM E Me dm E 135 ix 1 Introduction The Robotics and Mechatronics Research Laboratory RMRL is investigating the possibility of launching an autonomous hybrid rocket The investigation consists of several studies and smaller projects mostly performed by final year students at Monash University The project presented in this report investigates the onboard computer and attitude control system Before autonomous algorithms can be constructed problems such as choosing the appropriate operating system for the onboard computer as well as low level control of underlying hardware have to be solved RMRL has several ongoing projects in the field of autonomous flying vehicles Besides the hybrid rocket it is worth mentioning another project investigating a similar control system for a small scale helicopter Most of the practical solutions apply to both of these projects and several of the results and even the software components can be reused This study however deals with rockets which thus will be the focus of this report 1 1 Rocket modules The rocket will consist of several individual parts or modules The main modules are 1 Structural such as casing and mounting 2 Hybrid rocket motor with propellant and oxidizer 3 Inertial Measurement Unit IMU 4 Attitude and guidance system 5 Power supply 6
104. endPulse chid send pulseprio COMMAND PULSE CODE ID STOP AD break case ID SET SERVO 0 An example for remotely moving a servo pos strtoul ptr amp endptr 10 if pos gt 254 endptr ptr 0 printf Cannot set servo position s n ptr else set servo servo 0 pos break Fl Ce case ID OPEN VALV 120 G 8 netserver c SetPPin PIN2 1 Since Ignition thread is controlling PIN1 let s use PIN2 break case ID CLOSE VALVE 0 SetPPin PIN2 0 break fFFRAEREX Add Your new ID packet interpreters here 44v eoe If no package handler could be found we assume an error has occured default printf Unkown command receiced ID d n ntohs PacketID asUintN Switch If we got packet id else printf Error Data packet received but no Packet ID was in it n Skip ahead to next packet ptrt strlen ptr 1 while there is still data left in buffer if numbytes gt 0 bff EOGI You will end up here if the client closes the connection You should reset all states Stop ad conversion if it is running MsgSendPulse chid filt pulseprio COMMAND PULSE CODE ID STOP AD while All cleanup code goes here close sockfd pthread cleanup pop 1 return 0 A simple wrapper for adding analog data values to the send buffer used in the sending thread int addAnalogData2Buffer char buffer int ID double dvalue
105. ere OscilatorFrequency is either 1 or 10 Mhz as set by jumper 1 C1 and C2 are integer numbers both between 2 and 65535 These two numbers are passed inside a double uint structure as defined in pcm3716 h Example This example sets the sampling frequency to 100kHz assuming a 10 MHz clock double uint pacerdata pacerdata cl pacerdata c2 10 devctl card fd DEVCTL SETPACER amp pacerdata sizeof pacerdata NULL F 2 3 DEVCTL SET TRANSFER RATE Parameter type unsigned int Description Sets the transfer rate defined by the int parameter This can only be done before issuing the DMA init command Be aware of that the pacer speed divided by the transfer rate should be an integer for the driver not to loose data Example unsigned int rate rate 2000 Sets the new speed to 2000 Hz devctl card fd DEVCTL SET TRANSFER RATE amp rate sizeof rate NULL F 2 4 DEVCTL DMA INIT Parameter type None Description This command can first be issued once the pacer speed has been set Besides initializing the DMA controller it calculates the sizes and allocates memory for the necessary memory buffers Once this command has been issued it is not possible to set the pacer to a new value or reinitialize the DMA buffers except after first closing the connection to the device and then reopen it Example 85 devctl card fd DEVCTL DMA INIT NULL 0 NULL F 2 5 DEVCTL
106. eret apad Pe eren eee Rd E Ca eai 59 D Using NOD sate P pL EN 61 Dil Mini how to eei tecto ede ata ante toto tee ia des Gade REI A 61 D 1 1 Often used console commands uie tion to bru s e RENS PUMP UIS SNR ERAN R ESPERA NGA 61 D 1 2 Changing permissions for a file to become executable 61 D 1 3 Automatically start programs at system boot 61 D 1 4 Installing QNX 6 2 on the PC 104 using the desktop computer 61 D 1 5 Disabling Photon DOOt siio tertie ben teen tar ec epe en e reete din sous 62 D 1 6 Setting up the network E Loco de ee eu aser eee hmi ut ae alise as 62 D 2 Software development In QNX usi us reto dtd es Sas ae 63 D 2 1 Programming In QNX Leeds tete tea obe oer per onte ne ud ecuatoriana 64 D 22 Compiling C programs cue adu rose dida Reg nne acce mien tes ear et oui oss 64 D 2 3 Using a remote terminal to access a QNX computer sess 64 D 2 4 Copying files between two computers using ftp sess 65 viii E Software framework for autonomous vehicles eeeeeeeeeeeeeeeeeeeen ene 67 E File SCs n et doo audeo ans rop tiat e b idus M ne AP M E 67 E 2 Threads and the C language ces oe err eie eren eor vae A borers 67 E 2 1 Thread OVELUIG D utet ee ee e voe etd e ar mde 68 E3 vDafa interehange oso dtd oe Deed asia D Maa ret M 69 E 4 Platformicomtmublcalion iari riri s Pepe er den er ia oi ei ro idet vendu dau ella da 69 E 4 1 Cormmunicauon protocols eod etaed
107. ering and transfer The attitude control thread is also a good candidate for being split into multiple threads Most likely it will be converted to at least three threads each stabilizing one of the Euler directions roll pitch and yaw We will discuss feedback controllers and Euler rotations in more detail in chapter 4 For the sake of discussion we will stick to one thread only knowing that it just acts as a placeholder for a more complex system in the final design The four threads of the communication system need some explanation First in order to achieve what is known as full duplex i e sending and receiving data at the same time we require two threads one that listens for incoming data over the network Listen thread and one that sends data over the network Send thread The properties of the TCP IP protocol have some drawbacks One of these concerns the possibility to detect when the computer at one end of the established link has crashed has become locked up or something similar i e the link is open but one side of the link has stopped responding One way to solve this problem is by sending keepalive or heartbeat data over the link even when no actual data is being sent In this way one side of the link can detect when the other side has stopped responding This is very important in real time applications Suppose the autonomous vehicle keeps a communication link open using TCP IP during normal operation If the link is co
108. ertial measurement Autonomous propulsion control ignition steps Attitude and guidance controller in C code Parachute release control 5 1 1 Inertial measurement The inertial measurement unit needs to be completed and tested Also the output from the software algorithm that calculates the positions velocities and rotations need to be connected as input to the attitude controller If the inertial measurement algorithm is a separate thread in the control program shared memory areas with protections such as R W locks discussed in Chapter 3 or similar may be employed 5 1 2 Propulsion control Using the propulsion control interface described in Chapter 3 code implementation found in Appendix G it should be possible to develop a script that performs the necessary steps of the ignition process see section 3 4 3 5 1 3 Attitude and guidance controller Chapter 4 gives an introductory explanation of the rocket dynamics It does not however discuss the relationship between the torques acting on the rocket and the corresponding angles of the movable fins relative the rocket body This study is required in order for the attitude controller to function This kind of study is not well suited for a theoretical approach and we 49 will have to rely on wind tunnel tests or other types of measurements performed once the rocket has been assembled 5 1 4 Parachute release control The parachute release has not yet been studied Questions such a
109. es int HBsockfd listen on HBsock fd struct sockaddr in my addr my address information struct sockaddr in their addr connector s address information int sin size n maxnalarms 5 struct timeval timeout char c fd set rfd if HBsockfd socket AF INET SOCK STREAM 0 1 perror Heartbeat return my addr sin family AF INET host byte order my addr sin port htons KEEPALIVEPORT short network byte order my addr sin addr s addr INADDR ANY auto fill with my IP bzero amp my addr sin zero 8 zero the rest of the struct if bind HBsockfd struct sockaddr amp my addr sizeof struct sockaddr 1 perror HeartBeat close HBsockfd return if listen HBsockfd BACKLOG 1 perror Heartbeat close HBsockfd return sin size sizeof struct sockaddr in if heartbeat fd accept HBsockfd struct sockaddr amp their addr amp sin size 1 perror Hearbeat close HBsockfd return printf Server got Keepalive Connection from s n inet ntoa their addr sin addr FD ZERO amp rfd FD SET heartbeat fd amp rfd timeout tv sec 1 timeout tv usec 0 FD ZERO amp rfd while 1 FD SET heartbeat fd amp rfd switch n select 1 heartbeat_fd amp rfd 0 0 amp timeout case 1 perror select return case 0 117
110. es of data D 10 Value 09 997559 D 11 Value 09 997559 eceived 30 bytes of data D 10 Value 09 997559 D 11 Value 09 997559 eceived 30 bytes of data D 10 Value 09 997559 D 11 Value 09 997559 eceived 30 bytes of data 10 Value 09 997559 Value 09 997559 eceived 30 bytes of data 10 Value 09 997559 Value 09 997559 Figure E 3 Linux session running TCP IP client 173 E 5 2 Windows client A Win32 client has also been developed using Microsoft Visual C The program has no direct user interface or control Instead it is designed to be integrated as part of other Windows programs that support Microsoft ActiveX and COM technologies One such program is MATLAB for windows version 6 5 Besides supporting advanced tools for numerical analysis MATLAB offers a built in graphical user interface GUI builder called Guide The builder can be used to construct custom GUIs by dragging and clicking It requires basic skills in MATLAB programming and is very easy to learn E 5 3 Windows client communication model The C program sits as a proxy between the Windows operating system and MATLAB The proxy offers a number of methods or functions enabling MATLAB to communicate with the QNX system The methods are found below Table E 5 Proxy methods Name Parameters Description Connect Internet address of remote Connects to the QNX server using host TCP IP network Disconnect Disconnects the ope
111. ested at the same frequency as the feedback control loop Thus the A D data update frequency inside the client must be at least as high as or higher than the frequency of the feedback control loop There are two strategies for synchronizing data transfers from the resource manager 1 Asynchronous The client acquires data by sending requests to the resource manager The resource manager then sends the data back to the client using shared memory objects 2 Synchronous The resource manager is responsible for the correct timing of the data transfers The manager notifies the client each time updated data in the shared memory area is present see Figure 3 7 The first method is easiest to implement Unfortunately it can cause unexpected problems When the client requests data from the resource manager the manager might not be able to respond directly Besides transferring data to the client the resource manager has to react on hardware interrupts caused by the DAQ hardware This requires some extra work to be performed at specific intervals which may cause delays and timing errors in the data transfer that cannot be foreseen by the client 17 The second method requires more setup and initialization by the client in order to work The benefit however is that it is the resource manager which keeps track of the time for data transfer Thus the resource manager can prepare in advance for the transfer of data This gives a very good ti
112. ev CLK speed sd n dev IRQ ransfer rate dHzMn dev transfer rate te a context structure dispatch context alloc dpp the resource manager message loop dispatch block ctp NULL amp amp tderr PCM3718 block error n IT FAILURE runmode SILENT handler ctp 115 G 8 netserver c G 8 netserver c TCP IP Enabled Rocket Control Platform x x k include stdio h include lt stdlib h gt include lt errno h gt include lt string h gt include lt sys ioctl h gt include fcntl h include lt sys netmgr h gt include hw inout h include lt sys mman h gt include lt sys neutrino h gt include lt devctl h gt include lt sys iofunc h gt include pcm3718 h include pulsecodes h include IDList h include ioports h include servocontrol h define PORT 6322 the port users will be connecting to define KEEPALIVEPORT 6323 Port for Keep alive data define BACKLOG 10 how many pending connections queue will hold define MAXSENDSIZE 512 Size of TCP IP send buffer define MAXRECVLENGTH 512 Size of TCP IP receive buffer define MAXDATASIZE 256 Size of shared Command data memory area define DMABUFFERSIZE 100 Maximum size of the DMA buffer used by the filter const char HeaderStart 3 0OxFF OxFE OxFE int sockfd servfd card fd heartbeat fd servo listen on sockfd new connection on
113. ex sizeof HeaderStart break if index sizeof HeaderStart printf Error Data packet received but no correct Packetheader was found continue if ptr maxptr 2 We got Packet ID memcpy PacketID asChar ptr 2 ptrt 2 switch ntohs PacketID asUintN f THIS IS THE INCOMING Packet Type ID INTERPRETER x case ID ROIDNAMES Client is requesting IDs and names from Server printf Request acknowledged Nn MsgSendPulse chid send pulseprio COMMAND PULSE CODE ID ROIDNAMES break case ID START AD Client requests AD conversion to begin MsgSendPulse chid filt pulseprio COMMAND PULSE CODE ID START AD MsgSendPulse chid send pulseprio COMMAND PULSE CODE ID START AD These lines are just an example how to send textmessages back to the client First we must lock the resource we want to use pthread rwlock wrlock amp Command data rwl Then we fill it with some data Command data id ID TEXTMESSAGE sprintf Command data buffer Starting A D Conversion Then we unlock the memory area so other threads can access it pthread rwlock unlock amp Command data rwl Send a pulse to the send thread to send some data away MsgSendPulse chid send pulseprio COMMAND PULSE CODE ID SENDDATA break case ID STOP AD Client requests AD conversion to halt MsgSendPulse chid filt pulseprio COMMAND PULSE CODE ID STOP AD MsgS
114. for client connection n if servfd accept sockfd struct sockaddr amp their addr amp sin size 1 perror accept exit 0 pthread create NULL NULL Heartbeat thread NULL printf Server got connection from s n inet ntoa their addr sin addr f Kk RK e k e ke e ke e e e TCP IP Listening Loop Ck ckckckckckck kk kk ke ke e ke e e x for Listening for TCP data while connection is open memset buffer 0 sizeof buffer if numbytes recv servfd recvbuffer sizeof recvbuffer 0 lt 0 if numbytes 0 printf Server Connection closed by peer n close servfd The heartbeat server silently closes down when it s connection is broken close heartbeat_ fd break else if numbytes 1 perror server close servfd break else numbytes gt 0 i e we got some incoming data ptr recvbuffer recvbuffer numbytes N0 maxptr ptrtnumbytes 119 G 8 netserver c printf Received d bytes of dataMn numbytes while ptr maxptr While there is still data left in buffer index 0 Skip ahead to beginning of packet header while ptr HeaderStart index amp amp ptr lt maxptr ptr if ptr maxptr printf Error Data packet received but no Packetheader was found continue Check for correct packetheader whil ptr HeaderStart index amp amp ptr lt maxptr Ttptr if ind
115. for the choice of reference directions we should place the x axis in the nominal direction of travel roll axis the z axis nominally down towards the local vertical yaw axis and the y axis such that it completes the right hand system pitch axis In the case of a rocket it is worth noting a potential problem using this choice of axes If the pitch angle is 90 then there is a singularity in the Euler angles If the rocket is launched vertically its pitch attitude would be 90 and its yaw and roll angles cannot be uniquely resolved Such problems can be overcome with a more suitable choice of axes FS95 4 5 2 Resolving the Euler angles in flight Using the Euler angles and rotations described we may deduce the relationship between the Euler angles and the angular velocities of the aircraft The result can be found in FS95 and is reproduced below o wsind 0 cos y cos Osin 4 39 o cos cos sin More important is the inverse relationship V o sin d o cos cos 0 0 0 cos o sing 4 40 0 sing cos tan 8 For small angles then y c and zo Integrating 4 40 the attitude in form of the Euler angles can be obtained from measured components of the angular velocities Note that the singularity at 9 90 appears in the form of a tan 0 which leads to problems performing the integration FS95 The matrix for transforming the velocity vector from the axes
116. gned int cl unsigned int c2 double uint Struct filled by client when attaching a filter thread to this resource manager S typedef struct int channelid Channel id of a channel created by the client process using ChannelCreate pid t pidid The Process ID of the calling thread process attachfiltersend t Struct filled by resource manager when replying to a filter attach operation typedef struct unsigned int size The size in bytes of the shared memory area unsigned char shm name 30 The name of the shared memory area Same as SHM NAME above attachfilterreply t Union containing both the message and reply structures of the attach filter message passing typedef union attachfiltersend t data attachfilterreply t reply attach message t e This is the Devetl Control Macros f xw xxewkkkwkekw define CMD CODE 1 Just an arbitrary number used as a relative reference for the manager define DEVCTL SETCHANNEL _ DIOTF DCMD MISC CMD CODE O channel setup data t Sets the channel range of the card define DEVCTL SETPACER DIOTF DCMD MISC CMD CODE 1 double uint Set the pacer speed define DEVCTL DMA INIT DIOTF DCMD MISC CMD CODE 2 NU Inits DMA controller and buffers define DEVCTL AD START DIOTF DCMD MISC CMD CODE 3 NULL Start A D conversion define DEVCTL AD STOP DIOTF DCMD MISC CMD CODE 4 NULL Stops A D conversion define DEVC
117. he frequency used by the onboard pacer IRQ 2 3 4 5 6 or 7 default 5 The software driver uses an interrupt to synchronize the local timer used for data transfers done approximately 2 4 times second for normal operation settings In 83 reality this is not a jumper setting but it is not likely the user will need to change the IRQ value while the driver is running r Transfer rate default 1000 Hz This tells how many times per second the driver will notify the client that new data has arrived This parameter can also be set directly from the client program during card initiation Example To start the device driver in silent mode using IRQ 7 1 Mhz clock frequency and tansfer rate of 2kHz type pem3718 s c 1 i 7 r 2000 amp F 2 Controlling the DAQ card Once the driver is running it creates a device in dev PCM3718 Client programs open this device by issuing an open command The client program can then issue control commands to the device driver which sets up the card in a desired fashion The commands are sent using the devctl function which is a QNX variant of the ioctl function found in operating systems such as UNIX or Linux The devctl function takes 5 arguments 1 the file descriptor for the open connection retrieved from open A control code macro specifying the operation to perform A pointer to a parameter whose type depends on the control code The size of the parameter Not used
118. hich describes the moment about O Taking the time dependence into consideration this can be written as z t 10 t 4 4 4 3 1 PID controller We may obtain a PID controller for the system described by 4 4 by performing a Laplace transformation T s 1 s s s amp 0 6 0 4 5 Assuming 6 0 and 6 0 to be 0 for convenience the transformed function s becomes G s TTG 4 6 Adding a PID controller the system shown in Figure 4 3 is obtained Variables used are 6 K T and Ta which represents the desired angle and the three parameters of the PID controller Figure 4 3 PID controlled system The closed loop form of the system in Figure 4 3 becomes Q s _ T s K s T O s I s T s K s T 4 7 4 3 2 State space controller with integral action Using 4 4 the system can also be described by two states x and x2 corresponding to the variables Q and respectively A state space model may then be obtained as follows 3 0 25 4 8 ipsia EM I I Jm ela Ax Bu u 4 9 X 0 Oj x 1 I y Cr Du q 4 10 X 31 Figure 4 4 State space model The state space model can be controlled using a linear controller which may be further extended by the addition of integral action In effect the model now acquires the properties of a PI or PID controller thus making it more robust FPE02 The desired system Figure 4 5 is obtained by augmenting an extra state x into our previo
119. hread during cleanup iri void RW Destroy void arg usleep 2000 pthread rwlock unlock amp ad data rwl if pthread rwlock destroy amp ad data rwl EBUSY printf Error Write lock was found in a busy state n The Analog filter thread This is a simple digital measuremnt noise filter Only this thread is in control of the data acquisition card PCM3718 Other threads can in a way control the card by sending messages to this thread But it is up to this thread how when and if these messages will be executed ai void filter thread void arg unsigned char buffer DMABUFFERSIZE unsigned char dmabuf channel setup data t channel setup data typedef enum BIPOLAR UNIPOLAR polartype t These two arrays are used for the calculation of the voltage number of a channel const polartype t polartype 9 BIPOLAR BIPOLAR BIPOLAR BIPOLAR UNIPOLAR UNIPOLAR UNIPOLAR UNIPOLAR BIPOLAR const double rangevalues 9 10 0 5 0 2 5 1 25 10 0 5 0 2 5 1 25 20 0 int AD is running 0 An internal state variable to keep track of the A D converter int ret rcvid i fd2 N channelnr intval unsigned int bufsize attach message t fm MSG msg unsigned char ptr bufferend double alphal alpha2 dval double uint pacerdata unsigned int filter speed 2000 This filter is filtering 2000 times Second The thread starts with initializing the Data acquisition card The outline
120. ication 9 O findGuidata Tag returns 0 if the specific handle cannot be found function GUIhandles GUIObject findGuidata Tag GUIhandles 0 GUIObject 0 if ischar Tag h allchild 0 index 1 if length h 1 return end while index lt length h amp amp isfield getappdata h index UsedByGUIData_m Tag 0 index index 1 end if index length h return else GUIhandles guidata h index GUIObject h index end else fprintf Error in findGuidata Tag must be a string end H 2 KeepaliveHandler m function KeepAliveHandler varargin Find the rocketclient handles using the unique tag COMh apphandles hObject findGuidata COMh invoke apphandles COMh KeepAlive 133 H 3 ConnectionstatusHandler m function ConnectionstatusHandler varargin Find the rocketclient handles using the unique tag COMh apphandles hObject findGuidata COMh status varargin 3 if status 1 Connected disable connect button and enable disconnect button set apphandles pushbuttonl Enable off set apphandles pushbutton2 Enable on apphandles connected 1 else set apphandles pushbuttonl Enable on set apphandles pushbutton2 Enable off apphandles connected 0 end guidata hObject apphandles H 4 DatarecvdHandler m 9 Event Handler function from RocketNetworkProxy function DatarecvdHandler varargin Find
121. ig nophoton To automatically boot back into Photon again simply remove the file nophoton D 1 6 Setting up the network card The easiest way to configure the network settings is to use Photon Click on the network button from the launch bar a new window will appear QNX offers two types of settings 62 Manual which lets the user enter an IP address and DHCP which dynamically sets the address Note that the QNX computer needs a connection to a DHCP enabled network for the latter to work Q These are the networking devices detected on this computer Click here to toggle the display of advanced options such as IP aliasing Connection Enable Device IP 169 254 13 200 Metmask 255 255 0 0 Figure D 1 TCP IP configuration D 2 Software development in QNX QNX does not offer an integrated development environment at least not in the non commercial version Using the Photon windowing environment makes the development process a lot easier A typical working session consists of a number of open windows and programs Using a text editor it is possible to write code A terminal window can further be used to compile the code An extra terminal window running sftp secure ftp or ftp is used in order to copy the compiled program to the PC 104 Finally a third terminal window running ssh or telnet with an open connection to the PC 104 is used to execute and test the programs Testing the programs on the PC 104 is necessary if
122. ill function correctly if deadlines are occasionally missed e g data acquisition systems Common operating systems such as Windows and Linux also fall into this category e Firm real time systems which are soft real time but for which late delivery of service is detrimental i e any response received after a missed deadline is considered to have no value This is in contrast to a soft real time system where a late response still holds some valuable information e Hard real time systems where it is imperative that responses occur within the required deadline e g flight control systems e Real real time systems which are hard real time and where the response times are very short e g Missile guidance systems In this report we will concentrate on hard and real real time systems for obvious reasons 3 1 2 POSIX In early days only sequential programming languages were available Examples are Pascal C and FORTRAN Programs written in these languages have a single thread of execution They start executing in some state and continue executing one instruction at a time until the program terminates Today there are a number of so called concurrent programming languages such as ADA Occam2 and Modula These languages allow the programmer to write code that if possible executes concurrently on the computer BW97 An alternative approach for achieving concurrency is to use a sequential programming language and an operating system
123. in order to send measurement data back to the remote client for data collection and or analysis The remote client can also send two commands to the PC 104 server As a convention command identifiers start at 1024 E 4 3 Type ID interpreter When data packets arrive over the network to the server program the 16 bits containing the Type ID type identifier needs to be converted into a format which it can understand and act upon This is automatically performed by the TCP IP Listen thread By comparing the received number with the macros defined in IDList h using a switch statement the Listen thread can both decipher and act upon the command or relay it to other threads A minimal command interpreter can be found below switch ntohs PacketID asUintN case ID START AD this macro is defined in IDList h MsgSendPulse chid filt pulseprio COMMAND PULSE CODE ID START AD MsgSendPulse chid send pulseprio COMMAND PULSE CODE ID START AD M9 break case ID STOP AD so is this macro MsgSendPulse chid filt pulseprio COMMAND PULSE CODE ID STOP AD MsgSendPulse chid send pulseprio COMMAND PULSE CODE ID STOP AD break This interpreter treats two incoming commands ID START AD and ID STOP AD as defined in DList h The structure PacketID contains the value of the ID in network byte order the function ntohs is used in order to convert from network byte order t
124. indow Remark Tag names can in reality be anything as long as the user remembers them when editing the code in the corresponding m file rocketclient fig File Edit View Layout Tools Help eB RAS or ct St Conne art AD Channel 0 Disconnect Set Servo Channel 1 Channel 2 Tee Figure E 6 GUI with servo control Open the m file rocketclient m Guide has automatically written code for us in this file Locate the callback code for the new pushbutton pushbutton4 It should look like this function pushbutton4 Callback hObject eventdata handles hObject handle to pushbutton4 see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA At the end of this function add the following line invoke handles COMh SendCommand ID_ SET SERVO O get handles edit4 String Save and close the file 78 Now start the program by typing Rocketclient Make sure the modified version of the netserver program is running on the PC 104 following the same procedure described earlier Push the connect button and wait for connection Now try to enter a number between 0 and 254 in the edit box and then push the Set servo button If everything has worked out ok the servo if there is one connected on PWM channel 0 should move to the corresponding position rocketclient SENSE Channel Q Disconnect Set Servo 200
125. int pageRegs 0x0087 0x0083 0x0081 0x0082 0 0x008B 0x0089 0x008A unsigned int countRegs 0x0001 0x0003 0x0005 0x0007 0 0x00C6 0x00CA 0x00CE unsigned int baseAddrRegs 0x0000 0x0002 0x0004 0x0006 0 0x00C4 0x00C8 0x00CC define define define define define define define define define define define define define define define define define define define define define PAGE ADDR reg ch COUNT reg ch BASE ADDR reg ch CLR B YTE PTR reg ch MODE SNGL reg ch ASK reg ch D ti INIT DISABLE INIT ENABLE ch 4 ENAB E ch ch lt 4 INPUT OUTPU DISABLE m 1 lt lt 2 ch 4 ch pageRegs ch countRegs ch baseAddrRegs ch 0x00C 0x00D8 4 lt 4 Ox0OOB 0OxOOD6 lt 4 0x00A 0x00D4 ch ch 4 ch ch 4 ch 4 90 G 2 IDList h G 2 IDList h ifndef ID LIST H define ID LIST H finclude arpa inet h f Kk kk e ke e ke e ke e ke ek ID LLST Definitions and macros XCkckckckckck ck kk ke e ke x e x DO NOT EDIT typedef union char asChar 2 uintl6 t asUintN ID t typedef struct const char ID Name const unsigned int ID Value IDENTRY t define IDMAP SIZE sizeof IDMAP sizeof IDENTRY t define BEGIN IDMAP const IDENTRY t IDMAP define END IDM
126. ion solution and for implementation of the communication protocol little time remained for the graphical user interface or GUI for short Now recall that in order to control the rocket we need to be able to open and close solenoid valves and to control servo motors We also need to monitor internal signals such as those representing velocities and attitude This was kept in mind when designing the GUI presented in Figure 3 13 It offers a simplified view of what the GUI may look like once it is fully developed In Figure 3 13 we have a small number of buttons and text boxes Two buttons take care of the remote connection to the PC 104 computer and the other buttons may be used either for starting the ADC for setting a connected servo to a specified position or for controlling the state of a solenoid valve In addition the GUI displays four A D conversion channels in some pre specified unit e g Volts It also incorporates a text window which informs the user about all communication events e g when the connection is opened or closed Figure 3 14 shows a corresponding setup of the PC 104 computer used in conjunction with the program A quite nice feature of the MATLAB GUI builder is the drag and drop solution for the graphical components With a mouse click the new buttons may quickly be added to the GUI without going through the time consuming process of compiling the program Once the new buttons have been installed only a few lines of MATLAB cod
127. ions in a sequence The effect of concurrent execution can be mimicked by allowing all processes to utilize the CPU for a very short time period or timeslot It is the task of the scheduler to choose the process to execute during a timeslot The scheduler is often a process of its own usually belonging to the kernel of the operating system 3 2 3 Communication through shared variables The correct behaviour of a concurrent program is critically dependent on synchronization and communication between processes and threads A common situation is when a specific action in one thread only occurs after a specific action in another thread Communication means passing of information between two processes or threads Synchronization is an important part of the overall design of a concurrent system Synchronization can be seen as communication without content i e the synchronization itself represents the required information Communication and synchronization is usually based upon either shared variables or message passing Shared variables are objects accessed by more than one process or thread Communication and synchronization is therefore possible by making reference to the variables when appropriate The most common form of communication using shared variables is access to a part of the system where only one process thread is allowed at any one time Most hardware components fall into this category for example printers graphics and I O devices This
128. is often enough is always reoccurring when working with analogue measurement systems The frequency fy is the maximum frequency allowed as input to the measurement system If there is indication that the signal could contain higher frequencies than fy then the signal need to be filtered before it enters the ADC Otherwise aliasing will distort the converted signal In other words a low pass filter should always accommodate an analogue to digital measurement solution A 1 Range accuracy and resolution An ADC like any measurement device is classified by three characteristics e Range The input and output range where the device operates e Accuracy The statistical accuracy of the measurement e Resolution The sensitivity of the device change of output divided by change of input It is possible to freely choose in which range the converter operates The choice of range widely affects the resolution of the measurement as will be shown The accuracy however is often dependent on the hardware itself For this purpose potentiometers for tuning are often located in conjunction with the ADC A 2 Digital representation Sampled signals are stored in a computer using digital representation i e bits The more bits used for acquiring a sample the higher resolution is obtained For example if eight bit resolution is used then 25 256 unique values can be used to represent the measurement In a computer digital words start at zero This means
129. it uses the data acquisition card servo controller or other special hardware The Photon windowing environment offers an excellent documentation and help facility To launch it click on Help either from the launch menu or the launch bar Here everything there is to know about programming in QNX can be found including definitions examples and articles tsi im File Edit View Bookmarks Help 5 t 9 amp EB Home Print Back Forward Up Find Where Mark Contents Bookmarks History Options MsgReceive MsgReceive r Section QNX Neutrino RTOS 6 2 Library Reference M main to munmap device memory MsgReceive MsgReceive r Search results u E TOLA MsgReceive MsgReceive_r PTE CA SEPA SEL Wait for a message or pulse on a channel D MsgRead MsgRead_r MsgRead MsgRead r Synopsis MsgReadv MsgReadv r MsgReadv MsgReadv r i ino h gt CESISSESSUEERCNENS include sys neutrino h MsgReceive MsgReceive r bell int MsgReceive int chid MsgReceivePulse MsgReceive void msg MsgReceivePulse MsgReceive int bytes MsgReceivePulsev MsgReceiv struct msg info x info MsgReceivePulsev MsgReceiv MsgReceivev MsgReceivev r int MsgReceive r int chid MsgReceivev MsgReceivev r void msg MsgReply vs MsgError int bytes struct msg info info MsgReply MsgReply r purl Dk Arg
130. ket ID was in it n Skip ahead to next packet ptr t strlen ptr 1 while there is still data left in buffer if numbytes O0 b fortia All cleanup code goes here return 0 int BuildCommandPacket char buffer int ID const char data int numbytes ID t IDnumber char ptr buffer memset buffer 0 sizeof buffer memcpy ptr HeaderStart sizeof HeaderStart ptr buffert sizeof HeaderStart numbytes sizeof HeaderStart IDnumber asUintN htons ID memcpy ptr IDnumber asChar 2 ptr 2 numbytes t 2 strcpy ptr data numbytes t strlen data c1 return numbytes int main int argc char argv int sockfd value chid numbytes struct hostent he struct sockaddr in their addr server s address information char sendbuffer MAXSENDSIZE 1 pthread t listen thread id heartbeat thread id if argo 2 fprintf stderr usage client hostname n exit 1 if he gethostbyname argv 1 NULL get the host info herror gethostbyname exit 1 131 G 8 netclient c if sockfd SOCket AF INET SOCK STREAM 0 1 perror socket exit 1 their addr sin family AF INET host byte order their addr sin port htons PORT short network byte order their addr sin addr struct in addr he h addr bzero amp their addr sin zero 8 zero the rest of the struct if conne
131. kind of synchronisation is known as mutual exclusion and common solutions used for providing this functionality are semaphores monitors and critical sections They will though not be treated in this text For further reading see the book by Burns and Wellings BW97 Another important shared variable mechanism is the Read Write lock or simply R W lock The R W lock is a mechanism that prevents threads from writing to a specific data area simultaneously If this happens data will probably be corrupted thus allowing only one thread to write to the memory area at any one time If no thread is writing no changes will be 11 made to the data in which case the R W lock allows read accesses by multiple threads simultaneously thus increasing data throughput The R W lock is the mechanism used in this project for attaining mutual exclusion 3 2 4 Communication through message passing The other type of communication is message based A message based system requires a sender a receiver and sometimes a medium for passing the message This can be a message box or a communication channel Customarily there are three different types of message based communication e Asynchronous The sender proceeds immediately regardless of whether the message was received or not Asynchronous communication is found in several operating systems as well as in POSIX e Synchronous The sender proceeds only when the message has been received Synchronous se
132. king pre emption causing a timing delay of the control algorithm Therefore we need to choose a lower priority for the inertial measurement algorithm say 12 If the attitude control thread should wake up and pre empt the inertial measurement algorithm it will have to wait until the algorithm has finished executing This scenario is unacceptable In other words we must guarantee that each time the attitude control thread starts executing the inertial measurement algorithm has completed its task This can be solved by first performing an analysis of the execution times of each thread in the system We then decide update frequencies for the measurement and control loops such that their execution windows never coincide The other threads in the system can be left at priority 10 The propulsion system can be considered to be more important than the other threads at priority 10 But because of the fact that the thread will only execute a few lines of code opening closing valves it was not considered necessary to raise its priority 23 3 5 2 Synchronization Another matter that needs to be discussed is that of synchronization We mentioned in section 3 2 4 that we use pulses for almost all communication Pulses are used for passing events between threads and real time objects such as timers All threads that rely on events from other threads or timers possess message retrieval loops making them wait for some event to occur e g a timer or an event
133. l measurement propulsion control and attitude control are basically the three subsystems needed for producing a working rocket control system There are however a few more subsystems necessary in a good design Maintenance and troubleshooting sooner or later will be required It is then a distinct benefit to have stored data available for system operation in order to localize both system errors and analyze its performance A subsystem that might be of interest concerns the communication between the autonomous vehicle and some remote computer acting as control and observation centre Storing data locally on a solid state hard disk is another option If there is a working communication system local data logging might not be preferred to the option of storing data in the remote system 3 4 Implementation of lower layer components We have briefly discussed the necessary components for a real time system and what we need in order to implement our particular system In Figure 3 1 we presented an overview of the software control system In this section the software implementation is described along with a discussion of the components in the lower layer The components needed are Data acquisition software driver Servo control interface Propulsion control interface Communication protocol 3 4 1 Data acquisition software driver An inertial measurement unit requires proper data acquisition routines and hardware in accord This project concentrates
134. l relevance for the rocket and motor studied in this project We only consider the case of a conic mass distribution The cylindrical distribution shows almost identical behaviour As a reference we use the case where there are no cross coupling between the axes This can be achieved by letting the rotation around the x axis roll be zero We may then observe e g the y axis applying a torque of say 0 5 Nm The result is shown in the graph found in Figure 4 10 below Since in this case most of the terms are zero the angular velocity increases almost linearly The reason for the increasing slope is that the rocket is loosing mass making it more sensitive to external disturbances such as torques Next we add a very small rolling torque around the x axis of say 0 01 Nm We still apply the 0 5 Nm torque around the y axis The result is seen in Figure 4 11 The top graph shows o and the lower and c Since we assume that and L are equal no cross coupling occurs for the x axis making it look much like the case we had in Figure 4 10 For the y and z axes however the result is different Both angular velocities start to oscillate which can be interpreted as if the rocket starts to wobble This effect is a known source of instability in rocket and aerospace sciences The solution is often solved by performing only one rotation manoeuvre at a time minimizing the cross coupling effects If we apply torques to all three axes at the s
135. lace but extend the PC 104 bus the 104 pin ISA bus Thus the same stack can contain both PC 104 and PC 104 plus modules PC 104 plus modules offer an extra 160 pin stackable PCI bus connector 2 4 PC 104 CPU modules All PC 104 solutions start with a CPU module also known as Single Board Computer SBC A PC 104 CPU module is basically an entire PC fitted onto the PC 104 form factor 9 1 x 9 7 cm which introduces some limitations The most important consequence is that the PC 104 CPU modules lag some years behind the frontline PC market Apart from offering connection sockets for standard hard disk drives and floppy drives most CPU modules also offer some solution for embedded memory cards such as CompactFlash or other memory solutions found in today s growing digital camera market This is ideal for embedded solutions where space is of major concern 2 5 Equipment used in this project This project utilizes two PC 104 modules one CPU module and one data acquisition module Both modules were purchased from Advantech Co Ltd 2 5 1 CPU module The CPU module is of model PCM 3350 It has the following specifications NS Geode GX1 300MHz CPU 586 Pentium compatible Up to 128 MB system memory SDRAM Onboard VGA One CompactFlash socket Built in enhanced IDE hard disk drive interface Onboard PS 2 keyboard mouse connector Two serial ports RS 232 Onboard 10 100Base T Ethernet interface RJ45 LAN connector 5 V power supply
136. lculator From12 PID controllerr2 Figure 4 17 Model with roll pitch and yaw controllers 46 The results from the simulation are found in Figure 4 18 where we made the rocket go to pitch 45 yaw 60 and roll 20 We see that the PID controllers have no problems reaching their final states The sine shaped disturbances are seen as small oscillations causing effects which the controllers reduce This shows that separate PID controllers one for each Euler rotation can be used despite the cross coupling between the axes angle degrees time s Figure 4 18 Triple PID Model simulation with e 60 Q 45 20 4 8 Chapter summary In this chapter we have seen how a physical model for rocket motion can be formulated Further we have implemented the derived model in MATLAB Simulink and we have shown how the model can be controlled using separate PID controllers We have also shown how the attitude angles may be calculated from internal measurements using Euler rotations We have further verified that interference from cross coupled terms do not rule out the employment of separate controllers for each axis In order to be on the safe side though only one manoeuvre should be performed at a time at least in the first tests of the attitude control system for reducing overshoot Please note that the derived model describes a rocket moving in free space i e there are no external forces acting on the system
137. ll be controlled through small servos placed inside the rocket The question is How do we actuate the servos Another important question is How should we design and implement the control algorithms 1 2 4 Data storage and communication We need to find a way of storing and or transmitting the data collected for observation and post processing during flight operation 1 3 Report layout This report is divided into two more or less individual parts or investigations First there is a part on applied technical issues where we discuss the structure of the software running the onboard computer The software structure forms a low level programming platform or framework for further development of the rocket control software The developed framework uses real time programming features in order to attain as high system performance and reliability as possible which is imperative for flight control systems The discussion can be found in Chapter 3 where the issues of propulsion control data acquisition and data storage communication will be investigated The second part of this project is more theoretical Using feedback control theory and theory of body dynamics a physical model of the rocket has been formulated in order to analyze the dynamic behaviour of the rocket The model can be used as a starting point for the creation of a feedback system controlling the rocket attitude in flight This is discussed in Chapter 4 In Chapter 2 the onboard com
138. ll use an inertial measurement unit for making navigational measurements This requires a data acquisition module to be installed in conjunction with the onboard computer The data acquisition module will also be used for monitoring onboard data such as temperature and pressure inside the rocket motor In order to meet these requirements in a cost efficient manner a PC 104 computer solution is used 2 1 What is PC 104 The PC architecture has become an accepted platform far beyond desktop applications Dedicated and embedded applications for PCs are used as controllers within laboratory instruments communication devices and medical equipment just to mention a few examples The standard PC form factor however and its associated card cages and backplanes are too bulky and expensive for most embedded control applications In response to this the industry developed a new form factor named PC 104 It offers complete hardware and software compatibility with the PC architecture but in ultra compact form Although PC 104 modules have been manufactured since 1987 a formal specification was not published until 1992 PC104 The key differences between PC 104 and the regular PC AT architecture IEEE P996 are e Compact form factor Size reduced to 3 6 x 3 8 inches 9 1 x 9 7 cm e Self stacking bus Eliminates the cost and bulk of backplanes and card cages e Reduced connector size Rugged and reliable 104 pin contact male female header
139. me thread we can make a first layout of the program as seen in Figure 3 10 Since we are unable to implement inertial measurement algorithms without the IMU we replace the inertial measurement thread with a digital filter thread A filter is a necessary component in every application that uses analogue measurement data Its main purpose is to filter out measurement noise This can be a simple low pass filter for filtering voltage spikes and other unwanted phenomena encountered in analogue measurement Most likely it will be necessary to filter out specific frequencies induced by vibration once the rocket is assembled and tested After the filtering of the incoming data the inertial algorithm can start execution The code for the inertial measurement algorithm can either be placed at the end of the filter thread itself or as a separate thread 21 Rocket Control Program Inertial Measurement Thread Attitude Control Thread Propulsion Control Thread Data logging amp Communications Thread Figure 3 10 First thread layout of control program A good design philosophy is to be generous with the number of threads in a program By using many threads single threads may be dedicated to performing specific tasks making the development of code fast and error free This philosophy has been applied to the Data logging amp communications thread Instead of one thread we use four threads each performing a specific part of data gath
140. ming confidence This second method has been used in this project 3 4 1 5 Data transfer amp timing When the analogue converter is working at a high pace which is normally the case it is unrealistic for the client to instantly analyze the incoming data Instead blocks of data containing more than one A D converted measurement are sent from the resource manager to the client Thus there are two frequencies that we can vary independently The first frequency is that of the pacer of the ADC controlling how many measurements per second the ADC is executing The other frequency determines how often the client requests data from the resource manager In order to get a feeling for what this is all about we demonstrate some simple examples Table 3 1 Examples of pacer and transfer frequencies ADC frequency Client frequency No of measurements transfer 10 kHz 1 kHz 10 50 kHz 1 kHz 50 100 kHz 2 kHz 50 The feedback control loop located in the client will most likely never be executing faster than 1 kHz even in rocket guidance applications In the first example of Table 3 1 10 measurements will be transferred from the resource manager to the client every millisecond At this instance there is another important matter to keep in mind concerning the ADC What is the ADC measuring The ADC can convert any number from 1 to 16 signals depending on the setup In the ADC conversions are done sequentially i e it fi
141. mpensate for this we assume that both the kinetic energy as well as the moments of inertia depend on the mass change of the system Hence we need to modify the equations of motion We now see the advantage of writing the translational equations using Lagrange s equations Using the same definitions for the kinetic energy as before but assuming that the mass is time dependent we can derive the new equations of motion directly from 4 19 The same applies to the moment equations if we use 4 28 where we have not yet taken the time derivative of Hc because of this After applying the product rule of differentiation it is easy to see that the new system only differs from 4 31 in one term in each equation System 4 32 now describes the variable mass system dF mv ml T4 y 0 H EF mv n DF mv m Q V o v M d M 1 e 1 1 1 0 d y O V o v d 4 e Tu t 1 0 0 4 32 Zz gt P Jo 1 0 s 1 0 0 Bear in mind that even if we solve for vx vy and v we cannot integrate directly in order to obtain the absolute displacement This is because the coordinate system we use is attached to the rocket in which only velocities and accelerations have physical meaning Thus we must transform the components of 4 32 to an inertial frame before solving for absolute displacement The same applies to the rotational components The transformation relations from the body frame
142. mpromised or even severed then the autonomous vehicle need to know this as soon as possible in order to perform alternative actions This can e g include starting a local logging routine for saving important data to disk that might otherwise be lost while the link is not working The word keepalive is also used in network terminology when talking about a different type of function Therefore we will refer to this system as heartbeat after the algorithm with that name in the book by Stevens Ste98 which has inspired the inclusion of this safety mechanism The heartbeat mechanism uses a separate thread The fourth and last thread of the communication system is the data logging The data logger is an independent thread monitoring the active state of the system and saving it to disk As we have mentioned the data logger is only necessary if no communication link is present Therefore it is considered to be optional in the sense that it may be turned on or off as the user sees fit The data logger uses standard C functions for accessing the file where it saves the data 22 Finally we can draw the new layout of our control program Rocket Control Program Filter Thread TCP IP Send Thread Propulsion TCP IP Listen Thread Control Thread Attitude TCP IP Heartbeat Control Thread Thread Data logging Thread Figure 3 11 Improved thread layout of control program 3 5 1 Thread priorities Each thread in a process or progr
143. n connection SendCommand Type ID and data string Sends a command data packet to the QNX server KeepAlive Used for communication link safety mechanism Heartbeat In order to inform MATLAB when a message from the server has arrived event handlers are used Event handlers are small MATLAB functions that MATLAB calls automatically when receiving the corresponding event from the proxy Events sent by the proxy are Table E 6 Proxy events Name Parameters Description Event handler DataRecvd Array of data This event is triggered DataRecvdHandler m packets whenever data has been received from the server ConnectionStatus Status integer Informs MATLAB when ConnectionStatus the connection is open or Handler m closed Ping Used by the Proxy to check KeepaliveHandler m that MATLAB is responding E 5 4 Communication link safety protocol Imagine the PC 104 is controlled in real time using a remote client Should the client crash or lockup during operation there is no way for the PC 104 to be notified of the occurrence unless there is some kind of safety mechanism Such mechanism has been integrated as part of the software framework Both the client and host send small messages over the TCP IP network every second Should either side fail to send these messages within a certain deadline the connection is said to be dead and appropriate action can be taken The deadline is currently set to 5 seconds MATLAB uses
144. n error detection and correction for the TCP IP protocol no need to develop custom algorithms e Vast experience in use with desktop computer applications A very interesting aspect of LAN is the increasingly growing market for wireless com munication which offers small cheap and technically advanced solutions such as Wireless Local Area Networks WLAN Later it might even be possible to embed a WLAN transceiver in the autonomous flying vehicle thus offering a cheap form of communication even when the vehicle is in flight The TCP IP protocol is integrated as part of the QNX operating system which offers much of the implementation we need at no extra cost QNX supports the standard programming model for network programming the Berkley model It is not difficult to implement sophisticated communication solutions since there are very good references on the subject both in the relevant technical literature and on the Internet 3 5 Implementation of higher layer components The upper layer in Figure 3 1 is only partially implemented Some components like the inertial measurement algorithm and the feedback control algorithm have not been implemented at all This was mostly due to lack of necessary pre testing of hardware such as the inertial measurement unit Nevertheless we can at least implement the most basic parts of the control software for the PC 104 computer By representing each component in the upper layer of Figure 3 1 as a real ti
145. n8 iobase PCM3718 CONTROL 0x18 return 1 return 0 ok card exist reset whole PCM 3718 cards Input Most of the functions with names beginning with PCM3718 get their indata from the global structure named dev y static void PCM3718 reset struct timespec ts ts tv_sec 0 ts tv_nsec 2000000 2 milliseconds out8 dev iobase PCM3718 DIO HI 0 out8 dev iobase PCM3718 DIO LO 0 nanosleep amp ts NULL out8 dev iobase PCM3718 CONTROL 0 out8 dev iobase PCM3718 PACERENABLE Oxff out8 dev iobase PCM3718 MUX 0 out8 dev iobase PCM3718 CLRINT 0 out8 dev iobase PCM3718 PACERCTL 0xb0 Stop pacer out8 dev iobase PCM3718 PACERCTL 0x70 out8 dev iobase PCM3718 PACERCTL 0x30 out8 dev iobase PCM3718 RANGE 0 Helper function for setrange Rangetype2str Rangetype range char str 100 G 7 pcm3718 c switch range case BIPOLAR 5V strcpy str BIPOLAR 5V break case BIPOLAR 2 5V strcpy str BIPOLAR 2 5V break case BIPOLAR 1 25V strcpy str BIPOLAR 1 25V break case BIPOLAR 0 625V strcpy str BIPOLAR 0 625V break case UNIPOLAR 10V strcpy str UNIPOLAR 10V break case UNIPOLAR 5V strcpy str UNIPOLAR 5V break case UNIPOLAR 2 5V strcpy str UNIPOLAR 2 5V break case UNIPOLAR 1 25V strcpy str UNIPOLAR 1 25V break case BIPOLAR 10V strcpy str BIPOLAR 10
146. nd is found in some programming languages e Rendezvous The sender proceeds only when a reply has been returned from the receiver Rendezvous also called remote invocation is found in Ada and various operating systems including QNX This project is based on the message passing model Each thread requiring synchronization has its own message receiving mechanism Messages are sent between threads in the system allowing synchronization as well as communication QNX uses the Rendezvous model for communication which is a memory consuming and relatively slow form of communication It is suited for process to process communication and not for thread to thread synchronization Fortunately QNX provides a lightweight message called a pulse This project widely uses the pulse mechanism for achieving synchronization 3 3 System overview What 1s it then that we want to achieve with the components described In order to answer this let us restate the required tasks mentioned in Chapter 1 e Data acquisition e Attitude control e Propulsion control e Data storage communication Figure 3 1 shows the hierarchy of the control system The upper layer represents the highest level of abstraction The components of the upper layer each depend on one component found in the lower layer Before complex behaviour such as autonomous control can be achieved we first need to implement the lower layer of Figure 3 1 This requires vast knowledge of both the hard
147. nd their corresponding ID numbers This is done by filling in all IDs currently in 76 use in a so called D Map The ID Map is a special structure that is maintained by the netserver program It sends this map to clients requesting the names and IDs from the server To get the MATLAB client to recognize the newly added ID we must add a new entry in the ID Map located in DList h Extend the map with a new IDENTRY like this BEGIN IDMAP IDENTRY ID CHANO IDENTRY ID CHANI1 IDENTRY ID CHAN2 IDENTRY ID CHAN3 IDENTRY ID CHANA IDENTRY ID CHAN5 IDENTRY ID CHAN6 IDENTRY ID CHAN7 IDENTRY ID START AD IDENTRY ID STOP AD IDENTRY ID SET SERVO 0 Add this line END IDMAP Save and close the file Now open the file netserver c and locate the Listen thread Make sure the variable endptr has been defined as unsigned char and that an integer named pos exists Also make sure that the function servo open has been called storing the open connection in an int named servo In the Listen thread locate the Type ID interpreter and add a new case statement switch ntohs PacketID asUintN case ID SET SERVO 0 pos strtoul ptr amp endptr 10 if pos gt 254 endptr ptr 0 printf Error setting server position s n ptr lse set_servo servo 0 pos break Save the file and compile it from a terminal window by typing
148. ndColor get 0 defaultUicontrolBackgroundColor 136 H 5 rocketclient m end function ID CHANO Callback hObject eventdata handles hObject handle to ID CHANO see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA oo Hints get hObject String returns contents of ID CHANO as text str2double get hObject String returns contents of ID CHANO as a double oo oo E Executes on button press in pushbutton3 function pushbutton3 Callback hObject eventdata handles hObject handle to pushbutton3 see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA if handles connected invoke handles COMh SendCommand ID START AD guidata hObject handles end E Executes during object creation after setting all properties function ID CHAN2 CreateFcn hObject eventdata handles hObject handle to ID CHAN2 see GCBO eventdata reserved to be defined in a future version of MATLAB handles empty handles not created until after all CreateFcns called if ispc set hObject BackgroundColor white else set hObject BackgroundColor get 0 defaultUicontrolBackgroundColor end function ID CHAN2 Callback hObject eventdata handles hObject handle to ID CHAN2 see GCBO eventdata re
149. nest hr pie tete xar da duca eio eR XR edu ea ass 41 4 6 3 Assembly oi mode le LEA s roe li ee e Eee A beu 41 4 6 4 Model simulations and f68sUlts i n Ete net Ud eda ua d arenes 42 4 7 Attitude control systemen c dempta S ria intact e E pee refe atit xta 43 dS Shaptetauiitiaby erineda aise dad ina diebns uda ts e ciuis easi Peut 47 5 Summary and eoe USTODS ce e os en bete tdt ore en meet esas em T cate 49 5 1 US VO so ara e E aU MT aate Ma Un eM 49 5 1 1 Inertial measurement s iss abuse a tede ved co ix ap Aa Rouge deci EXE dug 49 5 1 2 Propulsion control 2 o reped OE E E rU E E one 49 5 1 3 Attitude and guidance controller eoe n eeeete reta een ea tene re eue erudit 49 5 1 4 Parachute release Controls aseo rode ec aa NDS AN RESQUE D due quada ERR 50 Marec ni I M 50 MRS EE TLC OS MM M p E dE ET 51 A Analogue to digital conversion ss ssesessssessesersseesseserssressesstsstressesstesessteseesresseeseesersstesseseest 53 A l Range accuracy and resolutioni isus s dte eric c ao cocoa aeons 53 AZ Digital representa Oth iust eto pls re RR EE Deeo vag eU ese emet Ee UE 53 B Implementing a PID controllerc stavo pes eee echas ead usi e teet t seni 55 B Limiting the derivative cue ete et ty ute d iiu ee ain uin 55 B 2 gt A i WA Pies esnie aa AEE AARE EATE E EEEE AE EER RRE TARTASA RARES 55 BG Implementations nena ep beoe uina eared ede ct aegis 56 C ASNWIHCIECODUOL CUTE gat oi oc ose de cos le cc corse eec ten
150. ng a read command if rx data charvalue RWMODE ANALOG if runmode SILENT fprintf stderr PCM3718 Cannot set Readmode n return EINVAL rwmode rx data charvalue break case DEVCTL SET TRANSFER SPEED Software mode to set the filter wakeup speed also called transfer rate Check for errors if status dma set if runmode SILENT fprintf stderr PCM3718 You must set this speed before allocating DMA buffers Please Close connection before trying again n return EINVAL if runmode VERBOSE printf PCM3718 Setting filter wakeup speed to d Hz n rx data uintvalue dev transfer rate rx data uintvalue break default return ENOSYS BOK IK KKK KI kk kk RA hok Ck AA I A kk AA kk koe kk A A ke e ek ee x x Clear the return message note we saved our data after this memset amp msg gt o 0 sizeof msg 0 If you wanted to pass something different to the return field of the devctl you could do it through this member ey msg o ret val retstatus Indicate the number of bytes and return the message msg gt o nbytes nbytes return RESMGR PTR ctp amp msg gt o sizeof msg gt o nbytes The io_open function handles open calls to this device It resets the entire card on success Hence no more than one connection at a time should be open y int io open resmgr context t ctp io open t msg RESMGR HA
151. ning unit is expected to be ready for testing in the near future 1 1 4 Attitude and guidance system The attitude control and guidance of the rocket will be performed by an onboard computer system The onboard computer will also take care of data acquisition and data handling The system relies on the IMU to gain position and attitude information In flight the rocket will be manoeuvred by movable fins on the rocket body using them as rudders 1 1 5 Power supply Electrical power is essential The onboard computer as well as various subsystems such as the IMU and solenoid valves for rocket motor control requires electrical power at different voltages One or several batteries should be able to deliver the required amount of energy during operation which in the case of a rocket is not very long not more than a couple of minutes It is expected that the necessary study of the electrical requirements is performed in due time and we will therefore not discuss the matter further in this report 1 1 6 Parachute Once the fuel inside the rocket has been consumed the rocket has to return safely to ground This will require a parachute to be released after burnout The details of how this is to be performed will be taken care of at a later stage 1 2 Problem summary The onboard computer will act as a central unit controlling all the modules inside the rocket In general we need the onboard computer for performing the following tasks 1 Pr
152. nly used anti windup solution Taking the difference between the desired control signal V and the bounded control signal U the integration step can be modified according to the block diagram shown in Figure B 2 T is a new parameter related to the desired amount of anti windup 710 20 Figure B 2 PID controller with anti windup and derivative limiter B 3 Implementation Using a shift operator q such that q y k 2y k 1 where k is a discrete time step we can define s of the Laplace transform in an Euler backward sense using an arbitrary time constant h equivalent to the reciprocal of the sampling frequency I l 4 h S gt We can now calculate the discrete implementation of the controller shown in Figure B 2 For the derivative part D we obtain KT q TAR ier N y e D D rs KT sy Aou 20 240 rz 29 98 10 N h h pir LOD KN x k 1 Nh T This can be directly implemented in code D Td D K N y old_y N h Td Notice that the old input signal y k 1 is stored as a separate variable o d y 56 Next we look at the integration factor which we obtain directly from Figure B 2 K U V 1 l LI S o y A Using Euler backward we will obtain I k 1 Ep Fle V i The above is used in various controllers to reduce anti windup This can be implemented in code as follows I I K h Ti yref y Desired Integration Factor V P I D Desired Output
153. nt reading struct timespec ts ts tv_sec 0 ts tv_nsec 1000000 1 millisecond reading 0 out8 dev iobase PCM3718 STATUS 0 outs dev iobase PCM3718 AD LO 0 write something to base 0 while 1 nanosleep amp ts NULL if in8 dev iobase PCM3718 STATUS amp 20 break nanosleep amp ts NULL reading inl6 dev iobase PCM3718 AD LO Note This only works on Intel Architecture machines little endian return reading Reads Digital IO returns A byte containing entire channel 8 bits Ey unsigned char PCM3718 DIO read unsigned char data if rwmode RWMODE DIO1 data in8 dev iobase PCM3718 DIO LO lse data in8 dev iobase PCM3718 DIO HI return data Writes to the Digital IO Input A byte 8 bits to write to the channel void PCM3718 DIO write unsigned int data if rwmode RWMODE DIO1 out8 dev iobase PCM3718 DIO LO unsigned char data else out8 dev iobase PCM3718 DIO HI data Sets the pacer speed with the designated values Cl and C2 PCM3718 StartPacer unsigned int Cl unsigned int C2 out8 dev iobase PCM3718 PACERCTL 0x76 out8 dev iobase PCM3718 PACER1 C1 amp Oxff out8 dev iobase PCM3718 PACER1 C1 gt gt 8 out8 dev iobase PCM3718 PACERCTL 0xB6 outs dev iobase PCM3718 PACER2 C2 amp Oxff out8 dev iobase PCM3718 PACER2 C2 gt gt 8
154. number of different modes using onboard jumpers These jumper settings need to be given to the device driver in order for it to function correctly The device driver assumes default values for all these settings The driver program is called pcm3718 and is found in the root directory on the PC 104 computer it can be run in the three different output modes The mode is chosen when starting the driver by giving the following arguments n V S Normal this means that errors and some general info are printed onscreen to the terminal window it was started from Verbose prints a lot of info on the screen telling everything the driver is up to at the moment This mode is useful when debugging the driver itself but also comes in handy when debugging the program that uses the driver Silent does not print any messages to screen This mode should be used during normal operation To change the default driver parameters use the following arguments followed by the desired value separated by a white space character b d C i I O baseadress default 210 This is the I O memory address used by the card The address is entered using hexadecimal base DMA channel 1 or 3 default 3 Most PCs support a number of DMA channels often up to 8 where each hardware device is assigned a separate channel Channel 3 is often unused and is selected by default Internal clock frequency 1 or 10 MHz default 10 MHz T
155. o 1 0 tI o Inserting 4 27 into 4 24 and assuming principal axes the resulting equations for the moments become d M qs t 1 0 0 d 2M s 7 L 0 0 4 28 d M qU592 l 1 0 0 Note that there is a cross coupling between the three axes This will pose a problem to the rocket attitude control Forcing rotations around more than one axis at a time will give rise to additional rotations around all axes 4 4 4 Equations of motion for a constant mass system We now derive the equations of motion in the general three dimensional case For a rigid body the kinetic energy is usually represented by T mv rL 4 29 The derivatives of 4 29 will however not contain terms representing the angular velocities Therefore 4 29 can simply be written T mv TA vy t v 4 30 Inserting 4 30 into 4 19 using 4 28 we obtain 4 31 which fully describes the dynamic motion of a rigid body In this case we still assume the mass to be constant 35 205 B m T y o v YF m tov ov DF mv Ta Vp cv 2M 1 0 Lee 1 0 0 M 1 0 0 L 0 0 DM 1 6 4 Ly 1 0 0 4 31 The equations for F agree with the results from Greenwood Gre65 where a different approach is used 4 4 5 Equations of motion for a variable mass system It is fairly obvious that a travelling rocket is not a system that can be assumed to have constant mass not even approximately In order to co
156. o host byte order In 70 order to fully understand how the Listen thread interprets these commands a discussion of thread synchro nization is required E 4 4 Thread synchronization The QNX operating system offers both the POSIX synchronization solutions as well as its own The framework uses solutions from both of these Table E 3 Synchronization solutions used in this project Solution Variety of Defined in Pulse Message passing QNX Read Write lock Shared variable POSIX E 4 4 1 Pulses Processes normally synchronize using message passing Normally they are time consuming operations transferring big chunks of data A QNX pulse is a lightweight message using a fixed size They can be used to notify a thread or process that a certain event has occurred or to transfer very small chunks of data maximum of four bytes Pulses are used for these purposes throughout the framework E 4 4 2 Read Write locks When multiple threads are accessing the same data area such as a structure or an array there is a risk that one thread will write to the area at the same time as another thread is reading from it This could cause data corruption to occur Consider the layout of Figure E 1 where the filter is constantly updating the measurement data area whilst a number of other threads are reading from it To prevent data corruption we must use some form of mutual exclusion A read write lock offers this capability by allowing
157. ocket design will need to deploy a parachute once the rocket is out of fuel This can be taken care of by a separate thread We also need a thread which acts as the intelligence or the autonomous part of the system This thread should change the reference values for the attitude controller i e guidance and give order for ignition of the rocket motor and release of the parachute During initial test stages this thread should contain manually written testing manoeuvres For example Start rocket engine Wait 5 seconds Perform a 45 roll followed by a pitch change of 20 Turn off rocket engine 5 Release parachute In chapter 4 we will explain roll and pitch manoeuvres po DS Finally we must not forget the inertial measurement unit and its corresponding software algorithm which calls for an additional thread For simplicity assume that the rocket does not use network communication so that we can remove the corresponding threads The diagram of this final proposition is found in Figure 3 12 24 Rocket Control Program Filter Thread Roll Control Thread Inertial Measurement Pitch Thread Control Thread Propulsion Yaw Control Thread Control Thread Data logging Thread Servo Coordination Thread Test manoeuvre thread Parachute Release Thread Guidance Figure 3 12 Proposition of the final thread layout 3 6 Remote control and monitoring Development of the software for the PC 104 computer ha
158. of dynamics New York Prentice Hall 1965 T Hayles D Potter Programming DMA on PC XT AT Computers USA National Instruments Corporation 1991 See http www inf pucrs br eduardob disciplinas arqii dma html Rob Krten Getting started with QNX 4 a guide for realtime programmers Kanata Ont PARSE Software Devices 1998 Rob Krten Getting started with QNX Neutrino 2 a guide for realtime programmers Kanata Ont PARSE Software Devices 1999 Donald A Lewine POSIX programmer s guide writing portable UNIX programs with the POSIX 1 standard Sebastopol CA O Reilly amp Associates 1991 Revised 1994 51 MATLAB McK91 MSDN PC104 QNX Sch98 Sch00 Ste98 Swe99 Tho61 Tro00 Homepage of MATLAB online documentation Natick MA Mathworks Inc http www mathworks com support Phillip John McKerrow Introduction to robotics Sydney Reading Mass Addison Wesley Pub Co 1991 Homepage of Microsoft Developers Network MSDN Redmond WA Microsoft Corporation http msdn microsoft com Homepage of PC 104 Consortium San Francisco CA PC 104 Consortium http www pc104 org Homepage of QNX online documentation and support Ottawa Ont QNX Software Solutions Ltd http www qnx com support Herbert Schildt C the complete reference 3rd ed Berkeley Osborne McGraw Hill 1998 Herbert Schildt Windows 2000 Programming from the ground up Berkley Osborne McGraw Hill 20
159. ogram Attitude and guidance control A D Filter Remote Computer Data TCP IP Send acquisition card File logger TCP IP Listen Rocket Ignition and thrust control Figure E 2 Framework communication flow E 4 6 Remote command relaying We are now ready to go back to the Listen thread command interpreter The case ID START AD looked like this case ID START AD MsgSendPulse chid filt pulseprio COMMAND PULSE CODE ID START AD MsgSendPulse chid send pulseprio COMMAND PULSE CODE ID START AD break The exact same pulse is being sent to two different channels one to chid_filt Filter thread and one to chid send Send thread Besides the connection identifier each pulse has a priority a pulse code and a value to be entered in that order when MsgSendPulse is issued The COMMAND pulse code is used in order to tell the particular thread that a remote command has been received or locally issued The command type is passed in the value field of the MsgSendPulse function Note that the ID List macro is reused here Thus the ID List defined in DList h is used both for network communication as well as internal communication Other pulsecodes used are defined in the file pulsecodes h E 4 7 Sending measurement data over the TCP IP connection When an ID START A
160. ollowing is required 1 The necessary Type IDs have been defined in DList h 2 The Listen thread must have a specific case statement interpreting the Type ID 3 The remote client has a list of all Type IDs the platform can handle Remote communication requires at least two computers If one computer updates its ID List it will not automatically get updated on the other This requires constant updates in both host and client programs to make sure both ID List tables are identical To avoid this problem the framework supports automatic retrieval of the ID List from the server This means that maintenance of the ID List is required only on the server PC 104 E 5 1 QNX and Linux client A simple client program has been developed it compiles in QNX as well as in Linux Unfortunately it does not utilize the automatic retrieval system to get the ID List This requires that the same ID List needs to be included when compiling both the server and the client This is usually not a problem since development of both the client and server programs is done on the same computer The client is called netclient and its corresponding source is netclient c It is a simple text mode client It can send a sequence of commands to the PC 104 server when started It then prints all incoming messages from the server including the Type ID number and the data netclient 169 254 13 200 Received 26 bytes of data D 0 Value STARTING A D Conversion eceived 30 byt
161. on card can also be used for logging temperatures or pressures inside the hybrid rocket engine which further justifies the use of general purpose data acquisition software An overview of the subsystem is shown in Figure 3 2 Inertial Measurement Algorithm Software Hardware Data Acquisition Card Inertial Measurement Unit Figure 3 2 Inertial measurement subsystem Pressures amp Temperatures 4 3 3 2 Attitude control The system controlling the rocket attitude is an important part of the project Like many feedback control systems this subsystem may be further subdivided for convenience of analysis in this case into four parts as seen in Figure 3 3 e Inertial measurement system The output from the inertial measurement algorithm mentioned in the previous section is used as input to the control system e Feedback controller A software algorithm that makes decisions about how the system should be controlled e Actuation system Consists of one or two servo controllers each controlling a small number of servos which control the motion of the vehicle by fin stabilization 13 e Vehicle response The dynamic response of the rocket itself In order to design a good control algorithm a dynamic model of the motion of the rocket is required Feedback Actuation Vehicle Controller System Response Inertial Measurement System Figure 3 3 Overview of attitude control system Figure 3
162. only one thread to write to the area while no other thread is reading from it If no thread is writing to it however multiple threads can access the memory area for reading increasing throughput E 4 5 Message passing An overview of the message passing and control of the system can be seen in Figure E 2 Most threads in the real time platform are nothing more than simple message dispatchers This solution is very convenient since the thread can do synchronized tasks such as reacting to a timer as well as listening for incoming asynchronous messages from other threads This is so because both QNX timers and the internal communication system use pulses Before pulses can be received a thread needs to create its own communication channel Each channel has its own channel identifier number or simply chid Other threads use these chids when they want to send a pulse to a specific thread Each thread that requests messages from other threads create their channels in global namespace of the C program Other threads can then connect to these channels using the corresponding chid As an example a table of chid names used by the listen thread is found in Table E 4 Table E 4 Listen thread channel names Channel identifier name Connection name in Listen Connects to in global namespace thread namespace channelid filt chid filt Filter thread channelid send chid send Send thread 71 Guidance system Netserver pr
163. ontrol 1er pti tage iet util eeepc ae paginas EENEG 3 1 2 2 Datd aequiSitIQDaa uidet Lord flete e ie yd ate ai tinea 3 1 2 3 PRUE contol Sa siis po eiu deste E A E a eS 3 1 2 4 Data storage and communication c a eh ep edite eater diee Mem ue cona cepa ded 3 3 Report TAY OU tis io acere treo esee etr ua Ebr aoe i t am AER EGO tua PER RERA 4 Dy CUP cc ialdaaeanes 5 24r M ohstis PCATOAS son aa Na I Ea nh en Cased sta 5 Dede POPU EIE e cT 5 23 TPCT O4 and PC IO4 DNIS 5 eo imet iege EAA ge qan ehtun ette Rus e Rp ade 6 24 PCHOA CPU modules eee reo iae riata RW GYNR UE RI E HT aes Aaa 6 2 5 Equipment used in this project eu os eate yore ise Mu desce reed te edes veia Se 6 2 5 1 CPU iO GUC saya ea r ue E esu a caus aes 6 2 5 2 Data acquisition module iesu iii De oai qe vetas cai Foe das 7 26 VV PIC al SEDI os aos eee di Mete mapu uet erat to cena mpi a E idence tates n as mand 8 3 Software design and implementation os goce heo aspe acs eS det iu aca 9 3 1 Rea nie Sy SEIN NS ean t eon esp RE esc ge hat um epo tod See ttp e n eae SNe 9 3 1 1 Real time control SY SHOTS uiis eR trier ATA Ra Ft ER EHE EA a rea el t a deba 9 3 1 2 jj pq H t 10 3 1 3 OIN D T E rena c SERM 10 3 2 Components ola real time system esee e c oe detenido tao ir tutte ota teeuiuns 11 3 2 1 Proeesses and tBireads s d saa an edetes eges eda FO edu ere uS deni evt 11 3 22 R altinie schedulet ac aided bsc Fate PRU MR HARE USI
164. opulsion control Ignition steps and thrust control of the hybrid rocket motor 2 Data acquisition Gather data from the inertial measurement unit and convert measured values into positions velocities and attitude 3 Attitude control Use the external fins to manoeuvre the rocket based on a decision or feedback algorithm using data from the inertial measurement unit 4 Data storage and communication Gather onboard data such as velocity positions tank pressures and other critical parameters either by storing them onboard or by transmitting them over a communication link We can restate these tasks in a simpler form by only concentrating on the central parts If we solve each of these individual tasks it should be possible to fulfil the requirements stated above 1 2 1 Propulsion control The rocket motor is ignited by the opening and closing of solenoid valves according to a given pattern The important question is How do we control a solenoid valve using software in the onboard computer A similar question can be stated for the switching of the glow plug 1 2 2 Data acquisition The electrical signals generated by the components of the IMU need to be measured and converted to a digital format The question is here What is needed in order to make the measurements available to the onboard computer in a format usable by the software 1 2 3 Attitude control The manoeuvres of the fins by the attitude control system wi
165. p IRQ out8 SNGL MASK reg dev dma_channel DISABLE dev dma_channel MsgSendPulse channelid sched get priority max sched getscheduler 0 RESET PULSE CODE 0 if oldclock nsec 0 AD START has been called ret ClockPeriod CLOCK REALTIME amp 0ldclock NULL 0 if ret 1 printf PCM3718 Error resetting clockperiod n out8 dev iobase PCM3718 PACERCTL 0xb0 Stop pacer out8 dev iobase PCM3718 PACERCTL 0x70 Stop pacer out8 dev iobase PCM3718 PACERCTL 0x30 Stop pacer status ad_running 0 break case DEVCTL ATTACHFILTER Tells the Copy thread which process to wake up when data is ready if runmode VERBOSE printf PCM3718 Attaching filter with chid d and pid dWMn rx data amdata data channelid rx data gt amdata data pidid MsgSend channelid amp rx_data gt amdata data sizeof attachfiltersend t amp retstatus sizeof status if retstatus strcpy rx data amdata reply shm name SHM NAME rx data amdata reply size dev shmem size nbytes sizeof attachfilterreply t else return EINVAL status filter attached 1 if runmode SILENT printf PCM3718 Copy thread ready to send d bytes of data every d ns Mn dev shmem size dev transfer timeperiod break 109 G 7 pcm3718 c case DEVCTL SET READMODE Sets where the card will read from when issui
166. puter used in this project is introduced Chapter 2 should be read before Chapter 3 The Appendices are structured as follows Appendix A A brief introduction to analogue to digital conversion Understanding of the basic concepts will help in the the discussion of data acquisition in Chapter 3 Appendix B Explanation of some common pitfalls when implementing feedback controllers in programming code This information can be used for implementing the attitude controller in a future project Appendix C Circuit diagrams of the external electronics used by the onboard computer in order for it to work as propulsion controller Appendix D Insight into the use of the QNX operating system It contains some useful commands and hints often needed when using the OS Appendix E Explanation of the implementation of the software code developed for this project Here also a programming tutorial is found explaining how to use the software framework Appendix F Documentation of the software driver developed for the data acquisition module Appendix G The programming code written for the QNX OS Appendix H The Matlab code for the communication solution which we will discuss in Chapter 3 also mentioned in the tutorial found in Appendix E 2 Setup In order to perform attitude and guidance control of the hybrid rocket we need an onboard computer system which must be both powerful and small enough to fit inside the rocket The computer wi
167. rocesses and threads are used in order to allow concurrent execution Before real time operating systems were introduced only one program at a time could be executed This is encountered in console like environments where a command or program is executed one at a time in order to produce results This is called sequential execution as opposed to concurrent execution in which a large number of commands or programs runs simultaneously Each program running is in real time terminology called a process Each process has its own memory space and only that process can change the content of its own memory area in order to avoid corruption of the stored data belonging to one process caused by an error or illegal access by another process In POSIX the terms process and program can be used alternatively since all programs running in the operating system are in fact processes Another form of concurrency offered by most real time operating systems and in some programming languages is something called threads Unlike processes threads are not independent They are associated with a process and share its memory area with the process Threads are like lightweight processes usually smaller in size and less complex Threads are often used as building blocks in a process for creating a more complex behaviour A process has always at least one thread 3 2 2 Real time scheduler Actual concurrency is not possible on a single processor since it executes its instruct
168. rques U we use constant signals step functions The rocket mass is modelled by a ramp function with a negative slope The full model may be found in Figure 4 9 Four Simulink scopes are employed in the model as shown in Figure 4 9 recording the rocket mass m and the three angular velocities and Oz It is not possible to integrate or in order to obtain the angles of rotation since we are using a moving coordinate system The angular velocities are needed as inputs for an Euler angle rotation algorithm based on 4 40 Performing these transformations makes it possible to deduce the attitude angles relative the inertial frame The angles may in turn be used as inputs to an attitude control system 4l x2 calculator Inertia estimator y2 calculator Omega y z2 calculator Control signal Z Goto Figure 4 9 Overview of Simulink model 4 6 4 Model simulations and results Using the above Simulink model we can study the effects of different configurations such as initial parameters and input signals In order to keep the discussion short we use the same starting parameters for all our simulations These are shown below Table 4 1 Simulation parameters Parameter Description Value Mo Total starting mass of the rocket 12 kg dm dt Fuel ejection rate slope of ramp 160 g s function L Length of rocket lm R Outer radius of rocket 80 mm The parameters chosen have physica
169. rst converts channel zero then channel one then channel two and so on until it reaches its limit which is software controlled It then restarts the conversion from channel zero again Investigating Table 3 1 we cannot tell how often a specific measurement channel repeats itself In the first case where ten measurements are sent every millisecond it could mean ten distinct samples from the same signal source or it might be ten different signals We know that the inertial measurement unit uses six signals three gyros and three accelerometers if we have only one to five of these signals at a given instance of time we cannot use them as input to the inertial measurement algorithm we need all six measurements Making analogue measurements it is usually desirable to sample all the signals of interest at least once before starting any analysis i e one full set of measurements is needed The number of complete sets of measurements required for each update period in the client program thus needs to be estimated As a counter example let us consider the case where only the six channels from the IMU are measured Further assume that the ADC is running at 50 kHz and that the inertial measurement algorithm located in the client program is running at 1 kHz generating data blocks of 50 measurements for every transfer cycle as in the second case of Table 3 1 Then eight complete sets 8 6 48 are generated but only the first two measurements from
170. s Do we need to remove the rocket nose cone before parachute release will have to be answered Both hardware and corresponding software implementations need to be developed 5 2 Conclusions Once the issues above have been solved the hybrid rocket targeted in this report will have been brought closer to its first successful operation This work constitutes a substantial effort toward that goal and we wish those who will be continuing the work Good Luck 50 References Adv02 Adv99 BW97 Dri96 FPE02 FS95 Gre65 HP91 Krt98 Krt99 Lew91 Advantech Co Ltd PCM 3350 Series NS Geode 586 Level PC 104 CPU Module with VGA LCD LAN Interface User s Manual 3rd ed Taiwan Advantech Co Ltd 2002 Part No 2006335052 Advantech Co Ltd PCM 3718H 3718HG PC 104 12 bit DAS Module with Programmable Gain User s manual 2nd ed Taiwan Advantech Co Ltd 1999 Part No 2003371810 Alan Burns Andy Wellings Real Time Systems and Programming Languages 2nd ed Harlow Addison Wesley 1997 Morris Driels Linear Control Systems Engineering New York McGraw Hill 1996 Gene F Franklin J David Powell Abbas Emami Naeini Feedback control of dynamic systems 4th ed Upper Saddle River N J London Prentice Hall PTR 2002 Peter W Fortescue John P W Stark Spacecraft systems engineering 2nd ed Baffins Lane Chichester John Wiley amp Sons 1995 Donald T Greenwood Principles
171. s replace the standard PC s edge card connectors hence the name PC 104 e Relaxed bus drive 4 mA Lowers power consumption 1 2 Watts per module but also reduces the maximum number of components on the bus PC 104 offers all the advantages in the standard PC configuration including the use of existing peripheral equipment hard disk drives keyboards monitors etc as well as standard PC operating systems It is thus possible to reuse software solutions developed for standard PC applications saving development time and costs 2 2 PC 104 module stacks PC 104 modules are self stacking Stacked modules are spaced 0 6 inches 1 5 cm apart The three module stack shown in Figure 2 1 measure just 3 6 by 3 8 by 2 inches 9 1 x 9 7 x 5 1 cm PC 104 vendors today offer hundreds of different off the shelf modules meeting even the most specific demands Examples of existing PC 104 modules are CPU modules data acquisition modules I O modules and network modules Non stackthrough Module Stackthrough Module Stackthrough Module Figure 2 1 PC 104 module stack 2 3 PC 104 and PC 104 plus The PC 104 uses the ISA bus as module to module bus The ISA bus is rarely seen in the standard PCs of today due to its speed limitations In 1996 the new PCI bus was introduced to the PC 104 community under the name PC 104 plus In order to retain backward compatibility with the PC 104 bus it was decided that the new bus should not rep
172. s almost exclusively been performed using a desktop PC with QNX installed The compiled programs had to be moved or copied to the PC 104 computer for testing and debugging because the PC 104 had the required hardware DAQ card connected The QNX operating system as any UNIX style system offers terminal login over a network as a built in service This was used extensively during development Connecting the PC 104 computer over a local area network allows the desktop PC to be used for development as well as for testing using a terminal connection to the PC 104 This is almost like controlling two computers using only one keyboard and one monitor It is also possible to transfer the compiled programs from the development computer to the PC 104 for testing using file transfer programs The drawback with terminal login is that it only offers a text interface to the remote computer After some time we realized that a more sophisticated user interface would be required for controlling and monitoring the functions of the PC 104 computer What we needed was the possibility to simultaneously monitor multiple parameters and to send control commands or even sequences of commands to the PC 104 while it was running Connecting a monitor directly to the PC 104 as a graphical interface is out of the question This would just disrupt the response time of the PC 104 computer since we wish that the system perform as close to real operation environment as possible By
173. s have different pressures they cannot share the same solenoid valve Thus we need two oxygen valves one propane valve and one glow plug The ignition process is summarized briefly below Switch on the glow plug Open the propane valve Open the low pressure oxygen valve Wait for ignition of the gas mixture Switch off the glow plug Open the main oxygen valve Close the propane valve Close the low pressure oxygen valve Qo c4 cnc des S9 por Opening and closing the valves are performed using digital switching electronics located between the digital ports of the PC 104 and the solenoid valves and glow plug Detailed schematics and a description of the switch can be found in Appendix C The main component is a transistor controlling some external power source strong enough to open the valves or switching the current for the glow plug For demonstration purposes a digital switch was manufactured and tested with one of the solenoid valves The setup can be seen in Figure 3 9 The parallel port on the PC 104 was used for digital interfacing This setup using a 12V power supply for the solenoid valve worked as intended There is a potential problem however using the parallel port Instead the digital I O ports on the DAQ card ought to be used for propulsion control This is described in more detail in Appendix C The glow plug uses about 3A at almost 1 5V and thus requires some further elec tronics for converting a 12V or 5V signal
174. served to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA Executes during object creation after setting all properties function edit3 CreateFcn hObject eventdata handles hObject handle to edit3 see GCBO eventdata reserved to be defined in a future version of MATLAB handles empty handles not created until after all CreateFcns called if ispc set hObject BackgroundColor white else set hObject BackgroundColor get 0 defaultUicontrolBackgroundColor end function edit3 Callback hObject eventdata handles hObject handle to edit3 see GCBO eventdata reserved to be defined in a future version of MATLAB handles structure with handles and user data see GUIDATA 137 H 5 rocketclient m E Executes during object creation after setting all properties function ID CHAN1 CreateFcn hObject eventdata handles hObject handle to ID CHANI see GCBO eventdata reserved to be defined in a future version of MATLAB handles empty handles not created until after all CreateFcns called if ispc set hObject BackgroundColor white else set hObject BackgroundColor get 0 defaultUicontrolBackgroundColor end function ID CHAN1 Callback hObject eventdata handles hObject handle to ID CHANI see GCBO eventdata reserved to be defined in a future version of M
175. servfd PCM3718 Connection on card fd servo controller on servo int channelid send channelid filt int pulseprio A number used by all MsgSendPulse commands Shared Memory areas Read Write Lock Protected s xxx x x x f Kk ck ke e ke e ke e ke e Analog data channels Fe KK ke ke e ke e e e x x struct double channel 16 pthread rwlock t rwl ad data BRK KK kk kk kk kk kk kk kk kck kc kckck kc kckckckckckckckckockckckckok ck kk ke ke e x amp f f Kk RK e ke e ke e ke e ke e Command data Fe A ck ck ckckckckckckck ck kk ke struct unsigned short id char buffer MAXDATASIZE pthread rwlock t rwl Command data OK RK kk kk HK kk hok kk kk kk Kok oko kk kk kk Kok oko ke ke koe ek ee e e x x RK RK kk kk kk kc ke ke ke ke ke e ke e ke Type defintions CkCkck ck kckckckckckckokckokckokckok ko ke ke ke ke ke e e kx x typedef union struct pulse pulse your other message structures would go here too MSG 116 G 8 netserver c BORK RK KK IK KK kk ke ke ke ke ke ke ek Thread implementation XCkckckckckckckck kk ko ke ke ke x ke x f Keepalive Heartbeat thread This Thread sends small amounts of data on a separate socket to a similar thread located in the network client program These messages makes sure both sides of the connection are alive even when no normal data is sent over the transmission port ur void Heartbeat thread void arg int nprob
176. servos Figure 3 8 shows the servo and the servo controller A servo controller is a small piece of electronic hardware required for generating the PWM signals Using a servo controller for controlling servos is straightforward The controller can operate up to eight servos at the same time Control commands are sent to the controller through a serial cable connected between the controller and one of the PC 104 serial communication ports The software we need for controlling the servos is simply the code for sending the correct control characters to the serial port of the PC 104 Many features involving serial communication are already implemented in the QNX operating system High level programs can easily access the servo controller by using the very small serial interface written as a part of the software framework in this project The code may be found in Appendix G Serial Servo cable controller To 9V supply To 5V supply Servo connector Figure 3 8 Servo and servo controller 3 4 3 Propulsion control interface The ignition process is divided into two stages In the first stage oxygen and propane flows at a very low pressure past a heated glow plug which ignites the gas When ignition has been established the main oxygen supply is opened while the other supplies are closed The main gas supply flows at very high pressure through the rocket motor acting as oxidizer for the solid rocket propellant 19 Since the two oxygen flow
177. soft or firm real time and can be distinguished from those using hard or real real time where failure to respond can be considered just as bad as a wrong response For example a missed deadline in a flight control system of a combat aircraft may be catastrophical BW97 A number of hard or real real time operating systems exist Most of them are commercial but some also exist in non commercial versions The operating system used for this project is the non commercial version of QNX 6 2 developed by QNX Software Systems Ltd QSSL It is a POSIX compliant OS and has support for modern PC architectures QNX uses a micro kernel which guarantees real real time support A micro kernel is a lightweight OS kernel which gives a small memory trace thus suitable for embedded applications where computer memory and hardware performance is limited QNX is a scalable OS where support for different services is plugged into the kernel on demand such as networking file system or graphics This is also suitable for an embedded solution since the size of the system may be customized in order to fit particular needs 10 3 2 Components of a real time system A typical real time implementation utilizes a number of components in order to work Besides functions for maintaining concurrent execution it requires mechanisms such as synchro nization which is used for preventing data corruption and for maintaining execution stability 3 2 1 Processes and threads P
178. sten Peripheral hardware Rocket Ignition and thrust control Figure E 1 Overview of measurement dataflow in and out of the real time control system E 4 Platform communication The framework supports communication using TCP IP network In such networks one side acts as a host or server and the other acts as a client In this project the PC 104 is acting as the network server When starting the netserver program it waits for a connection from a remote client over the network When connection is established the client can start sending commands to the server such as telling it to start and stop A D conversion or to move servos The server can also send data back to the client for monitoring E 4 1 Communication protocol In the lower layers of TCP IP data is sent using small packets This model is utilized in the application layer as well The TCP IP send and receive threads have sophisticated architecture to pack and unpack data inside these application layer packets E 4 1 1 Application layer packet description Each packet starts with a five byte packet header The header always begins with a three byte character sequence defined by the constant character array HeaderStart defined in netserver c The start sequence is followed by a two byte Type ID number which identifies what type of data is contained in the packet After the packet header follows the data it consists of a null terminated character array or IUE The string can
179. strnomp argv i b 2 dev iobase strtoul argv i 1 amp check 160 if dev iobase 0 printf PCM3718 Unkown base adress s n argv itl return 1 itt else if strnomp argv i d 2 dev dma_channel strtoul argv it 1 amp check 10 if dev dma channel 1 amp amp dev dma channel 3 printf PCM3718 Unknown DMA channel s nAllowed DMA channels are 1 or 3 n argv it l return EXIT FAILURE qur else if strnomp argv i c 2 dev CLK speed strtoul argv i 1 amp check 10 if dev CLK speed 1 dev CLK speed 10 dev CLK_speed 1000000 else printf PCM3718 Unknown Clockspeed s nAllowed Clockspeeds are 1 or 10 Mhz n argv it1 return EXIT FAILURE itt else if strnomp argv i i 2 dev IRQ strtoul argv i 1 amp check 10 if dev IRO 2 dev IRQ 7 printf PCM3718 Unknown IRQ s nAllowed IRQs are 2 to 7 n argv itl return EXIT FAILURE itt else if strncmp argv i r 2 dev transfer rate strtoul argv i 1 amp check 10 if dev transfer rate gt 100000 check argv i 1 0 printf PCM3718 Unknown filterspeed s nMust be less than 100000 n argv it 1l return EXIT FAILURE 113 G 7 pcm3718 c itt else printf unknown argument s n n argv i printf Usage npcm3718 mode b adress d channel c clockspee
180. such as gravity or wind During computer simulations the influences from external forces were represented as disturbances only The work and the results presented here are intended as a basis for further study and implementation of the attitude control system 47 5 Summary and conclusions In this thesis we have discussed the aspects of controlling a hybrid rocket We have suggested an implementation using real time components which form the basis for the control software running the onboard PC 104 computer We have demonstrated e How to open close solenoid valves showing in principle how the hybrid rocket engine can be ignited from the software e How to perform data acquisition using the developed software driver This can be used for various purposes such as inertial measurement or system monitoring e How to control servos showing in principle how the attitude controller can manoeuvre the rocket using movable fins connected to the servos e How to collect data and monitor system performance of the hybrid rocket using network communication and data logging Further we have formulated a first model of the rocket dynamics Using this model we have shown how PID controllers can be used for controlling the rocket attitude 5 1 Future work Using the methods and implementation presented it should be possible to design a complete control system for the onboard PC 104 computer The parts and functions not implemented are In
181. sued l DEVCTL SETCHANNEL 2 DEVCTL SETPACER 3 DEVCTL DMA INIT Example devctl card fd DEVCTL AD START NULL 0 NULL F 2 7 DEVCTL AD STOP Parameter type None Description Halts the A D conversion Issuing a start A D command later continues the conversion where it left off When the device is closed it automatically stops the A D conversion Example 86 devctl card fd DEVCTL AD STOP NULL 0 NULL F 2 8 DEVCTL SET READMODE Parameter type unsigned char Description The DAQ card supports two 8 bit digital I O channels By issuing a read or write command it reads from or writes to a digital port To perform software A D the read function is also used This command selects what operation the read and write function will issue when called from this device Depending on the value of the unsigned char parameter the following relationships can be constructed Table F 1 Read mode overview Parameter value Read From Write to RWMODE DIOL Digital I O port 1 Digital I O port 1 RWMODE DIO2 Digital I O port 2 Digital I O port 2 RWMODE ANALOG A D converter The macros used as parameter values are defined in pcm3716 h Example unsigned char mode value unsigned int reading mode RWMODE DIO1 devctl card fd DEVCTL SET READMODE amp mode sizeof mode NULL value 0xF0 write card fd amp value 1 write OxFO to Digital port 1 mode RWMO
182. supporting real time execution All modern operating systems support such features One such real time solution has been standardized under the name POSIX POSIX is a set of international standards defining the behaviour of a conforming application POSIX is not itself an operating system but rather defines the interface between the application and the operating system For this to work it is essential that the operating system implementers offer the behaviour defined by the POSIX standard A strong feature of POSIX programs is that it is possible to transport source code between any POSIX compliant operating system such that similar behaviour is experienced on any such system after compilation Besides supporting interfaces for real time facilities POSIX also defines interfaces for file handling and security just to name a few tasks This report however will deal with the real time facilities only The POSIX interface is written using the standard programming language C 3 1 3 QNX While all operating systems of today have some kind of real time capability it is important to classify them as being either hard or soft real time operating systems A UNIX or Windows system for example may be considered real time in the sense that a user may expect a response within a few seconds after entering a command e g clicking the mouse button Fortunately it is usually not a disaster if the response is delayed or absent Systems of this kind use
183. synchronized script controlling the thrust of the rocket motor Meanwhile this thread generates a squarewave pulse on the parallel port switches state every 2 seconds This is to demonstrate the use of timers and I O control ny void ignition thread void arg struct sigevent timerevent struct itimerspec itime timer t timer id struct clockperiod clockp oldclock int state 0 int channelid ignition rcvid MSG msg channelid ignition ChannelCreate 0 timerevent sigev notify SIGEV PULSE timerevent sigev coid ConnectAttach ND LOCAL NODE 0 channelid ignition NTO SIDE CHANNEL 0 timerevent sigev priority sched get priority max sched getscheduler 0 timerevent sigev code TIMER PULSE CODE timer create CLOCK REALTIME amp timerevent amp timer id itime it value tv sec itime it interval tv sec 2 itime it value tv nsec itime it interval tv nsec 0 timer settime timer id 0 amp itime NULL for rcvid MsgReceive channelid ignition amp msg sizeof msg NULL 126 G 8 netserver c if rcvid 0 we got a pulse if msg pulse code TIMER PULSE CODE if state 0 SetPPin PIN1 1 Example of Parallell port control SetPinHigh PIN1 1 Example of DAQ IO port control state 1 else SetPPin PIN1 0 SetPinHigh PIN1 0 state 0 ae a Control thread
184. t stability This is probably due to numerical instability of the solution algorithm for some specific part of the model Unfortunately the analysis of this effect was not conclusive Nevertheless we have shown that control of the system which at first seemed very complicated is indeed possible 45 100 angle degrees cn o time s Figure 4 16 Double PID Model simulation with y 60 6 45 U 710 Nm Finally we add a PID controller for the x axis We now have one controller for each of the manoeuvres roll pitch and yaw The resulting model is shown in Figure 4 17 The controller parameters are still the same as before K 13 TI 0 7 Td 0 2 We also added disturbance torques on all three axes acting as generalized forces not accounted for by the model As disturbance signals we choose sine waves with amplitude 0 1 Nm and frequency 5 rad s This kind of disturbances gives more information about the robustness of the controller due to the fact that the system becomes excited by both negative and positive disturbances in the same simulation Rocket Mass Inertia estimator R2D1 Roll error KE x2 calculator Omega x i CI R Reference Y Roll Disturbance Goto4 PID controller3 From4 m m NE R2D3 Pitch error y2 calculator Omegs_y B l Pitch Reference ER Pitch Disturbance Goto5 PID controller1 From11 m Omegs_z LH R2D4 Yaw eror Yaw Reference ER Goto6 Yaw Disturbance z2 ca
185. the ninth set are obtained after the first transfer cycle Hence the question about handling the last two values must be addressed If they are ignored it will be necessary also to ignore the first four measurements of the next block since they are part of the same set Alternatively the last 18 two measurements from the previous block may be stored and then reconnected with the first values of the next block thus in effect mixing old and new data This question does not have a simple answer The only recommendation the author can give is to try to avoid the problem altogether This can be done by selecting frequencies for the ADC and client such that they match the number of channels and thus only multiples of full sets are generated each time the data is transferred from the resource manager to the client 3 4 2 Servo control interface There are many different servo motors on the market all designed for different applications and different environments They also offer different control interfaces depending on how accurate the servo movement must be One servo control interface is the pulse width modulation PWM which is a simple and low cost method of servo control At the time when this project was performed the final choice of servos and servo controller had not been made The robotics lab had though some PWM controlled servos that could be used for the time being This section discusses a small software interface controlling these
186. the right hand side of the window area by double clicking on them Notice that these edit boxes all have property Enable set to Inactive This means that the user cannot type in these boxes while the program is running This is desired since only MATLAB itself should be able to change the contents of these fields The most interesting thing about the boxes is that their tag names are identical with Type ID names defined in DList h This of course is no coincidence In fact when data arrives through the proxy into MATLAB the event handler in DataRecvdHandler m automatically scans all the edit boxes for tag names corresponding to the Type ID of the data packet just arrived If such tag name exists the handler updates the box with the received value This means that we do not have to do much work in order to get our data into the GUI Start by copying one of the text boxes and place it below the others Then copy one of the edit boxes and place it next to the copied text box as in Figure E 8 Edit the string of the text box to read Channel 3 or perhaps a name describing the measured signal Finally set the tag name of the edit box to ID CHAN3 Save and close the window Now we are ready to receive and display the new data from the PC 104 Remark The MATLAB program stores all data received by the PC 104 whether or not the user chooses to display them Instead of displaying the data in a box we can for example plot them in a ni
187. time critical systems such as this High level languages such as C should be avoided if possible since it is harder to analyze the timing overhead of the compiled code E 1 File structure The framework consists of a number of C source and header files Basically there are two programs that execute on the PC 104 during operation Firstly there is the data acquisition driver resource manager which controls the DAQ card and allows other programs to use it Secondly it is the control program itself This is a single C program containing all subsystems discussed in Chapter 3 Table E 1 Header files dmadef h Definitions used by the data acquisition driver to access the DMA hardware IDList h Defines macros used both for internal and remote communication ioports h Definitions and pseudo functions for access to the parallel port as well as the two digital I O ports located on the DAQ card pcm3718 h Definitions for the data acquisition driver pulsecodes h Definitions of the pulse codes used by the framework servoconttol h Code used to access the servo controller Table E 2 Source files netclient c A text client which can be compiled both in QNX as well as in LINUX Can be used as a base for a more sophisticated control and monitoring programs of the PC 104 netserver c This is the main program It compiles in QNX but will only execute on the PC 104 computer pcm3718 c This is the soft
188. to the high current 1 5V signal The implementation of this has not been chosen at the time of writing and requires further investigation Once the voltage converter for the glow plug is installed it should be possible to connect four identical switches three solenoid valves and one glow plug to the PC 104 in order to control the entire propulsion system Figure 3 9 Switching electronics left and solenoid valve right 20 3 4 A Communication protocol We mentioned in section 3 3 4 that communication is not vital for the operation of the rocket otherwise we would not call it autonomous It is however a very useful tool during development and testing e g for finding errors or for tuning system performance Using a communication system also is of advantage once the PC 104 and underlying systems are installed in the rocket Instead of unmounting the PC 104 or its memory the communication cable may be utilized collecting information such as stored data The communication solution developed for this project uses the TCP IP protocol for data transfer The TCP IP protocol is used today in major communication tasks such as the Internet The PC 104 has a built in LAN Local Area Network port which is used for all communications The LAN connector has several attractive features for communication Besides sup port for the TCP IP transfer protocol the most important are e Fast data transfer up to 100 Mbit s e Built i
189. ttitude control system 4 1 Coordinate system In the analysis of a moving rocket it is convenient to use a set of coordinates that is moving along with it The rocket can be considered to be a system of particles whose position relative the moving coordinate axes can be described by coordinates x y see Figure 4 1 The choice of axis orientation is important and depends on the mass distribution of the rocket In our case we will assume a rocket with uniform mass distribution around its longitudinal axis passing through the centre of mass Tho61 O Yi y Figure 4 1 The rocket can be considered to be a system of particles 4 2 Equations of motion for a rocket moving in the plane We want to acquire a general solution for the rocket motion i e we want to know both its position and its attitude in three dimensional space In the most general case this requires us to create a system using six degrees of freedom A common approach used to describe such systems is to analyze the forces and moments acting on the object In order to simplify the transition to a system with six degrees of freedom we will first consider a rocket moving in a plane In this case the system will have three degrees of freedom Choose the x y plane as the plane of reference see Figure 4 2 We assume the rocket to be positioned along the x axis and travelling in the positive x direction For the time being we assume the mass of the rocket to be constant The for
190. tus iofunc write verify ctp msg ocb NULL EOK if runmode VERBOSE printf No write permission Nn return status if msg gt i xtype amp IO XTYPE MASK IO XTYPE NONE return ENOSYS resmgr msgread ctp amp data msg i nbytes sizeof msg i if runmode VERBOSE printf PCM3718 Writiing to digital channel n PCM3718 DIO write data return EOK The PCM3718 main function starts and registers the dev pcm3718 device u main int argc char argv declare variables we ll be using resmgr attr t resmgr attr dispatch t dpp dispatch context t ctp int id i fd char check resmgr connect funcs t connect funcs resmgr io funcs t io funcs iofunc attr t attr 112 G 7 pcm3718 c ThreadCtl NTO TCTL IO 0 runmode NORMAL Jk e kx ek e e e amp initalize default parameter HK KK ke ke e ke e e e x memset amp dev 0 sizeof dev dev iobase 0x210 dev dma channel 3 dev CLK speed 10000000 dev IRQ IRQ5 dev transfer rate 1000 This is set to 1Khz because of the fact that QNX default real time clock is running at 1 kHz OK HK kk kk Kk kk kk kk Ck Ck kk kk hok Ck Kk kk kk hok kk ok Kok kk koe kk kk kk kk ok ke e ke e e ee ee x x Check all user arguments from the command line for i l i lt argc it t if stromp argv i v runmode VERBOSE else if strcemp argv i s runmode SILENT else if
191. uments Match gb Words chid Search Tople Text The ID of a channel that you established by calling ChannelCreate Search All Topics T Tasse Figure D 2 The QNX help viewer 63 D 2 1 Programming in QNX The only text editor that comes shipped with QNX 6 2 non commercial version is the Photon editor The Photon editor is influenced by the Notepad editor found in Microsoft Windows It offers about the same level of programming capabilities which is close to none A better development environment is preferable but there are no alternative editors at the time of this writing for the QNX Photon windowing environment File Edit Search Type Buffer Marker Help e ern 0 0 0 0 sJ 5 EH T T1 EI pthread create amp filter thread id amp attr filter thread NULL usleep 5000 Create the Control thread param sched priority 15 pthread attr setschedparam amp attr amp param pthread create NULL amp attr Control thread NULL usleep 5000 Create other non default priority threads here using the 3 lines of code above as atemplate Create the other threads pthread create NULL NULL ignition thread NULL usleep 5000 pthread create NULL NULL tcpsending thread NULL usleep 5000 pthread create NULL NULL Logging thread NULL usleep 5000 pthread create amp listen thread id NULL tcplistening thread NULL pthread join listen thread id NULL Wait until Listen thread terminates
192. us state space representation Figure 4 5 State space model with integration added From Figure 4 5 the control error e may be expressed as e x 0 0 4 11 The state space representation A B C and D is now augmented with this new state forming the matrices Ar Bi C and Dy This is done by simply adding an extra row and or column containing the new information x 0 1 Olfx 0 1 X A x Bu B 0 0 0 1 x 0 w 100 4 12 X 0 0 Ol x l I 0 X y Cx 0 1 o x 4 13 X The last part of 4 12 includes the addition of a new matrix denoted Br representing the input from the reference 4 From Figure 4 5 the control law u becomes u K x K x K x K x 4 14 32 Thus the final state space model is described by Equations 4 12 4 13 and 4 14 4 4 Rocket motion in three dimensions So far we have focused on the simplified problem of a rocket moving in two dimensions We assumed the rocket mass to be constant and neglected the aerodynamical and gravitational forces This will not model the rocket motion very accurately Extending the model to three dimensions is a first step towards a more accurate model 4 4 1 Equations of motion for a rigid body An object moving in three dimensions has six degrees of freedom Three which are translational and three which describe the object s rotation about its centre of mass all with respect to some axes fixed in the body known as the body frame In or
193. uter has a program called ftp which can be used to transfer files between two computers The Openssh package contains sftp which is a secure ftp program To start an ftp session from the desktop QNX computer to the PC 104 type sftp 169 254 13 200 or connectftp The latter is again an executable macro saving the user from typing the IP address of the PC 104 Ftp is a text based program which lets the user send and retrieve files from the current directory If the user wants to transfer files from a subdirectory say from root framework he or she can type the following cd root framework connectftp Files can be transferred from the current directory to the remote computer by typing send filename To copy a file from the remote computer to the local directory type get filename To close the program type quit or exit 65 E Software framework for autonomous vehicles In this appendix we discuss the C programs developed for this project The code itself which can be found in Appendix G forms a framework for future development In order to program in QNX proper understanding of the C language POSIX real time programming and knowledge of the QNX API is required A must read before trying out any programming in QNX is the book by Krten Krt99 which explains both the basics of real time programming as well as QNX programming Learning how to perform low level API calls directly in C is essential in
194. val timeout fd set rfd int n value char c he struct hostent arg if sockfd socket AF INET SOCK STREAM 0 1 perror Heartbeat return their addr sin family AF _ INET host byte order their addr sin port htons KEEPALIVEPORT short network byte order their addr sin addr struct in addr he h addr bzero amp their addr sin zero 8 zero the rest of the struct if connect sockfd struct sockaddr amp their addr sizeof struct sockaddr 1 perror Heartbeat close sockfd return timeout tv_sec 0 timeout tv_usec 0 129 G 8 netclient c FD ZERO amp rfd while 1 FD SET sockfd n send sockfd amp rfd 11 05 usleep 1000000 switch n select 1 sockfd amp rfd 0 0 amp timeout case 1 perror select return case 0 if nprobes gt maxnprobes printf Client Server not responding Nn close sockfd return break default if n recv sockfd amp c 1 0 lt 0 close sockfd return nprobes 0 close sockfd void tcplistening thread void arg int numbytes index servo pos struct listen timerevent struct itimerspec listen itime char recvbuffer 200 Incoming tcp ip packet buffer char buffer 200 char ptr maxptr endptr ID_t PacketID Ant chid filt for
195. ware in the system as well as the operating system The lower layer components act as a framework for the upper layer components The propulsion control interface should be sufficiently general in order that it may be controlled by different propulsion control algorithms the communication system or protocol should be sufficiently general for it to be used with different data transfer strategies and so on Note that the lower layer components can be reused in a number of autonomous vehicles such as helicopters airplanes and of course rockets We now investigate the subsystems of Figure 3 1 one at a time 12 Autonomous Hybrid Rocket Control Attitude Control Algorithm Servo Control Interface Figure 3 1 Overview of autonomous hybrid rocket control system Data Storage Transfer Algorithm Propulsion Control Algorithm Inertial Measurement Algorithm Communication Protocol Propulsion Control Interface Data Acquisition Software Driver 3 3 1 Inertial measurement Positioning in 3 dimensions is achieved using gyros and accelerometers inside the inertial measurement unit IMU The signals from these components can be connected to a data acquisition card and used as input to an iterative software algorithm that outputs useful parameters such as position attitude and velocity These data are then used as input to the feedback control algorithm see section 3 3 2 The data acquisiti
196. ware driver resource manager for the data acquisition card Only runs on the PC 104 The program netserver c is the main program of this project The program is not complete and it needs several hours of work before it can perform any autonomous control It consists of almost 900 lines of code from which new applications can be built The software driver or resource manager is complete and ready to be used in any application requiring a DAQ module of the same series as the one used in this project E 2 Threads and the C language Each running program in QNX is considered to be a process with at least one thread In C code a thread is a real time element that is syntactically equivalent to a normal C function 67 Instead of being called as a normal function it can be initiated to execute concurrently with other threads of the same process If desired several instances of the same thread can be executed without risk of error An interesting thing with threads is that they share memory with other threads of the same process In practice this means that all global variables in the C source file are shared between threads the same way they are shared in a normal C program Caution must be taken though since threads are running concurrently data protection must be used in order not to corrupt the shared data Such protection systems are integrated as part of the QNX operating system E 2 1 Thread overview The netserver c fil
197. xs te PAS UG ERR dE 11 32 3 Communication through shared variables sse 11 3 2 4 Communication through message passing sssssssssseeeneeneneenennn 12 3 3 SVS COMO VET VICW enaa e A A rA neon ial 12 3 3 1 Inertial meas termient uso e reuera tidie o Fee Ine a a ii 13 3 3 2 Atitude CONOR cg eo Seide ias UR det en idet a i 13 3 3 3 Propulsiofi control cire inan et ue ie R v RTRA 14 3 3 4 Data storage amp communication sessesssssssseeeeeenee enne ener enne nnne 15 3 4 Implementation of lower layer components sess 15 3 4 1 Data acquisition software dEIVet s socscess sins as teecledecvancs sateen YT aces oed ecra ei ken 15 3 4 2 Servo control Interface ore eae oin disces etur d boner uis 19 3 4 3 Propulsion control interfaCe ssis sristi uoti inaia a are ale ein ende 19 3 4 4 Communication protocol a od dee e certet sedute eim erlauben d 21 3 5 Implementation of higher layer components 21 3 5 1 Thread priorities odas oc een en n Oe A eco sme ER NRE A 23 3 5 2 Synchronization sse ates redes er e ie eei EEE da UR dees eae 24 3 5 3 Proposition for a final design us od E Raetia bed ER via ba RE rage eo Ea be dao 24 3 6 Remote control and motitortfip rc oce epo te So ONG n p Sod e ibd de euge 25 3 6 1 The MATLAB Graphical User Interface sess 26 S4 ANA ter summa reich enc eset rots Id eno e ESE a quede oe svi ed ul asus tese d nas 28 vii 4 Rocket dynamic ANA

Download Pdf Manuals

image

Related Search

Related Contents

"service manual"  700 Series Manual    Manual de Recuperação, Cópias de Segurança e  Genicom Serial Matrix 3850 User's Manual  BMW 228i Coupe Service and Warranty Information  取扱説明書 - 有限会社メリット    

Copyright © All rights reserved.
Failed to retrieve file