

Netduino servo class
#21
Posted 03 September 2010 - 04:23 AM

#22
Posted 26 September 2010 - 03:48 AM
#23
Posted 26 September 2010 - 05:24 AM
Hi guys,
I'm a newb (when it comes to hardware) and I'm trying to hook up this parallax servo. The red wire is hooked into the 5V pin, the black is hooked into the ground pin, and the white is hooked into the Digital I/O 7 pin. I tried my own code to make the servo move, but was getting an exception. So I tried the Servo class from above (which essentially does the same thing) and I get the same error:
"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in SecretLabs.NETMF.Hardware.dll"
I get the System.ArgumentOutOfRangeException when it tries to new up the Servo class, and I get the same exception when I try and instantiate the PWM with the digital I/O 7 pin.
I assume that this means that it doesn't see anything connected to the pin, or maybe it's not the right type of device? Any ideas what the problem might be?
FYI, the servo does power on, as it jitters a little bit then I plug it in, I've also tried different digital pins to no avail.
I've made that same mistake before.

R/C Servos use Pulse Width Modulation, and PWM is only supported on digital pins 5,6,9, and 10
http://netduino.com/netduino/specs.htm
Change it from pin 7 (hardware and software) to a valid PWM pin and it'll work.
#24
Posted 26 September 2010 - 05:09 PM
#25
Posted 05 December 2010 - 04:13 PM
#26
Posted 05 December 2010 - 04:37 PM
/* * Servo NETMF Driver * Coded by Chris Seto August 2010 * <chris@chrisseto.com> * * Use this code for whatveer you want. Modify it, redistribute it, I don't care. * I do ask that you please keep this header intact, however. * If you modfy the driver, please include your contribution below: * * Chris Seto: Inital release (1.0) * Chris Seto: Netduino port (1.0 -> Netduino branch) * Chris Seto: bool pin state fix (1.1 -> Netduino branch) * * Omar (OZ): I've changed a decent amount of code... original is here: http://forums.netduino.com/index.php?/topic/160-netduino-servo-class/ * * */ using System; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; namespace Servo_API { public class Servo : IDisposable { private PWM servoControl; private uint[] _range = new uint[2]; private const uint IN_MAX = 180, IN_MIN = 0; private bool _reverse = false; public Servo(Cpu.Pin pin) { servoControl = new PWM(pin); servoControl.SetDutyCycle(0); // Start stopped. // Set default timing settings _range[0] = 1000; _range[1] = 2000; } public void SetDegree(double _degree) { if (_degree > IN_MAX) _degree = IN_MAX; // If greater than 180, then make it 180 if (_degree < IN_MIN) _degree = IN_MIN; // If less than 0, then make it 0 if (_reverse) _degree = IN_MAX - _degree; // Modify it to be reversed. servoControl.SetPulse(20000, (uint)map((long)_degree, IN_MIN, IN_MAX, _range[0], _range[1])); } public uint Full_Right { get { return _range[0]; } set { _range[0] = value; } } public uint Full_Left { get { return _range[1]; } set { _range[1] = value; } } public bool Reversed { get { return _reverse; } set { _reverse = value; } } // This is from http://www.arduino.cc/en/Reference/Map ... You can read more about it there. /// <summary> /// Used internally to map a value of one scale to another /// </summary> /// <param name="x">Current value input</param> /// <param name="in_min">Minimum input</param> /// <param name="in_max">Maximum input</param> /// <param name="out_min">Minimum output</param> /// <param name="out_max">Maximum ouput</param> /// <returns></returns> private long map(long x, long in_min, long in_max, long out_min, long out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } ~Servo() { Dispose(); } public void Dispose() { servoControl.SetDutyCycle(0); servoControl.Dispose(); } } }
#27
Posted 05 December 2010 - 05:56 PM
In testing, I ran:
for (int i = 0; i <= 180; i++) { myServo.Degree = i; }
Not sure why my servo is straining to get to the outer bounds, but I'll look into it more.
#28
Posted 05 December 2010 - 11:52 PM
#29
Posted 14 December 2010 - 02:35 AM
#30
Posted 14 December 2010 - 04:47 PM
#31
Posted 14 December 2010 - 08:41 PM
Not powering the servo from Vin, right?
nope, i have it powered with the netduino's 5V.
#32
Posted 15 December 2010 - 03:16 AM
#33
Posted 15 December 2010 - 08:27 PM
If it has any load on it, you need to power it through some other source. Other than that, I think you need to probe the signal pin to see what it's doing.
I think it is pulling too much power from the netduino. I'll power it externally and post the results here...
#34
Posted 21 April 2011 - 01:21 AM

#35
Posted 21 April 2011 - 01:50 AM

#36
Posted 21 April 2011 - 04:11 AM

#37
Posted 21 April 2011 - 11:29 PM
Hi Tarkon,
Have you selected your Netduino as the deployment target (in Project Properties > .NET Micro Framework)? If your app is running in the emulator instead, hardware features won't work
Chris
Thank you, I'm big stupid.

#38
Posted 02 January 2012 - 11:14 PM
~Servo() { Dispose(); }
could you explain this peace of code?
#39
Posted 03 January 2012 - 02:02 AM
#40
Posted 09 April 2012 - 11:35 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users