Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

ESC - Code Problem


  • Please log in to reply
8 replies to this topic

#1 Adamos

Adamos

    New Member

  • Members
  • Pip
  • 9 posts

Posted 26 August 2011 - 09:27 AM

Hello, i am having problems with controlling my ESC. I dont even hear the beep!!!!!

here is the code

namespace lets_start
{
    public class Program
    {
        public static void Main()
        {           
             
            while (true)
            {
                motorOnThenOff();
              //  motorTest();
                
            }  
        }

        static void motorOnThenOff()
        {
            OutputPort motor = new OutputPort(Pins.GPIO_PIN_D5, false);

            int onTime = 2500;  //the number of milliseconds for the motor to turn on for
            int offTime = 1000; //the number of milliseconds for the motor to turn off for

            motor.Write(true);       // turns the motor On
            Thread.Sleep(onTime);    // waits for onTime milliseconds
          //  motor.Write(false);      // turns the motor Off
          //  Thread.Sleep(offTime);   // waits for offTime milliseconds

            motor.Dispose();
        }

        static void motorTest()
        {
        
            PWM Motor = new PWM(Pins.GPIO_PIN_D5);
            
            while (true)
                
                Motor.SetDutyCycle(100);
                Thread.Sleep(500);
                Motor.SetDutyCycle(50);
                
                //Thread.Sleep(800);
                //Motor.SetDutyCycle(0);
            } 
            
          

        }

    }

Edited by Stefan, 26 August 2011 - 09:31 AM.
Added [code] tags


#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 August 2011 - 09:31 AM

Hi Adamos and welcome to the Netduino community! Another member posted a somehow related question recently and found a solution, perhaps it'll help you? http://forums.netdui...oller-with-pwm/
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Adamos

Adamos

    New Member

  • Members
  • Pip
  • 9 posts

Posted 26 August 2011 - 09:44 AM

Hi Adamos and welcome to the Netduino community!

Another member posted a somehow related question recently and found a solution, perhaps it'll help you?
http://forums.netdui...oller-with-pwm/


Thanks!! Well i have seen that code but i still got problems :/ using an arduino of a friend of me i hear the beeps!! but using the netduino nothing. Of course am a beginer!!

#4 Freeman4gu

Freeman4gu

    Member

  • Members
  • PipPip
  • 17 posts

Posted 26 August 2011 - 12:52 PM

Thanks!! Well i have seen that code but i still got problems :/ using an arduino of a friend of me i hear the beeps!! but using the netduino nothing. Of course am a beginer!!



Hey the other tread is from me ;) in my case you had first to set the throttle of the esc to 100% and then connect the esc and motor (esc and motor should not get any power input before), then set throttle to 0%. After that your esc should sound correct and you can control your motor ;) then set throtte to 20% to begin ^^

Don't know which motor you have, but start only with 20%, else this can happen:

Attached File  WP_000076.jpg   38.58KB   23 downloads

public static void Main()
        {
            OutputPort esc = new OutputPort(Pins.GPIO_PIN_D0, false);
            OutputPort relais = new OutputPort(Pins.GPIO_PIN_D1, true);
            InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptNone);
            SpeedController xl5 = new SpeedController(Pins.GPIO_PIN_D5, new TRAXXAS_XL5());

            #region initiate esc & motor
            // set max throttle
            Debug.Print("waiting");
            while (button.Read())
            {
                if (xl5.Throttle != 100) xl5.Throttle = 100;
            }

            // activate esc
            Debug.Print("activate esc");
            esc.Write(true);
            Thread.Sleep(500);

            // activate motor
            Debug.Print("activate motor");
            relais.Write(false);

            // set min throttle
            Debug.Print("set throttle min");
            if (xl5.Throttle != 0) xl5.Throttle = 0;
            Thread.Sleep(5000);
            #endregion

            bool end = false;
            bool oldspeedup = button.Read();
            DateTime dt = DateTime.Now;
            int i = 1;
            while (true)
            {
                //if (!buttonInput.Read()) break;
                bool speedup = !button.Read();
                if (oldspeedup != speedup && speedup & end) break;
                if (speedup)
                {
                    Debug.Print("speedup");
                    end = true;
                }
                if (speedup && xl5.Throttle != 20 + (i * 2)) xl5.Throttle = 20 + (i * 2);
                if (!speedup && xl5.Throttle != 0) xl5.Throttle = 0;
                oldspeedup = speedup;

                if (DateTime.Now > dt)
                {
                    dt = DateTime.Now.AddSeconds(3);
                    i++;
                }
            }


            Debug.Print("deactivate relais");
            esc.Write(false);
            Thread.Sleep(500);
            relais.Write(true);
            xl5.Throttle = 0;
        }


#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 August 2011 - 01:04 PM

Don't know which motor you have, but start only with 20%, else this can happen:

Attached File  WP_000076.jpg   38.58KB   23 downloads

Oh dear! That did hurt I suppose? :o
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 Adamos

Adamos

    New Member

  • Members
  • Pip
  • 9 posts

Posted 26 August 2011 - 02:54 PM

Oh dear! That did hurt I suppose? :o


Thanks guys for ur help i will try it out i will let you now about my progress!!!!

Well i am always be carefull with this things coz am using a jet motor!!!! :P (i saw similar motor working)

#7 Adamos

Adamos

    New Member

  • Members
  • Pip
  • 9 posts

Posted 26 August 2011 - 03:05 PM


           **** SpeedController xl5 = new SpeedController(Pins.GPIO_PIN_D5, new TRAXXAS_XL5());


Well my ESC in not a TRAXXAS one. I have seen similar code and i thing so that need a another one class in order to instansiate
SpeedController() .

#8 Freeman4gu

Freeman4gu

    Member

  • Members
  • PipPip
  • 17 posts

Posted 26 August 2011 - 03:09 PM

Yeah I know, I also have no Traxxas one ;) but works :P I really didn't understand the whole code yet, so I used this at the moment.

#9 haxburgen

haxburgen

    Member

  • Members
  • PipPip
  • 21 posts

Posted 21 July 2012 - 03:41 PM

What is the pin configuration? I assume the D5 pin is the pin to the ESC. But where do D0 and D1 get connected to?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.