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