barcode rendering framework c# example Sound Counting FSM in Font

Creator PDF 417 in Font Sound Counting FSM

Sound Counting FSM
PDF417 Encoder In None
Using Barcode creation for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
Code 3/9 Generation In None
Using Barcode creation for Font Control to generate, create Code39 image in Font applications.
www.OnBarcode.com
As described in the section JohnNXT User Guide, when you enter the Arms Control mode in JohnNXT s menu, you can control the position of its arms with sound pulses. Now, let s analyze the mechanism that makes this possible: the sound counting FSM, illustrated in the diagram in Figure 8-9.
UCC - 12 Creation In None
Using Barcode encoder for Font Control to generate, create GS1 128 image in Font applications.
www.OnBarcode.com
Barcode Printer In None
Using Barcode drawer for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Figure 8-9. The sound counting FSM diagram Its implementation code, whose outline was included in Listing 8-2, is reported in Listing 8-3.
GTIN - 13 Printer In None
Using Barcode maker for Font Control to generate, create European Article Number 13 image in Font applications.
www.OnBarcode.com
Make UPC A In None
Using Barcode generation for Font Control to generate, create GTIN - 12 image in Font applications.
www.OnBarcode.com
CHAPTER 8 JOHNNXT IS ALIVE!
Paint QR Code JIS X 0510 In None
Using Barcode printer for Font Control to generate, create Denso QR Bar Code image in Font applications.
www.OnBarcode.com
UPCE Printer In None
Using Barcode generator for Font Control to generate, create UPC - E1 image in Font applications.
www.OnBarcode.com
Listing 8-3. The Sound Counting FSM Implementation, to Control JohnNXT s Arms with Sounds //////////////////////////////////////////////////////////////////////////////// // MANIPULATION // //////////////////////////////////////////////////////////////////////////////// #define #define #define #define #define #define E_EXIT 1 E_TRIGGER 2 E_ELAPSE 3 E_TIMEOUT 1300 FSM_IDLE 0 FSM_COUNTING 1
PDF417 Generator In Java
Using Barcode generator for Android Control to generate, create PDF-417 2d barcode image in Android applications.
www.OnBarcode.com
PDF 417 Drawer In VS .NET
Using Barcode generator for ASP.NET Control to generate, create PDF417 image in ASP.NET applications.
www.OnBarcode.com
int MeasureNoise () { int n; //estimate ambient noise by averaging 10 readings n = 0; repeat(10) { n += Sensor(MIC); Wait(20); } n /= 10; return n; } // this function waits for one of three events: // - someone clicks the orange button // - the timer elapses // - a loud sound pulse occurs // and returns a number to describe which event // occurred first short WaitEvent(short noise, unsigned long timer) { short event = 0; while ( event==0 ) { if (ButtonPressed(BTNCENTER,true)==1) { event = E_EXIT; while(ButtonPressed(BTNCENTER,true)==1); TextOut(5,LCD_LINE6,"Button"); } else if (CurrentTick() > timer + E_TIMEOUT) { event = E_ELAPSE; TextOut(5,LCD_LINE6,"Elapse");
GTIN - 12 Maker In None
Using Barcode generator for Office Excel Control to generate, create UPC-A image in Office Excel applications.
www.OnBarcode.com
Encode Code 128 In Java
Using Barcode maker for Android Control to generate, create Code 128B image in Android applications.
www.OnBarcode.com
CHAPTER 8 JOHNNXT IS ALIVE!
Generating UCC - 12 In Java
Using Barcode generator for Java Control to generate, create UPC Symbol image in Java applications.
www.OnBarcode.com
Barcode Creator In None
Using Barcode drawer for Microsoft Word Control to generate, create Barcode image in Office Word applications.
www.OnBarcode.com
} else if (Sensor(MIC)>noise+50) { event = E_TRIGGER; TextOut(5,LCD_LINE6,"*"); until(Sensor(MIC)<noise+40); Wait(10); } } ClearLine(6); return event; } // this subroutine shows the actual state of the arms FSM sub ShowArmsState(short state, short line) { ClearLine(line); switch(state) { case A_FOLDED: TextOut(5,(8-line)*8,"Folded"); break; case A_UP: TextOut(5,(8-line)*8,"Up"); break; case A_CLOSED: TextOut(5,(8-line)*8,"Hands closed"); break; case A_OPEN: TextOut(5,(8-line)*8,"Hands open"); break; case A_ROTATE: TextOut(5,(8-line)*8,"Wrist rotate"); break; } } // this subroutine manages the arms FSM, to command the arms with // sound pulses sub J5_Manipulation() { unsigned long soundFSMtimer; short count = A_FOLDED; short state = FSM_IDLE; short event; bool exit; short noise; ClearScreen(); TextOut(0,LCD_LINE1,"Arms control"); // measure background noise noise = MeasureNoise(); Remote(A_FOLDED,ACK_DONE); // the sound counting FSM is implemented as follows until(exit) { if (state == FSM_IDLE) {
UPCA Maker In Objective-C
Using Barcode creator for iPad Control to generate, create UCC - 12 image in iPad applications.
www.OnBarcode.com
Painting Code 39 Extended In Visual C#.NET
Using Barcode generation for VS .NET Control to generate, create Code 39 Full ASCII image in VS .NET applications.
www.OnBarcode.com
CHAPTER 8 JOHNNXT IS ALIVE!
PDF-417 2d Barcode Scanner In C#
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Generating 2D Barcode In C#.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create 2D image in VS .NET applications.
www.OnBarcode.com
// wait for an event event = WaitEvent(noise,soundFSMtimer); // perform the actions for this state if (event == E_TRIGGER) { state = FSM_COUNTING; count = A_FOLDED; } else if (event == E_ELAPSE) { // reset the timer soundFSMtimer = CurrentTick(); } else if (event == E_EXIT) exit = true; } else if (state == FSM_COUNTING) { // displays information onscreen line 3 ShowArmsState(count,3); // wait for an event event = WaitEvent(noise,soundFSMtimer); // perform the actions for this state if (event == E_TRIGGER) { count++; if (count>A_ROTATE) count = A_ROTATE; // reset the timer soundFSMtimer = CurrentTick(); } else if (event == E_ELAPSE) { // reset the timer soundFSMtimer = CurrentTick(); Remote(count,ACK_DONE); state = FSM_IDLE; } else if (event == E_EXIT) exit = true; } } } The J5_Manipulation() subroutine is called by the principal JohnNXT FSM from the main task, when you choose the Arms Control item from the JohnNXT menu. This subroutine starts measuring the average ambient noise by calling the MeasureNoise() function, which reads the Sound Sensor ten times and then computes the arithmetic average.
Data Matrix ECC200 Creator In Visual C#
Using Barcode drawer for .NET framework Control to generate, create Data Matrix ECC200 image in Visual Studio .NET applications.
www.OnBarcode.com
Barcode Drawer In Visual C#.NET
Using Barcode drawer for .NET Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 8 JOHNNXT IS ALIVE!
Averaging many measurements over time is useful for lowering the uncertainty of the whole measureTip ment. For example, imagine making a single measurement of the sound level, right when an unpredictable loud noise occurs. You would get a bad estimation of the real environment s background noise: in fact, you expected to get a low percentage value, but your single measurement has returned a high value, because of that sudden loud noise. In robotics, it s a bad habit to trust a single measurement. To avoid having a single measurement corrupt your estimation with its high uncertainty, it s common use to average many measurements over time. Every time you make a new measurement, it contributes to lowering the estimation s uncertainty.
To compute the average value, you simply sum these ten readings in the variable n (initially set to zero) and then divide it by ten. This noise measurement is then used as a threshold to detect loud sounds, such as hand claps or whistles. As previously said, the FSM in Figure 8-9 is implemented in the J5_Manipulation() subroutine. The code s meaning is straightforward. In both the two states, the WaitEvent function detects the events. This function waits for one of three kinds of events, by returning the corresponding opcode to the FSM: the orange NXT button click that causes the whole routine to exit, the timer elapsing, or a loud sound s detection. In the beginning, the FSM is in IDLE mode, and there it remains until a loud sound is detected. The count variable is initialized with the A_FOLDED value. The first sound detected is an event that causes the state to switch from IDLE to COUNTING, and the count variable to assume the value A_FOLDED, which is the first value among the constants that describe the arms state. While in the COUNTING state, a new sound detection is an event that causes the count variable to be incremented by one (limited by the maximum value of A_ROTATE) and the timer to be reset. If you stop clapping, the timer elapses, and the arms are actuated according to the count variable s value. The master actuates the arms by calling the Remote(count, ACK_DONE) function, which sends the count variable value as a command to the slave NXT. The count variable can assume one of the values of the possible commands for the arms: remember that the constants in capital letters are indeed aliases for numerical values, declared in JohnNXT s header file J5Defs.nxc. So, by passing count to the Remote function, you re just telling the FSM implemented in the slave NXT program to bring the arms into one of their possible states. After the arms actuation, the state comes back to IDLE and the timer is reset. If the timer elapses while the FSM is in IDLE mode, it does not cause any action. If you were paying attention, you would notice that the code that implements the timer is the same as I described in 6, using the soundFSMtimer variable and the CurrentTick() NXC API function. Now you know the internals of the sound counting FSM.
Copyright © OnBarcode.com . All rights reserved.