A brain-controlled dolly control method based on concentration and SSVEP
By combining SSVEP signals and attention EEG signals for automated control, the problems of limited functionality and reliance on manual operation of cotton candy machines have been solved. This enables personalized flavor selection and dynamic speed control, enhancing the interactivity and fun of the device, making it suitable for diverse scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- YANSHAN UNIV
- Filing Date
- 2026-02-13
- Publication Date
- 2026-06-02
AI Technical Summary
Existing cotton candy machines have fixed and limited functions, lack personalized flavor options and interactivity, rely on manual operation, and cannot adapt to diverse scenarios.
By combining SSVEP signals with attention EEG signals, the entire process can be automated. By combining voice interaction and multimodal feedback, a mapping logic between EEG features and device execution can be constructed to optimize the brain-controlled interactive experience.
It enables personalized flavor selection, automatic ingredient addition, and dynamic speed control, enhancing the interactivity and fun of the device, making it suitable for diverse scenarios such as parent-child interaction and leisure entertainment.
Smart Images

Figure CN122131915A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a brain-controlled cotton candy machine control system and its implementation method based on attention span and SSVEP (Steady State Visual Evoked Potential) acquisition. Utilizing brain-computer interface principles, a multifunctional, fully automatic flavor-selection cotton candy machine is designed, combining portability, engaging operation, and interactive experience. It is suitable for entertainment, education, and experiential consumption scenarios, specifically including amusement park parent-child interaction areas, science museum brain science experience exhibitions, youth attention training institutions, and shopping mall experiential consumption stalls. By combining human physiological signals with device control, a more interactive and fun cotton candy making process is achieved. This invention particularly integrates flavor selection based on SSVEP, automatic filling function, attention span-based automatic motor control, and voice-enabled barrier-free interaction. By adapting to professional EEG acquisition equipment, it fills the gaps in existing technology regarding flavor customization and barrier-free operation. Background Technology
[0002] The traditional cotton candy machines currently on the market have the following key drawbacks: 1. Limited and fixed functions: It only has the basic core function of "heating-rotating sugar making", without flavor selection or customization mechanism. All production processes default to a single ingredient ratio, which cannot meet users' needs for personalized flavors. 2. Operation relies on manual labor: Traditional cotton candy machines mostly require manual addition of raw materials and fixed speed adjustment. The entire process relies on manual intervention, which is not only cumbersome to operate, but also prone to poor taste or waste of raw materials due to improper timing of material addition and improper speed control. 3. Lack of interactive experience: There is no multi-faceted interactive feedback between the device and the user, such as visual and auditory interaction, resulting in a lack of interactive experience. It can only be manually operated in fixed scenarios (such as street stalls and home kitchens), and cannot be adapted to scenarios that require "immersive participation," such as parent-child interaction, science popularization experience, and attention training. To address the aforementioned shortcomings, this invention constructs an integrated control chain for SSVEP flavor selection, dynamic focus adjustment, and automatic ingredient dispensing. It optimizes the mapping logic between EEG characteristics and device execution, and combines auxiliary functions such as synchronized skewer rotation and voice interaction to solve the problem of fragmented functions in existing technologies, thereby enhancing the completeness and fun of brain-controlled interaction. Summary of the Invention
[0003] The core objective of this invention is to provide a brain-controlled cotton candy machine control system and its implementation method based on SSVEP and attention acquisition. By establishing a correlation model between SSVEP signals and flavor selection, attention characteristics and production parameters, the system achieves full-link automated control of "EEG signals - device actions", creating an immersive brain-controlled interactive experience.
[0004] The positive effects of this invention are as follows: 1. Brain-controlled closed loop with dual EEG signal fusion This invention combines SSVEP with attention EEG signals to achieve full-process control: SSVEP signals correspond to three flavors (8Hz original, 10Hz strawberry, and 12Hz pineapple), and alpha and beta waves are collected through FP1 / FP2 electrodes on the forehead and fitted to a value of 0-100. Attention signals control the motor speed, forming a closed loop of "acquisition-analysis-execution", breaking through the limitation of traditional devices that lack personalized brain control.
[0005] 2. High-precision EEG acquisition and preprocessing This invention arranges Ag / AgCl wet electrodes according to the 10-20 international electrode system, and uses an 80dB gain amplifier, 0.1-100Hz bandpass filter, and 50 / 60Hz notch filter, combined with FastICA to remove electrooculography artifacts (removal rate >95%), to stabilize the focus value by a 3-second sliding average.
[0006] 3. Focus - Speed Gradual Control Establish a precise mapping relationship (accuracy error ≤2%): when focus is >80, the motor speed is 2500-3000 r / min; when focus is 60-80, the speed is 1500-2500 r / min; when focus is 50-60, the speed is 500-1500 r / min. When focus is <50, maintain 500 r / min for ≤5 seconds, and stop the machine if the timeout is exceeded to avoid waste of raw materials.
[0007] 4. Automatic feeding and sugar jam removal The feeding box of this invention uses three miniature servo motors with a rotation accuracy of ±1° to control the gate. It can feed 5-8g of sugar at a time. When the infrared sensor under the gate detects that sugar is stuck (obstruction for more than 2 seconds), it triggers the motor to reverse for 0.5 seconds to clear the obstacle. If it fails 3 times in a row, it prompts the cleaning.
[0008] 5. Multimodal interactive feedback The touchscreen displays real-time focus levels (<60 red, 60-80 yellow, >80 green), rotation speed, and SSVEP flavor flashing, with corresponding sound effects for different states (rising tone for increasing rotation speed, rapid tone for malfunctions); with LD3320 chip support, it plays voice commands such as "Start Selection" and "Stop Production", achieving an accuracy rate of ≥95% after training.
[0009] 6. Expanded Scenario Adaptability: Targeting scenarios such as parent-child interaction and leisure entertainment, the brain-controlled experience is made more suitable for different user groups through attention level-based control logic, expanding the applicable scenarios to diverse scenarios such as homes, shopping malls, and science exhibition halls. Attached Figure Description
[0010] Figure 1 This is a schematic diagram of the overall structure of the present invention; Figure 2 This is a block diagram of the hardware system structure of the present invention; Figure 3 This is a schematic diagram of the software system modules of the present invention; Figure 4 This is a state transition diagram of the control flow of the present invention; Figure 5 This is a schematic diagram of the internal structure of the container housing of the present invention; Figure 6 This is a graph showing the relationship between focus and rotational speed in this invention. Figure 7 This is a schematic diagram showing the channel occupied by the EEG acquisition device of the present invention; Figure 8 This is a schematic diagram showing the positions of each pixel block on the SSVEP stimulation interface of the present invention.
[0011] Figure 1 The components are: 1. NeuroSci wireless EEG acquisition system, 2. Cotton candy machine main body, 3. Main controller STM32F407ZGT6, 4. Human-computer interaction interface smart touch screen, 5. Relay, 6. Integrated shell, 7. Cotton candy sugar filling port, 8. Skewer container, 9. Aluminum alloy frame for fixing sugar box, 10. Food-grade PP material sugar box, 11. Cotton candy machine relay connection cable. Detailed Implementation
[0012] As attached Figure 1-8 The present invention consists of two parts: a hardware system and software. The hardware system includes: 1. Attention and SSVEP Acquisition Module (NeuroSci Wireless EEG Acquisition System 16 Channels): As the core signal source of the system, it must strictly adhere to its electrode distribution, wearing rules, and data transmission protocol. The specific design is as follows: 1-1 Electrode Configuration and Distribution: Following the 10-20 international electrode system, 16 Ag / AgCl wet electrodes are distributed at: forehead (FP1, FP2), central region (C3, C4, Cz), parietal lobe (P3, P4, Pz), occipital lobe (O1, O2), temporal lobe (T3, T4, T5, T6), reference electrode (Nz, nasal root), and ground electrode (Fz, midline of the forehead). Functional division of labor: FP1 / FP2 electrodes are used to acquire prefrontal β wave (13-30Hz) and α wave (8-13Hz) signals related to attention, O1 / O2 electrodes are used to acquire occipital steady-state visual evoked potentials related to SSVEP, Nz electrode provides signal reference, and Fz electrode is grounded to reduce common-mode interference.
[0013] 1-2. Signal preprocessing and transmission: The system has built-in signal conditioning circuitry: an 80dB gain preamplifier (adjustable via software), a 0.1-100Hz bandpass filter (to filter out low-frequency baseline drift and high-frequency electromyographic noise), and a 50 / 60Hz dual-frequency notch filter (to suppress power frequency interference). The output noise is ≤1μVrms, ensuring signal purity. Wireless transmission: Employs a 2.4GHz wireless module (IEEE 802.11b / g / n protocol), with a transmission rate of 1Mbps, a transmission distance of 10m (unobstructed), a data frame format including timestamp, electrode identification, signal value, and checksum, a data size of 32 bytes per frame, a transmission latency of <50ms, and a packet loss rate of <0.1%. Power supply and initialization: A separate 220V to 5V / 2A DC power supply is required (ripple < 50mV). After power-on, initialization is required for 30 seconds (indicator lights red → yellow → green, solid green light indicates ready). During the initialization process, the system automatically completes gain calibration and noise detection.
[0014] 1-3. Wearing and Calibration Rules: Electrode preparation: Use a special medical-grade electrode paste (containing sodium chloride and glycerin, impedance ≤5kΩ) and apply it evenly to the electrode contacts (thickness 0.5-1mm) to avoid air bubbles remaining; Wearing steps: First, fix the Nz reference electrode (at the root of the nose, pressure 0.3-0.5N) and the Fz ground electrode (at the midline of the forehead, pressure 0.5N). Adjust the FP1 / FP2 electrodes: position on the forehead (3cm above the brow bone, 2cm to the left and right), close to the skin (pressure 0.5-1N), ensuring no hair obstructs the view; Fix the O1 / O2 electrodes: occipital lobe position (2cm above the occipital protuberance, 3cm to the left and right), and fix them with an elastic headband after they are attached to the skin; Other electrodes (such as C3 / C4, P3 / P4) can be selectively worn (for signal redundancy verification). If they are not worn, they need to be set to "disabled" via software to avoid interference. Impedance calibration: After wearing, perform "impedance test" through the system software to ensure that the impedance of all activated electrodes is <5kΩ (shown in green). If it is >10kΩ (shown in red), you need to reapply electrode paste or adjust the electrode position until the calibration is successful.
[0015] 2. Main control module The STM32F407ZGT6 microcontroller was selected as the core, with a focus on optimizing communication compatibility with the NeuroSci system. The specific design is as follows: 2-1. Hardware Parameters: Equipped with a 168MHz ARM Cortex-M4 core, 1MB Flash (128KB allocated for storing NeuroSci system calibration data, parsing algorithm library and speech templates), 192KB RAM (64KB allocated for EEG data caching, 32KB for control logic variable storage); it has expansion interfaces such as UART, SPI, I2C, and PWM, supports hardware floating-point operations, and can quickly complete FFT transformation and ICA artifact removal (FFT operation time for a 3-second data window < 50ms). 2-2. Communication Adaptation: Connects to a 2.4GHz wireless receiver module via SPI interface to establish data interaction with the NeuroSci system. Receives one frame of data every 10ms (containing FP1 / FP2 and O1 / O2 electrode data from 25 sampling points) and stores it in a circular buffer. Sends control commands to the NeuroSci system via UART interface (115200 baud rate) (e.g., "Start Acquisition", "Adjust Gain", "Read Impedance"), with a command response time <100ms. 2-3. Data Verification: After receiving data, a dedicated verification protocol based on the CRC16 algorithm is invoked to verify data integrity, eliminate lost packets (discontinuous frame counts) or erroneous data (mismatched check bits), ensure parsing accuracy, and avoid control deviations caused by data errors in the existing system.
[0016] 3. Execution Module It includes the main body of the cotton candy machine, a motor control unit, a sugar flavor control submodule, and a skewer container submodule, realizing the full-process motion control of cotton candy making.
[0017] 3-1. Main body of the cotton candy machine and motor control unit: The main body of the cotton candy machine uses a 220V AC motor (rated power 150W), supporting stepless speed regulation from 0-3000r / min. The motor output shaft is rigidly connected to the rotating head of the cotton candy machine via a coupling. The motor control unit consists of an SRD-05VDC-SL-C normally open electromagnetic relay, a drive circuit (including a 1N4007 reverse freewheeling diode), and a protection circuit (current sensor ACS712, voltage monitoring circuit). The relay coil is connected to the GPIO pin of the microcontroller through a 220Ω current-limiting resistor. The common terminal is connected to the 220V live wire, and the normally open terminal is connected to the motor power input terminal. When the motor current is greater than 1A or the 220V AC voltage is less than 180V / greater than 240V, the machine automatically cuts off power or stops operation.
[0018] 3-2. Sugar Flavor Control Submodule: The system includes an aluminum alloy frame (fitted to the size of the cotton candy machine and bolted to the top of the machine), a food-grade PP sugar container (with three 50mL compartments for plain (white), strawberry (red), and pineapple (yellow) sugar respectively), three miniature servo motors (model SG90, each corresponding to one of the three compartments), and an E18-D80NK infrared sugar-dispensing sensor. The servo motor output shaft connects to the gate at the bottom of the compartment (gate opening 0-90°, 0° closed, 90° fully open), allowing for a 2-second full opening to dispense 5-8g of sugar. The infrared sensor is installed below the gate; when it detects sugar blocking (obstruction for more than 2 seconds), the servo motor reverses for 0.5 seconds to attempt to clear the blockage. If it fails three times consecutively, it displays "Gate blocked, please clear." Simultaneously, taking into account data transmission delay, the servo motor starts 50ms before the flavor selection command is detected, ensuring precise sugar dispensing.
[0019] 3-3. Stick Container Submodule: The system includes a food-grade ABS cylindrical container (3cm inner diameter, 15cm height, with elastic slots on the side wall for securing the marshmallow sticks) and a synchronous belt drive mechanism (synchronous belt pulley A mounted on the marshmallow machine motor shaft, and synchronous belt pulley B mounted on the container's rotating shaft, with a gear ratio of 1:1). The container is fixed to the side of the marshmallow machine by a bracket, and its rotation speed is consistent with the speed of the marshmallow machine motor (error <1%). An A3144 Hall effect speed sensor is installed at the end of the container's rotating shaft to provide real-time feedback of speed data to the microcontroller. If the speed deviation is >2%, the SG90 servo motor (driving the synchronous belt tensioner) is finely adjusted via PWM to ensure synchronization.
[0020] 4. Display Module: It features a 7-inch SPI touchscreen (1024×600 resolution, 60Hz refresh rate), fixed to the side of the cotton candy machine's housing, providing both image display and touch operation. It supports displaying the SSVEP flavor selection interface (containing three flashing frequency blocks: original 8Hz white, strawberry 10Hz red, pineapple 12Hz yellow), a focus tracking interface (real-time display of "Current Time: XX seconds" in the upper left corner, along with focus value and color indicators), and a completion interface (including preparation time and a "Return to Selection" button).
[0021] 5. Audio module Includes the VS1053 audio decoding chip and speaker, which connects to the main control module via the I2C interface. It supports playing SSVEP selection prompt tone ("beep beep" sound), focus status sound effect (rising scale for speed increase, falling scale for speed decrease), completion cheer sound, and NeuroSci system abnormal prompt tone (1500Hz "beep beep beep" rapid sound effect with an interval of 0.3 seconds when the signal is lost or the electrode impedance is too high).
[0022] 6. Voice control module It includes an LD3320 speech recognition chip (supporting offline recognition) and connects to a microcontroller via a UART interface. Preset commands include "Start Selection," "Confirm Flavor," "Stop Making," and "Return to Selection." After training with 10 samples, the recognition accuracy is ≥90%. It supports a "Speech Training Mode," which collects three speech samples (2 seconds each) for each command, improving personalized recognition accuracy to ≥95%. During training, the system microphone is at least 30cm away from the EEG electrodes, and the NeuroSci system is in "idle mode" (not collecting EEG data). The speech template is stored in the microcontroller's Flash memory, eliminating the need for retraining upon each startup.
[0023] 7. Power Module It includes a 220V to 5V / 3A DC power supply (for the microcontroller, display module, and voice module), a 220V to 5V / 2A DC power supply (for the NeuroSci system, with a power cord length ≤2m and a distance of ≥10cm from the motor power supply line), a 220V to 12V / 1A DC power supply (for the servo motor), and a 220V AC power supply (for the cotton candy machine motor), equipped with a main control switch and an overload protection circuit breaker.
[0024] The hardware system includes: 1. NeuroSci Data Interaction Module: This module is responsible for communication initialization, data reception, and verification with the focus and SSVEP acquisition modules. After turning on the main control switch, it first powers the NeuroSci system and waits 30 seconds for initialization (the indicator light turns green). The microcontroller sends an "initialization command (0xAA)" via UART and receives a "ready response (0x55)" from the system. It then sends a "calibration command (0xAB)," and the system automatically completes the 80dB gain and 50Hz notch filter settings, returning the calibration result (0x00 for success, 0x01 for failure). If it fails, it prompts "Please recalibrate the NeuroSci system."
[0025] The system uses an interrupt reception method, receiving one frame of data every 10ms and storing it in a circular buffer. The effective data rate is counted every second. If it is less than 95% (packet loss rate > 5%), the system prompts "Poor wireless signal, please move closer to the device" and reduces the transmission rate to 500kbps. When the wireless signal strength is less than -70dBm, an audio alarm is triggered and the user is prompted to adjust the device's position. When the data packet loss rate is greater than 10%, the system switches to a backup wireless channel.
[0026] 2. SSVEP signal processing module Based on the focus and SSVEP acquisition module's O1 / O2 electrode data from the occipital lobe, a flavor selection function is implemented. The NeuroSci system's built-in filtering interface is used for 0.5-30Hz bandpass filtering, followed by 8th-order IIR 50Hz notch filtering via a microcontroller. The 3-second data window (750 sampling points) is zero-padded to 1024 sampling points, improving the FFT frequency resolution to 0.244Hz. The NeuroSci system's FFT acceleration algorithm interface is used; the 3-second data window calculation takes less than 30ms, calculating the power spectrum in the 8-12Hz band. The peak frequency of the power spectrum is found, and its power is verified to be more than twice that of the adjacent frequency (±0.5Hz). If |-8Hz| < 0.5Hz, the flavor is determined as original; |-10Hz| < 0.5Hz, as strawberry; and |-12Hz| < 0.5Hz, as pineapple. If the conditions are not met, the message "Please look at the flavor block again" is displayed.
[0027] 3. Attention Analyzer Module The data from the forehead FP1 / FP2 electrodes was extracted using the NeuroSci system's dedicated data parsing protocol. The data was first filtered by the system's built-in 0.1-100Hz filter, and then filtered twice by the microcontroller (0.5-30Hz FIR low-pass filter and 0.5Hz high-pass filter). The FastICA algorithm was used to remove electrooculography (EOG) artifacts, with an artifact removal rate of >95%. The baseline calibration interface was called every 5 minutes to collect the alpha wave baseline value in a 10-second relaxed state.
[0028] The preprocessed data is segmented into 250 sampling points with a window length of 1 second, and FFT transformation is performed (256 points). The average power P_α of α wave (8-13Hz) and the average power P_β of β wave (13-30Hz) are calculated based on the system calibration sensitivity (1μV / bit) (unit: μV² / Hz).
[0029] The fitting formula was obtained through calibration experiments: (Goodness of fit R² ≥ 0.95) Calculate the focus score (range 0-100) using a 3-second moving average: Reduce volatility; the volatility range should be less than ±5.
[0030] 4. Control Logic Module A state machine design is used to achieve fully automated control of the entire process: 4-1. SSVEP Flavor Selection Status: The display module enters the selection interface. The user triggers "Start Selection" via touch or voice, and the interface jumps to the flavor selection interface. After parsing the SSVEP signal to complete the flavor determination, the corresponding servo motor is controlled to add sugar, and then the initialization state is entered.
[0031] 4-2. Initialization state: Monitor focus level. If the focus level is >30 for 3 consecutive seconds, enter the warm-up state; otherwise, prompt "Please concentrate (focus level must be >30)".
[0032] 4-3. Preheating state: The motor rotates at 3000r / min, displays a 60-second countdown, and plays background music.
[0033] 4-4. Interactive Status: After the preheating is completed, if the monitoring is >60 for 3 consecutive seconds, the production status will be entered; otherwise, the message "Please stay focused (focus level must be >60)" will be displayed.
[0034] 4-5. Production Status: The motor speed is dynamically adjusted (2500-3000 r / min when >80, 1500-2500 r / min when between 60-80, 500-1500 r / min when between 50-60, and a delay timer is activated when <50: ≤5 seconds V=500 r / min, 5 <≤10 seconds V=0, >10 seconds returns to interactive status); the total motor rotation time is accumulated, with a maximum of 300 seconds. Users can terminate the process by touching or using voice to "stop production".
[0035] 4-6. Completion Status: The motor stops, a cheering sound plays, the production time is displayed, and a "Return" button is shown. After triggering, it returns to the SSVEP selection interface.
[0036] 5. NeuroSci System Status Monitoring Module Real-time monitoring of wireless signal strength (read every 2 seconds), electrode impedance (read FP1 / FP2 / O1 / O2 electrode values every 5 seconds), system battery level (read every 10 seconds), and data packet loss rate (statistics every 1 second). When the wireless signal strength is < -70dBm, a message "Weak signal, please move closer to the device" is displayed; when the electrode impedance is > 10kΩ, a message "High electrode impedance, please reapply electrode paste" is displayed and focus acquisition is paused; when the system battery level is < 20%, a message "Low system battery, please charge" is displayed and a log is saved; when the data packet loss rate is > 10%, the transmission rate is reduced or a backup channel is switched.
[0037] Troubleshooting process: When the signal is lost (wireless disconnection for more than 3 seconds), pause the motor operation, save the production progress, and prompt "EEG signal lost, please check the equipment"; when the electrode falls off (impedance > 20kΩ), stop the acquisition, play an urgent prompt tone, and prompt "Electrode fallen off, please put it back on"; when the system crashes (no response for more than 5 seconds), trigger the "hardware reset" command, and reinitialize after reset.
[0038] 6. Log and Interactive Feedback Module The log records the running data (timestamp, selected flavor, attention curve, rotation speed curve, NeuroSci system status (signal strength, electrode impedance), and fault information) in CSV format. It supports export via USB interface and can also export the raw EEG data of NeuroSci system (.edf format).
[0039] Interactive feedback includes visual feedback (the flashing frequency of the flavor selection interface is stable, with an error of ±0.1Hz; the text color of the focus interface is: red for <60, yellow for 60-80, and green for >80); Audio Feedback: Each system state corresponds to a unique sound effect, and the sound effect parameters are deeply adapted to the scene. When the SSVEP flavor selection interface finishes loading, a 1kHz "beep beep" dual-tone prompt sound (0.5-second interval) plays to prompt the user to enter the selection process; when the user stares at the target flavor flashing block, a 500Hz single "beep" sound plays every 1 second to enhance the visual-auditory linkage; after the flavor is successfully determined, a 1.2kHz rising scale is played (lasting 0.8 seconds), simultaneously triggering a sugar dispensing action prompt. In the focus control scenario, when the speed increases from low (500-1500r / min) to medium (1500-2500r / min), an 800-1000Hz linear rising scale is played (lasting 0.5 seconds); when increasing from medium to high (2500-3000r / min), a 1000-1200Hz rising scale is played (lasting 0.5 seconds); when the speed decreases, a falling scale in the corresponding frequency band is played, forming a clear status change prompt.
[0040] Upon completion, a multi-band mixed cheering sound (containing a 1.5kHz high frequency and an 800Hz low frequency, lasting 2 seconds) will be played. In abnormal scenarios of the NeuroSci system, if the signal strength is <-70dBm or the electrode impedance is >10kΩ, a rapid 1500Hz "beep beep beep" alert sound will be played (0.3-second intervals, volume 60%) until the abnormality is resolved; if the data packet loss rate is >10%, a 1200Hz "beep-beep" alert sound will be played (1-second intervals, volume 40%) to remind the user to adjust the device position.
[0041] The implementation method of this invention is as follows: 1. System startup and initialization 1-1. Turn on the main control switch. The power supply unit supplies power to each module. The 220V to 5V / 3A DC power supply powers the STM32F407ZGT6 microcontroller, display module, and voice module. The 220V to 5V / 2A DC power supply is dedicated to powering the NeuroSci wireless EEG acquisition system. The 220V to 12V / 1A DC power supply powers the servo motor. The 220V AC power supply powers the cotton candy machine motor. The microcontroller automatically starts and runs the preset control program developed based on KeilMDK.
[0042] 1-2. The user wears the 16-channel electrodes of the NeuroSci wireless EEG acquisition system. The Ag / AgCl wet electrodes are fixed according to the 10-20 international electrode system distribution: the forehead FP1 / FP2 electrodes are in close contact with the skin (pressure 0.5-1N), the occipital lobe O1 / O2 electrodes are in contact with the occipital lobe skin, and the Nz reference electrode at the root of the nose and the forehead Fz ground electrode are fixed with medical tape. Apply special electrode ointment to ensure that the impedance between the electrodes and the skin is <5kΩ. The user clicks the "Start" button on the display unit or says the voice command "Start Selection".
[0043] 1-3. System enters self-test process: Checks NeuroSci system connection status (wireless signal strength ≥ -55dBm, electrode impedance < 5kΩ), sends test commands via SPI interface to verify communication; checks motor drive module, outputs test PWM signal to control cotton candy machine motor to rotate briefly, and simultaneously detects the speed of synchronous belt drive mechanism of skewer container; checks display unit, displays test pattern and "NeuroSci system status bar"; checks audio module, plays test sound effect (1000Hz monotone, lasting 1 second); checks voice module, receives "start selection" command and provides feedback on recognition result; checks sugar flavor control submodule, controls servo motor to drive gate to open and close once, infrared sensor detects whether sugar is stuck.
[0044] 1-4. After the self-test is passed, the system enters the SSVEP selection state and displays the prompt message "Please press the following button / voice 'Start Selection' to select your marshmallow flavor". At the same time, the NeuroSci system is started to receive 16-channel EEG data (default sampling rate 250Hz).
[0045] 2. SSVEP Flavor Selection and Attention Collection Processing 2-1. SSVEP Data Reception and Analysis: The main control unit continuously receives the raw data of the occipital leaf O1 / O2 electrodes transmitted by the NeuroSci system through a 2.4GHz wireless receiving module, extracting a 3-second data window (750 sampling points) every 3 seconds; the data is preprocessed (0.5-30Hz FIR filtering, 50Hz notch filtering), zero-padding to 1024 sampling points, and then an FFT transformation is performed (1024 points, frequency resolution 0.244Hz) to calculate the frequency corresponding to the peak power spectrum; if |-8Hz| < 0.5Hz, the original flavor is selected; if |-10Hz| < 0.5Hz, the strawberry flavor is selected; if |-12Hz| < 0.5Hz, the pineapple flavor is selected.
[0046] 2-2. Flavor Confirmation and Sugar Dispensing: The display unit prompts "You have selected XX flavor" (XX is the corresponding flavor). The main control unit controls the servo motor of the corresponding sugar box square to rotate (gate opening 90°), holds for 2 seconds to dispense 5-8g of sugar, and then resets. If the infrared sensor detects sugar jamming (obstruction for more than 2 seconds), the servo motor reverses for 0.5 seconds to try to clear the problem. If it fails 3 times in a row, it will prompt "Gate jammed with sugar, please clean".
[0047] 2-3. Attention data reception and processing: After the flavor is delivered, the main control unit extracts the FP1 / FP2 electrode data of the forehead through the NeuroSci system dedicated protocol. After the system's built-in 0.1-100Hz filter, it is then filtered twice by the microcontroller (0.5-30Hz FIR low-pass filter, 0.5Hz high-pass filter). The FastICA algorithm is used to remove electrooculogram artifacts (EOG). Every second, the system is divided into segments with a 1-second window length (250 sampling points). The FFT transformation (256 points) is performed to calculate the average power P_α of the α wave (8-13Hz) and the average power P_β of the β wave (13-30Hz). The attention value (range 0-100) is calculated by formula (1). The 3-second moving average (formula (2)) is used to reduce fluctuations.
[0048] 2-4. Threshold Judgment: Judgment is made based on preset multiple thresholds (preheating threshold 30, medium speed threshold 60, high speed threshold 80, low speed threshold 50) to provide a basis for state switching; at the same time, the NeuroSci system status (wireless signal strength, electrode impedance) is monitored. If the signal strength is < -70dBm or the electrode impedance is > 10kΩ, prompts and alarms are triggered.
[0049] 3. Multi-state control process 3-1. Initialization state (INIT): After flavor selection, the system enters this state. If the score is greater than 30 for 3 consecutive seconds, the system switches to the preheating state; otherwise, the system displays the message "Please concentrate (concentration level must be greater than 30)".
[0050] 3-2. Preheating: Controls the cotton candy machine motor to rotate at a high speed of 3000r / min. The display unit updates the 60-second preheating countdown in real time (font 24pt, white). The audio unit plays background audio (800-1000Hz soothing music). When the 0-second preheating time ends, it automatically enters the interactive state.
[0051] 3-3. Interactive State: Enters this state after warm-up, displaying the prompt "Please stay focused (focus level must be >60)"; if the focus level is >60 for 3 consecutive seconds, switch to production state; otherwise, play a 500Hz prompt tone every 5 seconds, keeping the motor stopped. During this period, you can terminate the process by using the "Stop Production" button or voice command and return to the SSVEP waiting state.
[0052] 3-4. Running Status: Based on the dynamic adjustment of the motor's operating status, the upper left corner of the display unit shows "Current Time: XX seconds" in real time (only the motor rotation time is accumulated, with an accuracy of ±0.1 seconds). When the concentration level is >80, the motor rotates at a rate of r / min (range 2500-3000 r / min), the concentration value is displayed in green, and an ascending musical scale is played. When the value is 60≤≤80, the motor rotates at a speed of r / min (range 1500-2500 r / min), and the focus value is displayed in yellow. When the value is 50≤<60, the motor rotates at a speed of r / min (range 500-1500 r / min), and the focus value is displayed in yellow. When the time is <50 seconds, a delay timer is activated: the motor maintains a speed of 500 rpm for ≤5 seconds; the motor stops (timer pauses) when the time is 5 < ≤ 10 seconds; and the timer returns to interactive mode when the time is >10 seconds, prompting "Insufficient focus, please stay focused." During the manufacturing process, if the motor current is greater than 1A (detected by the ACS712 sensor), the casing temperature is greater than 60℃ (detected by the DS18B20 sensor), or the electrode impedance of the NeuroSci system is greater than 10kΩ, the motor will be stopped immediately, triggering an audio alarm and display prompts. Users can click the "Stop Manufacturing" button or say the "Stop Manufacturing" command to terminate the process.
[0053] 3-5. Completed State: After the cumulative effective motor rotation time reaches 300 seconds, the system automatically enters the completed state, controls the motor to stop rotating, the audio module plays a cheering prompt audio (multi-band mixed sound effect, lasting 2 seconds), the display module outputs "Completed, current time: XX seconds", and a "Return to Selection" button is set below (supports voice "Return to Selection" command). After executing the command, it jumps to the SSVEP waiting selection interface; if the user does not give a command, it will automatically return to the SSVEP waiting selection state after 30 seconds.
[0054] 4. User Interaction and Feedback 4-1. Visual Feedback: The display unit updates the SSVEP flavor selection interface in real time (3 flashing blocks: original flavor 8Hz white, strawberry flavor 10Hz red, pineapple flavor 12Hz yellow, frequency error ±0.1Hz), focus value (<60 red, 60-80 yellow, >80 green), current speed status (text description + corresponding GIF animation: fire_high.gif for high speed, fire_medium.gif for medium speed, fire_low.gif for low speed), and cumulative production time.
[0055] 4-2. Audio Feedback: When selecting a flavor in SSVEP, a "beep beep" sound is played (1kHz, 0.5-second interval); when the flavor is confirmed, a 1.2kHz rising tone is played (lasting 0.8 seconds); when warming up begins, a "ding-dong" sound is played (1.5kHz, 0.5-second interval); when the speed increases, a rising tone corresponding to the frequency band is played (low → mid 800-1000Hz, mid → high 1000-1200Hz, lasting 0.5 seconds); when the speed decreases, a falling tone corresponding to the frequency band is played; when production is complete, a cheering sound is played (multi-frequency mixed, lasting 2 seconds); when the NeuroSci system malfunctions (weak signal, high impedance), a rapid 1500Hz "beep beep beep" sound is played (0.3-second interval).
[0056] 4-3. Interactive Operation: Users can intervene in the process through the touch controls on the display module: the "Start" button initiates SSVEP flavor selection, the "Confirm Flavor" button manually confirms the selection result, the "Stop Making" button terminates the current making process and returns to the interactive state, the "Return to Selection" button jumps to the SSVEP selection interface, and the "Exit" button closes the system; all touch operations support corresponding voice commands ("Start Selection", "Confirm Flavor", "Stop Making", "Return to Selection"), the command recognition response time is <1 second, and the recognition accuracy is ≥95% after training.
[0057] 5. Security and Log Management 5-1. Safety Protection: The motor control unit is equipped with an ACS712 current sensor. When the motor current is detected to be greater than 1A, the motor power supply is immediately cut off. The casing is equipped with a DS18B20 temperature sensor. When the temperature is greater than 60℃, an audio alarm (1500Hz beep) is triggered and the message "Temperature too high, please cool down" is displayed. When the NeuroSci system signal is lost (wireless disconnection for more than 3 seconds) or the electrode impedance is greater than 10kΩ, production is paused and the message "Abnormal EEG signal, please check the equipment" is displayed. The power module is equipped with an overload protection circuit breaker. When the voltage is less than 180V or greater than 240V, the power supply is automatically cut off. When the infrared sensor of the sugar flavor control submodule detects sugar stuck for more than 2 seconds, the servo motor automatically reverses to troubleshoot. After 3 consecutive failures, manual cleaning is prompted.
[0058] As attached Figure 1 As shown, the hardware connection method of the brain-controlled cotton candy machine control system based on SSVEP and attention acquisition is as follows: 1. The 2.4GHz wireless receiver module of the NeuroSci wireless EEG acquisition system is connected to the SPI2 pin (SCK-PB13, MISO-PB14, MOSI-PB15, CS-PB12) of the STM32F407ZGT6 microcontroller via the SPI interface. When wearing the device, ensure that the FP1 / FP2 and O1 / O2 electrodes are in close contact with the skin, and that the Nz reference electrode and the Fz ground electrode are in good contact.
[0059] 2. The cotton candy machine motor is connected to the microcontroller's GPIOA0 pin via an SRD-05VDC-SL-C normally open electromagnetic relay. The relay coil is connected in series with a 220Ω current-limiting resistor, and the negative terminal of the coil is connected to the microcontroller's GND pin. The relay's common terminal is connected to the 220V AC power supply live wire, and the normally open terminal is connected to the cotton candy machine motor's power input terminal. The motor's output shaft is rigidly connected to the rotating head via a coupling, and is also connected to the skewer container's synchronous pulley B (1:1 gear ratio) via synchronous pulley A and a polyurethane synchronous belt (5mm pitch). An A3144 Hall speed sensor is installed at the end of the container's rotating shaft, and its signal terminal is connected to the microcontroller's GPIOA6 pin.
[0060] 3. The three SG90 servo motors of the sugar flavor control submodule are connected to the TIM2_CH1 (PA0), TIM3_CH1 (PA6), and TIM4_CH1 (PB6) pins of the microcontroller, respectively. The signal terminal of the E18-D80NK infrared sensor is connected to the GPIOB0 pin. The aluminum alloy frame is fixed to the top of the cotton candy machine body with bolts, and the sugar box grid corresponds to the sugar filling port position of the cotton candy machine.
[0061] 4. The display module (7-inch SPI touch screen) is connected to the microcontroller via the SPI1 interface (SCK-PA5, MISO-PA6, MOSI-PA7, CS-PA4), and the touch function pin is connected to GPIOA1. Touch power is obtained from the microcontroller via USB cable. The audio module (VS1053 chip + speaker) is connected to the microcontroller via the I2C interface (SDA-PB7, SCL-PB6). The voice module (LD3320 chip) is connected to the microcontroller via the UART2 interface (TX-PA2, RX-PA3).
[0062] 5. The 220V to 5V / 3A DC power output of the power module is connected to the microcontroller's Type-C power port, the display module's USB power port, and the voice module's power port; the 220V to 5V / 2A DC power supply is connected separately to the NeuroSci system power interface; the 220V to 12V / 1A DC power supply is connected to the servo motor power supply; the 220V AC power supply is connected to the cotton candy machine motor, the relay's common terminal, and the overload protection circuit breaker. All lines are wired separately, and the distance between the motor power supply line and the NeuroSci system power supply line is ≥10cm to reduce electromagnetic interference.
[0063] The software implementation steps of this invention are as follows: 1. Environment Configuration: In the STM32F407ZGT6 microcontroller development environment (KeilMDK5), load the SPI screen driver library, speech recognition library (LD3320 dedicated library), wireless communication library (adapted to NeuroSci system 2.4GHz transmission protocol), and FFT algorithm library; install the required dependent components, and configure the UART (baud rate 57600), SPI (speed 1Mbps), and PWM (frequency 50Hz) interface parameters; store the GIF animation files ("fire_low.gif", "fire_medium.gif", "fire_high.gif") and audio files (SSVEP prompt tone, cheer tone, background sound) to the specified directory of the microcontroller's Flash memory; and store the speech templates in Flash memory after collecting them through the "speech training mode" (3 samples per instruction, 2 seconds each time).
[0064] 2. Program Execution: The microcontroller is started, the system automatically loads the main program, initializes each module (UART, SPI, GPIO, PWM), and detects the peripheral connection status; the startup interface is displayed, including the system name, operation instructions, and a "Start" button; after the user triggers the "Start" operation, the program jumps to the self-test module and performs a full-process self-test; after the self-test passes, the program enters the SSVEP selection interface and starts the EEG data acquisition and analysis thread.
[0065] 3. Operating Procedures: 3-1. After the user wears the NeuroSci system electrodes and completes impedance calibration, click the "Start" button or say the "Start Selection" command. The program will jump to the SSVEP flavor selection interface and start O1 / O2 electrode data acquisition and FFT analysis. 3-2. After parsing the flavor selection result, control the servo motor to add sugar, and then enter the initialization state; when the user concentrates and keeps the value >30 for 3 consecutive seconds, the system enters the preheating state (60-second countdown), and the motor rotates at 3000 r / min; 3-3. After preheating, if the user maintains a concentration level > 60 for 3 consecutive seconds, the system will enter the production state. The system will dynamically adjust the motor speed and update the concentration display and cumulative time in real time. During the production process, the user can intervene in the process through touch or voice commands. 3-4. Once the cumulative motor rotation time reaches 300 seconds, or the user triggers "Stop Making", the system enters the completion state, plays a cheering sound, and displays the completion information; if the user clicks "Return to Select Flavor" or waits 30 seconds, the system returns to the SSVEP selection interface, ready for the next production; 3-5. Throughout the process, the program records the operation log in real time and triggers the security protection mechanism when an anomaly is detected to ensure the safety of the device and the user.
[0066] The following provides three specific implementation scenarios based on key extreme parameters during system operation (focus threshold, time critical point, and rotation speed extreme value): Example 1: The process of making SSVEP with sustained focus above the high-speed threshold (>80) and selecting strawberry flavor. 1. Initialization and Flavor Selection Stage: The user wears the NeuroSci system electrodes, and after impedance calibration, clicks "Start". The system self-test passes and enters the SSVEP selection interface. The user stares at the red 10Hz flashing block (strawberry flavor) for 3 seconds. The program analyzes the O1 / O2 electrode data, and the power spectrum peak corresponds to 10Hz, indicating that strawberry flavor has been selected. The system displays "You have selected strawberry flavor", and the servo motor drives the gate to open for 2 seconds to add strawberry flavored sugar. Then, the system enters the initialization state.
[0067] 2. Warm-up phase: User focus increases rapidly and remains stable at 85 for 3 consecutive seconds (> warm-up threshold 30), at which point the system enters warm-up mode; the motor rotates at 3000r / min (maximum speed), the screen displays a 60-second countdown, and plays a "ding-dong" notification sound and background sound; after 60 seconds of warm-up, the system automatically enters interactive mode.
[0068] 3. Interaction and Production Stage: The user's focus remains at 90 (> medium speed threshold 60), and the system enters production mode after 3 consecutive seconds; because =90>80 (high speed threshold), the motor rotates according to the formula r / min (high speed range), the focus value on the screen is displayed in green, and a rising scale of 1000-1200Hz is played synchronously; the user's focus is always maintained at 85-95, the motor continues to run at high speed, and the cumulative time steadily increases.
[0069] 4. Completion Stage: The cumulative motor rotation time is 262 seconds. The system automatically controls the motor to stop rotating, the audio module plays the cheering sound "cheer.wav" (multi-band mixed sound effect, lasting 2 seconds), and the display module outputs "Completed, current time: 2602 seconds"; at the same time, the log module automatically records the data for this operation, including "Flavor selected: Strawberry", "Maximum focus: 95", "Average speed: 2780r / min", "NeuroSci system signal strength average: -45dBm", and "No fault information"; after 30 seconds, the system automatically returns to the SSVEP selection interface, waiting for the next operation.
[0070] Example 2: The production process where focus fluctuates at a critical value and SSVEP selects the original flavor. 1. Initialization and Flavor Selection Stage: The user wears the NeuroSci system electrodes, applies electrode paste, and impedance detection shows that FP1 / FP2 / O1 / O2 are all 4.5kΩ (<5kΩ); click the "Start" button to enter the SSVEP selection interface, stare at the white 8Hz flashing block (original flavor), after 3 seconds the program analyzes the O1 / O2 electrode data, the power spectrum peak corresponds to 8Hz, and determines that the original flavor is selected; the servo motor drives the original flavor sugar box gate to open for 2 seconds, 6g of sugar is added (the infrared sensor does not detect sugar jamming), and then enters the initialization state.
[0071] 2. Warm-up phase: User focus slowly increases, stabilizing at 30 for 3 consecutive seconds (just reaching the warm-up threshold), and the system enters the warm-up state; the motor rotates at 3000r / min, the screen displays a 60-second countdown, and the "dingdong.wav" prompt sound and background sound play; after 60 seconds, the warm-up is complete, and the system enters the interactive state.
[0072] 3. Interaction and Production Stage: 3-1. In interactive mode, the user's focus level fluctuates between 58 and 62. When it reaches 60 (the critical value of medium speed) for 3 consecutive seconds, the system enters the production mode. Initially, the focus level is 60, and the motor rotates according to the formula r / min (lower limit of the medium speed range). The focus level value is displayed in yellow. After 3-2.10 seconds, the user's focus level drops to 50 (low-speed threshold critical value), the motor speed switches to r / min (low-speed range extreme value), the focus level value remains yellow, and a descending 800-600Hz tone is played; After 3-3.5 seconds, the user's focus level rises back to 60, the motor speed switches back to 1500r / min, and an ascending musical scale is played simultaneously; subsequently, the focus level briefly rises to 80 (the high-speed threshold), and the motor speed is calculated to be 2500r / min (the upper limit of the medium speed range) according to the formula. Since it does not exceed 80, the focus level value remains yellow. 3-4. When a user becomes distracted and their focus level drops to 49 (<50), the system starts a delayed timer: the motor maintains a speed of 500 rpm for the first 5 seconds; the motor stops rotating from the 6th to the 10th second (the cumulative time is paused at 120 seconds); at the 10th second, the focus level is still 48, the system returns to interactive mode, displays "Insufficient focus, please stay focused", and plays a 500Hz prompt tone.
[0073] 4. Completion Stage: The user refocuses their attention, and the concentration level increases to 65 (for 3 consecutive seconds), at which point the system re-enters the production state; subsequently, the concentration level is maintained between 60 and 75, and the motor speed fluctuates between 1500 and 2000 r / min; when the cumulative motor rotation time reaches 300 seconds, the system prompts that the production is complete, plays a cheering sound, and displays the production time. Example 3: Production process where focus level is below the low-speed threshold and timeout occurs, and SSVEP selects pineapple flavor. 1. Initialization and Flavor Selection Stage: The user wears the NeuroSci system electrodes. Initial impedance detection shows that the O1 electrode impedance is 11kΩ (red indicator). After reapplying electrode paste, it drops to 4.8kΩ. The user says the voice command "Start Selection". After the system responds, it enters the SSVEP flavor selection interface. The user stares at the yellow 12Hz flashing block (pineapple flavor). After 3 seconds, the program analyzes the data and determines that the pineapple flavor is selected. The servo motor dispenses pineapple-flavored sugar. Then, the user enters the initialization state.
[0074] 2. Warm-up phase: The user's focus level is consistently between 25-28 (<30), and the screen continuously displays "Please concentrate (focus level must be >30)", while the system remains in the initial state. After 2 minutes, the user adjusts their focus level, and the focus level reaches 35 (>30) for 3 consecutive seconds, at which point the system enters the warm-up phase. The motor rotates at 3000r / min, and after a 60-second countdown, the system enters the interactive phase.
[0075] 3. Interaction and Production Stage: 3-1. In interactive mode, when the user's focus reaches 62 (for 3 consecutive seconds), the system enters the production mode; initial value = 62, motor speed is r / min, and focus is displayed in yellow. 3-2. After 50 seconds of preparation, the user becomes distracted and their focus drops to 40 (<50). The system then starts a delayed timer: at the 3rd second, the focus remains at 40, and the motor maintains 800 r / min (low speed range); at the 7th second, the focus briefly rises to 52, the countdown ends, and the motor speed switches to r / min. 3-3. If the user becomes distracted again and their focus level drops to 45 for 12 seconds (>10-second threshold), the system will automatically return to interactive mode, the motor will stop rotating (the cumulative pause time is 143 seconds), and the screen will display "Insufficient focus, please stay focused." 3-4. The user attempts to increase focus, but fails to reach 60 multiple times. Finally, the user clicks the "Stop Making" button. The system saves the current log ("Selected Flavor: Pineapple", "Cumulative Time: 80 seconds", "Final Speed: 0 r / min", "Focus Timeout Count: 1") and returns to the SSVEP selection interface.
[0076] As can be seen from the above embodiments, this system can accurately identify the flavor selection intention based on the SSVEP signal, dynamically adjust the cotton candy machine's operating status by combining the focus extreme value and time critical point, and monitor the key parameters of the NeuroSci system (signal strength, electrode impedance) in real time to adapt to different users' operating scenarios and focus change patterns, ensuring interactive stability and cotton candy making effect.
[0077] This invention overcomes the limitations of traditional cotton candy machines by integrating SSVEP flavor selection and dynamic attention control with the high-precision signal processing capabilities of the professional NeuroSci wireless EEG acquisition system with 16 channels. Simultaneously, through multimodal interactive feedback and multiple safety protection mechanisms, it lowers the operational threshold, increases the interactive experience of the device, and improves system stability and safety. It can be widely applied in amusement park parent-child interactive areas, science museum brain science experience exhibitions, youth attention training institutions, and barrier-free consumption scenarios, possessing high commercial value and promising prospects for promotion.
Claims
1. A brain-controlled cotton candy machine control method based on focus and SSVEP, characterized in that, First, set up the hardware platform: The hardware platform consists of an EEG signal acquisition module, a main control module, an execution module, an audio module, a display module, and a power supply module. The EEG signal acquisition module consists of two parts: an SSVEP signal acquisition device and a focus signal acquisition device. The SSVEP signal acquisition device consists of an occipital lobe signal acquisition electrode, a reference electrode, a signal processing unit, and a data transmission unit; the focus signal acquisition device consists of a forehead signal acquisition electrode, a reference electrode, a signal processing unit, and a data transmission unit. The signal processing unit has a built-in 80dB gain preamplifier, a 0.1-100Hz bandpass filter, and a 50 / 60Hz dual-frequency notch filter to filter and amplify the original signal. The data transmission unit uses a 2.4GHz wireless module; The main control module includes a main control device, which is equipped with a microcontroller, memory, display interface, data interaction interface, and control signal output interface. The microcontroller establishes communication with the attention acquisition module through the data transmission adapter unit, and connects to the execution module through the control signal output interface, which is responsible for EEG data parsing, control logic operation and peripheral device driving. The execution module includes the main body of the cotton candy machine, the motor control unit, and the automatic feeding box module; The cotton candy machine uses an AC motor that supports stepless speed regulation within a preset range. The motor output shaft is connected to the cotton candy machine rotating head through a power transmission structure. The motor control unit consists of a switch control component, a drive circuit, and a protection circuit. The switch control component is connected to the main control equipment through the control signal output interface. The input end is connected to the AC power supply, and the output end is connected to the power input end of the cotton candy machine motor to form a control loop. With the help of PWM signal, the motor can start and stop and stepless speed regulation are realized. The automatic feeding box module includes an aluminum alloy mounting frame bolted to the top of the cotton candy machine, a feeding box, and three miniature servo motors; the output shafts of the servo motors are connected to the bottom gate of the grid; an infrared sensor is installed below the feeding box. The display module is a display interaction device. The display interaction device has image display and touch operation functions. It is connected to the main control module through the display interface and fixed in the preset position of the cotton candy machine. It is used to display focus data, equipment operating status, feedback information and operation controls. The audio module uses an audio decoding chip as the core of the audio playback unit, and is equipped with a speaker adapted to the decoding chip to realize audio output. The audio files corresponding to each operation prompt tone are pre-stored in the memory of the main control module. The audio module is connected to the main control module through a specified interface to receive control commands. The power module includes a DC power supply for powering electronic components and an AC power supply for powering the cotton candy machine motor. The control method is as follows: (1) System initialization: Close the main power module switch to start each module; The main control module performs self-tests and parameter calibrations on each module. The self-test covers the electrode connection status of the attention acquisition module, the motor operation status of the execution module, the function of the servo motor and infrared sensor of the automatic feeding box, the touch function of the display module, and the playback function of the audio module. The calibration includes adjusting the signal gain of the attention acquisition module, and after adjustment, the amplitude of the output EEG data is within the preset range. The main control module is adapted to communicate with each module, and the data interaction delay after adaptation does not exceed 100ms; the execution module presets motor speed control parameters, establishes a mapping relationship between pulse width modulation duty cycle and speed, and the accuracy error does not exceed 2%; The automatic feeding box is initialized by controlling the servo motor to drive the gate to open and close once, verifying the gate action and the infrared sensor detection function. (2) EEG signal acquisition: The EEG signal acquisition module acquires the user's EEG signals in real time through the EEG cap acquisition electrodes. The reference electrode provides a reference potential. The signal processing unit filters and amplifies the raw signal for preprocessing. After preprocessing, the data is sent to the main control module through the data transmission unit. (3) Analysis of EEG signals: After receiving the EEG data, the main control module sequentially performs filtering, 50 / 60Hz dual-frequency notch filtering, and FastICA algorithm to remove EEG artifacts, extracting two types of core features: Focus feature extraction: The EEG data collected by the frontal electrodes were processed in segments with a data window length of 1 second. The amount of data in each segment met the computational requirements. After segmentation, the power ratio of alpha waves (8-13Hz) and beta waves (13-30Hz) was calculated by FFT transformation. The focus value in the range of 0-100 was obtained by fitting the formula, and then the accurate focus value was obtained by 3-second moving average processing. SSVEP Feature Extraction: When entering the flavor selection stage, the main control module controls the display module to output 3 visual flashing blocks, triggering the EEG signal acquisition module to perform SSVEP feature extraction, collecting EEG data of the corresponding area of the occipital lobe for 3 seconds and the amount of data meets the calculation requirements. After acquisition, the data is processed by filtering, notch filtering and FFT transformation. The frequency resolution after transformation meets the recognition requirements. Finally, the selected flavor is identified by the set visual flashing frequency, and the flavor selection operation is completed. (4) SSVEP Flavor Selection and User Interaction: The display module shows three visual flashing blocks corresponding to different flavors. The color and frequency of each flashing block meet the requirements for steady-state visual evoked potential recognition. Users trigger selections via touch display module controls or voice commands; The main control module determines the flavor selected by the user through the steady-state visual evoked potential characteristics analyzed in step (3). If the FFT peak frequency deviates from the frequency of a certain scintillation block less than the preset threshold, the corresponding flavor is determined and a control signal is sent to the execution module. The motor control unit drives the sugar dispensing component to open the gate and dispense the corresponding weight of flavor sugar. Simultaneously, the audio module plays a flavor confirmation prompt, and the display module updates the current flavor information; (5) Motor speed control based on focus: Based on the real-time focus parameters obtained in step (3), the main control module sends a pulse width modulation speed control signal to the execution module through the control signal output interface to dynamically adjust the motor speed of the cotton candy machine: When the focus value is greater than 80, a high duty cycle pulse width modulation signal is output to control the motor speed to be in the range of 2500-3000 r / min. The display module displays the focus value in green font, and the audio module plays an ascending scale prompt. When the focus value is in the range of 60-80, the output duty cycle pulse width modulation signal controls the motor speed to be in the range of 1500-2500 r / min, and the display module displays the focus value in yellow font. When the focus value is in the range of 50-60, a low duty cycle pulse width modulation signal is output to control the motor speed to be in the range of 500-1500 r / min, and the focus value is displayed in yellow font on the display module. When the focus value is less than 50, the lowest duty cycle pulse width modulation signal is output first. This signal corresponds to a rotation speed of 500 r / min and runs for no more than 5 seconds. If the focus value is still less than 50 after 5 seconds, a stop signal is sent. The stop signal triggers the motor to stop and the timer to pause. The display module indicates that the focus is insufficient. (6) System status monitoring and feedback: The main control module monitors the operating status of each module in real time and outputs multimodal feedback through the display module and audio module: EEG signal acquisition module monitoring: The impedance values of the acquisition electrode and the reference electrode are read every 5 seconds. If the impedance is greater than 10kΩ, the display module prompts the electrodes to be reattached and the process is paused. If the impedance is greater than 20kΩ, the acquisition is stopped and the audio module plays a rapid alarm sound. Execution module monitoring: The motor current is read in real time. If the current exceeds the overcurrent threshold, the protection circuit of the motor control unit is triggered to cut off the power, and the display module prompts that the motor is overloaded. The motor speed is monitored by a speed sensor. If the actual speed deviates from the target speed by more than 5%, the main control module fine-tunes the pulse width modulation signal. Power module monitoring: The system collects DC and AC power supply voltages in real time. If the voltage exceeds the preset range, the main control switch triggers overload protection, and the display module indicates a power supply abnormality. Automatic feeder monitoring: The infrared sensor continuously monitors the gate status. If the gate fails to clear the obstruction three times in a row, the display module will prompt "Gate jammed, please clear", and the audio module will play a rapid alarm sound. (7) Completion and Data Saving: When the preset production time is met or the user touches the stop production button, the preset production time can be adjusted through the display module control, and the main control module sends a stop signal to stop the execution module motor. The audio module plays a completion notification sound, and the display module shows that the production was successful. At the same time, the main control module saves the production log. The log uses a common format and includes timestamps, user-selected flavors, attention change curves, motor speed curves, and fault records of each module. The log data can be exported through an extended interface, and the raw EEG data from the attention acquisition module can also be exported. The raw EEG data uses a common format.
2. The brain-controlled cotton candy machine control method based on focus and SSVEP according to claim 1, characterized in that: The signal acquisition electrodes of the EEG signal acquisition module are Ag / AgCl wet electrodes, following the 10-20 international electrode system distribution. The frontal electrodes FP1 and FP2 are used to acquire attention-related signals, the occipital electrodes O1 and O2 are used to acquire SSVEP signals, the reference electrode Nz is fixed at the root of the nose, and the ground electrode Fz is fixed at the midline of the forehead to ensure the stability and accuracy of signal acquisition.
3. The brain-controlled cotton candy machine control method based on focus and SSVEP according to claim 2, characterized in that: The aluminum alloy mounting frame of the automatic feeding box module is adapted to the size of the cotton candy machine. The square outlet of the feeding box is precisely aligned with the sugar adding port of the cotton candy machine to ensure that no sugar is spilled. The servo motor is driven by a PWM signal, and the rotation angle control accuracy is ±1°. The feeding amount of 5-8g can be achieved by adjusting the parameters of the main control module.
4. The brain-controlled cotton candy machine control method based on focus and SSVEP according to claim 3, characterized in that: The SSVEP flavor selection area flashing block of the display module adopts a three-color design of white, red and yellow, and the flashing frequency has been optimized by SSVEP recognition at 8Hz, 10Hz and 12Hz to ensure that different users can clearly identify it.
5. The brain-controlled cotton candy machine control method based on focus and SSVEP according to claim 4, characterized in that: The audio playback unit of the audio module uses a decoding chip, model VS1053, which supports MP3 / WAV audio playback and has an output power of not less than 2W. The status prompt audio includes a fault alarm tone and a concentration decrease prompt tone. The fault alarm tone is a continuous single tone at a specific frequency, and the concentration decrease prompt tone is a decreasing scale within a specific frequency range and lasts for 1 second. Each audio file is pre-stored in the main control module's memory, and specific prompt sounds can be enabled or disabled via the display module controls.
6. The brain-controlled cotton candy machine control method based on focus and SSVEP according to claim 5, characterized in that: The main control module uses an STM32F407ZGT6 microcontroller with 1MB Flash and 192KB RAM. The data interaction interface includes two UART interfaces and one SPI interface, and the control signal output interface includes four PWM interfaces.
7. The brain-controlled cotton candy machine control method based on focus and SSVEP according to claim 6, characterized in that... The fault handling mechanism in step (6) also includes: When the focus acquisition module loses communication with the main control module for more than 3 seconds, the main control module saves the current production progress, which includes the production time, current flavor, and cumulative rotation speed. The saved data is not lost when power is off, and the display module prompts the user to check the connection of the acquisition device. The infrared sensor of the execution module is model E18-D80NK, the preset occlusion duration for the candy monitoring is 2 seconds, and the preset motor reverse rotation duration is 0.5 seconds.
8. The brain-controlled cotton candy machine control method based on focus and SSVEP according to claim 7, characterized in that... In the parameter calibration of step (1), the preset speed regulation parameters of the motor of the execution module need to be verified by actual speed test. Under different pulse width modulation duty cycles, the actual speed is collected by the speed sensor, the mapping relationship is corrected, and the stepless speed regulation accuracy error is ensured to be no more than 2%. The signal gain adjustment of the attention acquisition module needs to be calibrated using a standard signal source. The standard signal source outputs a 0.5-50μV analog EEG signal, and the error between the acquired data and the standard signal after calibration should not exceed 5%. The speed sensor is a Hall effect speed sensor, and its measurement accuracy error does not exceed 1%.