Hi hampee,
if you start an autonomous boot a good start would be to control a servo.
You need a class like this:
using System; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; namespace Netduino.Extender { /// <summary> /// private static readonly Servo _Servo = new Servo(Pins.GPIO_PIN_D10); /// /// Debug.Print((data2 * 3).ToString()); /// _Servo.SetPulse(20000, data2 * 3); /// </summary> public class Servo { private PWM _Pwm; /// <summary> /// /// </summary> /// <param name="pin">Can be /// Pins.GPIO_PIN_D5 or ((Cpu.Pin)0x33), /// Pins.GPIO_PIN_D6 or ((Cpu.Pin)0x34), /// Pins.GPIO_PIN_D9 or ((Cpu.Pin)0x35), /// Pins.GPIO_PIN_D10 or ((Cpu.Pin)0x36). /// </param> public Servo(Cpu.Pin pin) { _Pwm = new PWM(pin); } public void SetDutyCycle(uint onInPercent) { _Pwm.SetDutyCycle(onInPercent); } /// <summary> /// To set a specific pulse width. /// </summary> /// <param name="completePeriodInNanoSeconds">For 50Hz servos: 20 ms</param> /// <param name="onTimePerPeriodInNanoSeconds">1 ms (left), und 2 ms (right)</param> public void SetPulse(uint completePeriodInNanoSeconds, uint onTimePerPeriodInNanoSeconds) { if (onTimePerPeriodInNanoSeconds > completePeriodInNanoSeconds) throw new InvalidOperationException(); _Pwm.SetPulse(completePeriodInNanoSeconds, onTimePerPeriodInNanoSeconds); } } }
Thanks for your help!
I already got a servo class. But its verry diferent from your code.
public class Servo { private PWM pin; private uint[] range = new uint[2]; private const uint maxDegree = 180, minDegree = 0; public Servo(Cpu.Pin servoPin) { pin = new PWM(servoPin); pin.SetDutyCycle(0); range[0] = 1000; range[1] = 2000; } public void move(double degree) { if (degree > maxDegree) degree = maxDegree; if (degree < minDegree) degree = minDegree; pin.SetPulse(20000, (uint)map((long)degree, minDegree, maxDegree, range[0], range[1])); } public void setRange(uint fullLeft, uint fullRight) { range[1] = fullLeft; range[0] = fullRight; } private long map(long x, long in_min, long in_max, long out_min, long out_max) { return (degree - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } }
I wrote it but it is highly influenced from some code on this forum so i dont take all credit.
unfortunately i havent had a chance to test it yet. But before i do so i thought i sould check with someone more experienced so i dont burn my board.