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

Netduino Plus 2 RC Reading Works for Me?


  • Please log in to reply
4 replies to this topic

#1 sjmill01

sjmill01

    Advanced Member

  • Members
  • PipPipPip
  • 45 posts
  • LocationSouth Carolina

Posted 01 November 2013 - 12:02 AM

In the last few days, I cobbled some code that seems to use the Netduino Plus 2 PWM pins to reliably read data from an RC receiver.

 

While searching the web for code, I found countless posts that the Netduino Plus 2 either can't do it or is not reliable to do it.  But, I'm living proof that it does it.

 

Is this just an "Apple vs. PC"-like phenomenon on the web, or should I not trust the Netduino Plus 2 to reliably read RC data - particularly in the application of motor control?

 

So far, I'm only using it to trigger audio on an MP3Trigger.  However, my next target is to receive drive and direction from an RC controller, process it against sensors with the Netduino Plus 2, and then send the appropriate PWM to the motor driver.

 

Thanks in advance for any advice,

Sean



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 November 2013 - 02:57 AM

Hi Sean, The big unknown is garbage collection, really. If you discard a lot of objects, the garbage collector will start up and those incoming pulses may be delayed. Or if they're fast enough, in theory, you could lose some of them. We do lots of stuff with Netduinos that they're not supposed to be designed to do ;) The important things is that you have fun and do cool projects. Just always be mindful of safety. Chris

#3 sjmill01

sjmill01

    Advanced Member

  • Members
  • PipPipPip
  • 45 posts
  • LocationSouth Carolina

Posted 03 November 2013 - 12:29 AM

Thanks for the reply.

 

When you say "delayed", are we talking <1 second or greater?

 

I'm driving a life size R2D2 that weighs about 100 lbs, so safety is definitely a consideration.

 

Thanks,

Sean



#4 tommyleo

tommyleo

    New Member

  • Members
  • Pip
  • 3 posts
  • LocationMilan - Italy

Posted 03 November 2013 - 08:10 AM

Thanks for the reply.

 

When you say "delayed", are we talking <1 second or greater?

 

I'm driving a life size R2D2 that weighs about 100 lbs, so safety is definitely a consideration.

 

Thanks,

Sean

 

Hello Sean,

 

in my project wih NetDuino Plus 2 (4.3) I read 4 Reciever channels and I drive 4 motors for a quadricopter, and work very well, with a main loop close to 700hz

 

I have clean my code....hope that I don't forget somethings:

 

This is a class for Receiver Channels

using System;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;namespace tommyQuad{    class Channel    {        //InterruptPort        public InterruptPort pin;        //Last tick read        public long lastTick {get; set;}        //Min and Max pulse width values        public int minValue { get; set; }        public int maxValue { get; set; }        //Current Value        public int currentValue { get; set; }        public Channel()        {            lastTick = -1;            minValue = 1110;            maxValue = 1915;            currentValue = 1000;        }    }    class Receiver    {        //Ticks in Microseconds (There are 10,000 ticks in a millisecond, so in a microsecond = 10 ticks)        private const long ticksInMicrosecond = (long)(TimeSpan.TicksPerMillisecond / 1000);                public Channel[] channels;        public Receiver()        {            //Initialize the channel array            channels = new Channel[40];        }        // Begins monitoring a channel on the receiver given a pin index        public void addChannel(Cpu.Pin pin)        {            Channel c = new Channel();            c.pin = new InterruptPort(pin, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);            c.pin.OnInterrupt += new NativeEventHandler(port_OnInterrupt);            channels[(uint)pin] = c;            return;        }        // Called when an intterupt event occurs on one of the monitored pins        private void port_OnInterrupt(uint data1, uint state, DateTime time)        {            try            {                if (state == 0)                {                    long pulseWidth = time.Ticks - channels[data1].lastTick;                    int pulseWidthMicroseconds = (int)(pulseWidth / ticksInMicrosecond);                    channels[data1].currentValue = pulseWidthMicroseconds;                }                else                {                    channels[data1].lastTick = time.Ticks;                }            }            catch { }        }    }}

Main code:

using System;using System.Net;using System.IO;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace tommyQuad{    public class Program    {        //Digital Pins for Receiver        public static Cpu.Pin chRoll = Pins.GPIO_PIN_D10;      // Roll(Alieron)        public static Cpu.Pin chPitch = Pins.GPIO_PIN_D11;     // Pitch(Elevator)        public static Cpu.Pin chThrottle = Pins.GPIO_PIN_D12;  // Throttle        public static Cpu.Pin chYAW = Pins.GPIO_PIN_D13;       // YAW(Rudder)        //OnBoardLed        static bool OnBoarLedStatus = false;        static OutputPort OnBoardLed = new OutputPort(Pins.ONBOARD_LED, OnBoarLedStatus);        //Receiver Channel        static Receiver myReceiver = new Receiver();        public static void Main()        {                        //Receiver channel            myReceiver.addChannel(chRoll);            myReceiver.addChannel(chPitch);            myReceiver.addChannel(chThrottle);            myReceiver.addChannel(chYAW);            //Main loop                        long myTicks = 0; //1ms = 10.000 Ticks = 1KHz            long myTicksCount = 0;            while (true)            {                myTicks = DateTime.Now.Ticks;                if (myTicks - myTicksCount >= 100000) // 100Hz                {                    myTicksCount = myTicks;                                        Debug.Print("Th: " + myReceiver.channels[(int)chThrottle].currentValue.ToString() +                    "  Pi: " + myReceiver.channels[(int)chPitch].currentValue.ToString() +                    "  Ro: " + myReceiver.channels[(int)chRoll].currentValue.ToString() +                    "  YAW: " + myReceiver.channels[(int)chYAW].currentValue.ToString());                    OnBoardLed.Write(!OnBoarLedStatus);                }            }        }    }}

I'm sorry for my english!

 

Tommy



#5 Juzzer

Juzzer

    Advanced Member

  • Members
  • PipPipPip
  • 135 posts
  • LocationHertfordshire, UK

Posted 03 November 2013 - 01:09 PM

Dont believe the Arduino lot when they say it cant be done.... ;)

 

This is reading 3 channels i think from memory, was along time ago...

 

http://diydrones.com...actually-worked






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.