Menu

Electric Motor Control Program

Anobium
2022-11-11
2022-11-14
  • Anobium

    Anobium - 2022-11-11

    I was asked to create a diorama of a Mosquito model aircraft with powered engines.

    The two electric engines are mounted in the Mosquito model aircraft engine cowlings. The motors are 8mm diameter AliExpress motors. The are encased in Sugru resin to reduce noise but mainly to hold them in position. The circuit is simple - the motors are controlled from the PIC via a BD681 with the base connected to via a 1k resistor - all very simple.

    The control program is shown below. This is a user story - the story of what the engines should do. They can define the engine story and then recompile the source (and program the chip) to play thru the user story.

    This uses the concept designed by Chris Roper - it is very cool!

    User Story

    This story starts each engine. Left then Right engine. The Left engine is idling when the Right engine is started. When both engines are idling the control is for both engines. Then, after a period of full power the engines are returned to idle then stopped. This is repeated forever. There is the RANDOM function to give differences to each user story execution.

    The priming event simulates the misfiring of the engine, see https://youtu.be/YFQwwH-3HZI

    The end goal is a small control panel that interacts with the user.

    :=)

    User Story

    // Mosquito Engine Start Process
    //
    
        // Select Left Engine
            EngineSelected = LEFTENGINE
    
            // Start engine
            EngineOn
    
            // PrimeEngine ( events, delayseconds ) - a random number of priming events  
            EnginePriming Scale ( Random,0,255,50,250), 2
    
            If Random > 127 Then
    
                    // EngineOperationsStalled ( seconds )  - wait a random number of seconds between 3 and 10
                    EngineOperationsStalled Scale( Random,0,255,3, 10 )
    
                    // PrimeEngine ( events, delayseconds ) - a random number of priming events  
                    EnginePriming Scale ( Random,0,255,50,250), 2
            End If
    
            // EngineRunning ( seconds ) - this is the lowest RPM/power level, run of 3 seconds
            EngineRunning 3
    
        // Select Right Engine
            EngineSelected = RIGHTENGINE
    
            // Start engine
            EngineOn
    
            // PrimeEngine ( events, delayseconds )
            EnginePriming 10, 1
    
            // EngineOperationsStalled ( seconds )
            EngineOperationsStalled Scale( Random,0,255,1,7)
    
            // EnginePower ( enginepower [ 0 to 100 ], seconds )
            EnginePower 10, 5
    
        //  Both engines are now running
            EngineSelected = BOTHENGINES
    
            // EnginePower ( enginepower [ 0 to 100 ], seconds )
                EnginePower 50, 5
    
            // EnginePower ( enginepower [ 0 to 100 ], seconds )
                EnginePower 100, 5
    
            // EngineRunning ( seconds ) - tick over for 15 s
                EngineRunning 15
    
        // Cease Engines
                 EngineOff
    

    How does this work ?

    The GCode program does all the real work. It sets up the chip, PPS etc. The user story is #inserted into the GCode and then the user story calls the methods defined in the GCODE.

    The GCode uses two different type of PWM, and a few macros with the user story using constants and variables defined in the GCODE.

     

    Last edit: Anobium 2022-11-11
  • Anobium

    Anobium - 2022-11-11

    The final user story.

    // Mosquito Engine Start Process
    //
    
    Do
        // Select Left Engine
            EngineSelected = LEFTENGINE
    
            // Start engine
            EngineOn
    
            // PrimeEngine ( events, delayseconds ) - a random number of priming events  
            EnginePriming Scale ( Random,0,255,50,250), 2
    
            If Random > 127 Then
    
                    // EngineOperationsStalled ( seconds )  - wait a random number of seconds between 3 and 10
                    EngineOperationsStalled Scale( Random,0,255,3, 10 )
    
                    // PrimeEngine ( events, delayseconds ) - a random number of priming events  
                    EnginePriming Scale ( Random,0,255,50,250), 2
            End If
    
            // EngineRunning ( seconds ) - this is the lowest RPM/power level, run of 3 seconds
            EngineRunning 3
    
        // Select Right Engine
            EngineSelected = RIGHTENGINE
    
            // Start engine
            EngineOn
    
            // PrimeEngine ( events, delayseconds )
            EnginePriming 10, 1
    
            // EngineOperationsStalled ( seconds )
            EngineOperationsStalled Scale( Random,0,255,1,7)
    
            // EnginePower ( enginepower [ 0 to 100 ], seconds )
            EnginePower 5, 5
    
        //  Both engines are now running
            EngineSelected = BOTHENGINES
    
            // EnginePower ( enginepower [ 0 to 100 ], seconds )
                For EngineSetting = 5 to 100 Step 5
                    EnginePower EngineSetting, 0
                    wait 500 ms
                Next
    
            // EnginePower ( enginepower [ 0 to 100 ], seconds )
                EnginePower 100, 15
    
            // EngineRunning ( seconds ) - tick over for 15 s
                EngineRunning 15
    
        // Cease Engines
                EngineShutDown
                wait 5 s
    
    
    Loop
    
     
  • Anobium

    Anobium - 2022-11-14

    Completed project. This version exposes the constants in the user story.

    The user story is:
    - Start one of the engine, then the other. This is random. It could start the left or right engine.
    - When trying to start the engine try up to five times to start the engine. When trying to start the engine use the starting technique.
    - When an engine starts the power is set to minimum.
    - Then, start the other engine using the same sequence.

    • With both engines operational - increase power to 80% and run for the specified operational time ( in seconds )
    • During the specified operational time run the engines at 80%
    • Every second of the specified operational time check the engines are operational, and, randomly (a 1 on 255 chance) fail an engine. If an engine fails then feather the engine, and, increase power to the remaining engine to 100%

    • Then, return the engine(s) to idle

    • And, finally, shut down the engines.

    An operation run looks this - this is from the serial terminal. The comments are added

    Normal Operations //start of user story
    Starting Right Engine
    Right Engine Failed to start
    Starting Right Engine
    Right Engine set to idle power // a good start
    Normal Operations
    Starting Left Engine
    Left Engine Failed to start
    Starting Left Engine
    Left Engine Failed to start
    Starting Left Engine
    Left Engine set to idle power // a good start, so, both engines are running
    Both Engines 5% // power up to 80%
    Both Engines 10%
    Both Engines 15%
    Both Engines 20%
    Both Engines 25%
    Both Engines 30%
    Both Engines 35%
    Both Engines 40%
    Both Engines 45%
    Both Engines 50%
    Both Engines 55%
    Both Engines 60%
    Both Engines 65%
    Both Engines 70%
    Both Engines 75%
    Both Engines 80% // power80%
    Engine status: Failure // failure
    Left Engine failure
    Starting Left Engine // try to restart engine!
    Left Engine failure // still failed, so, feather the engine
    Right Engine 85% // increase power to compensate
    Right Engine 88%
    Right Engine 91%
    Right Engine 94%
    Right Engine 97%
    Right Engine 100% // complete operational time using 100%
    Right Engine set to idle power // start shutdown
    Shutting down Right Engine
    Left Engine set of OFF
    Right Engine set of OFF

    next run....

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.