2014-03-27 2 views
0

나는 크리스의 클래스의 새 버전을 사용하고 있습니다 : 3.3 GND 포트 (5) 디지털에Netduino - 클래스 서보 - 4.3.1

/* 
* Servo NETMF Driver 
*  Coded by Chris Seto August 2010 
*  <[email protected]> 
*  
* 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) 
* 
* 
* */ 
using System; 
using Microsoft.SPOT; 
using Microsoft.SPOT.Hardware; 
using SecretLabs.NETMF.Hardware; 
using SecretLabs.NETMF.Hardware.Netduino; 

namespace Servo_API 
{ 
    public class Servo : IDisposable 
    { 
     /// <summary> 
     /// PWM handle 
     /// </summary> 
     private PWM servo; 

     /// <summary> 
     /// Timings range 
     /// </summary> 
     private int[] range = new int[2]; 

     /// <summary> 
     /// Set servo inversion 
     /// </summary> 
     public bool inverted = false; 

     /// <summary> 
     /// Create the PWM Channel, set it low and configure timings 
     /// </summary> 
     /// <param name="pin"></param> 
     public Servo(Cpu.PWMChannel channelPin) 
     { 
      // Init the PWM pin 
      servo = new PWM((Cpu.PWMChannel)channelPin, 20000, 1500, PWM.ScaleFactor.Microseconds, false); 

      servo.DutyCycle = 0; 
      // Typical settings 
      range[0] = 1000; 
      range[1] = 2000; 
     } 

     public void Dispose() 
     { 
      disengage(); 
      servo.Dispose(); 
     } 

     /// <summary> 
     /// Allow the user to set cutom timings 
     /// </summary> 
     /// <param name="fullLeft"></param> 
     /// <param name="fullRight"></param> 
     public void setRange(int fullLeft, int fullRight) 
     { 
      range[1] = fullLeft; 
      range[0] = fullRight; 
     } 

     /// <summary> 
     /// Disengage the servo. 
     /// The servo motor will stop trying to maintain an angle 
     /// </summary> 
     public void disengage() 
     { 
      // See what the Netduino team say about this... 
      servo.DutyCycle = 0; //SetDutyCycle(0); 
     } 

     /// <summary> 
     /// Set the servo degree 
     /// </summary> 
     public double Degree 
     { 
      set 
      { 
       /// Range checks 
       if (value > 180) 
        value = 180; 

       if (value < 0) 
        value = 0; 

       // Are we inverted? 
       if (inverted) 
        value = 180 - value; 

       // Set the pulse 
       //servo.SetPulse(20000, (uint)map((long)value, 0, 180, range[0], range[1])); 
       servo.Duration = (uint)map((long)value, 0, 180, range[0], range[1]); 
      } 
     } 

     /// <summary> 
     /// Used internally to map a value of one scale to another 
     /// </summary> 
     /// <param name="x"></param> 
     /// <param name="in_min"></param> 
     /// <param name="in_max"></param> 
     /// <param name="out_min"></param> 
     /// <param name="out_max"></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 servo = new Servo(PWMChannels.PWM_PIN_D5); 
servo.Degree = 30; // Change 'While' to 'For' to limit how many time it repeats 
     for (int j = 0; j < 3; j++) 
     { 
      for (int i = 0; i <= 180; i++) 
      { 
       servo.Degree = i; 
       Thread.Sleep(10); 
      } 


      for (int i = 180; i >= 0; i--) 
      { 
       servo.Degree = i; 
       Thread.Sleep(10); 
      } 
     } 

내가 연결 서보 Netduino에

내 서보은 다음과 같습니다 http://www.hobbyking.com/hobbyking/store/_14458_hobbyking_939mg_metal_gear_servo_2_5kg_12_5g_0_14sec.html

,536,913,632 10

작동하지 않습니다! 왜? 누군가 이미 효과가있는 것을 했습니까?

+0

은 무엇입니까 너의 질문? –

+0

작동하지 않습니다! 작동하는 방법? – Dorathoto

+0

"작동하지 않음"으로 충분하지 않습니다. 어떤 오류가보고 있습니까? 어떤 일이 생겼습니까? 문제/오류에 대한 자세한 내용을 참조하십시오. – Ryan

답변

0

부재 .start() 100 % Netduino 작업

내 클래스, - 서보 클래스를 .NET 4.3.1

using System; 
using Microsoft.SPOT; 
using Microsoft.SPOT.Hardware; 
using SecretLabs.NETMF.Hardware; 
using SecretLabs.NETMF.Hardware.Netduino; 

namespace Servo_API 
{ 
    public class Servo : IDisposable 
    { 
     /// <summary> 
     /// PWM handle 
     /// </summary> 
     private PWM servo; 

     /// <summary> 
     /// Timings range 
     /// </summary> 
     private int[] range = new int[2]; 

     /// <summary> 
     /// Set servo inversion 
     /// </summary> 
     public bool inverted = false; 

     /// <summary> 
     /// Create the PWM Channel, set it low and configure timings 
     /// </summary> 
     /// <param name="pin"></param> 
     public Servo(Cpu.PWMChannel channelPin) 
     { 
      // Init the PWM pin 
      // servo = new PWM((Cpu.PWMChannel)channelPin, 20000, 1500, PWM.ScaleFactor.Microseconds, false); 
      servo = new PWM(PWMChannels.PWM_PIN_D5, 20000, 1500, Microsoft.SPOT.Hardware.PWM.ScaleFactor.Microseconds, false); 
      servo.Period = 20000; 

      // Typical settings 
      range[0] = 1000; 
      range[1] = 2000; 
     } 

     public void Dispose() 
     { 
      disengage(); 
      servo.Dispose(); 
     } 

     /// <summary> 
     /// Allow the user to set cutom timings 
     /// </summary> 
     /// <param name="fullLeft"></param> 
     /// <param name="fullRight"></param> 
     public void setRange(int fullLeft, int fullRight) 
     { 
      range[1] = fullLeft; 
      range[0] = fullRight; 
     } 

     /// <summary> 
     /// Disengage the servo. 
     /// The servo motor will stop trying to maintain an angle 
     /// </summary> 
     public void disengage() 
     { 
      // See what the Netduino team say about this... 
      servo.DutyCycle = 0; //SetDutyCycle(0); 
     } 

     /// <summary> 
     /// Set the servo degree 
     /// </summary> 
     public double Degree 
     { 
      set 
      { 
       /// Range checks 
       if (value > 180) 
        value = 180; 

       if (value < 0) 
        value = 0; 

       // Are we inverted? 
       if (inverted) 
        value = 180 - value; 

       // Set the pulse 
       //servo.SetPulse(20000, (uint)map((long)value, 0, 180, range[0], range[1])); 
       servo.Duration = (uint)map((long)value, 0, 180, range[0], range[1]); 
       servo.Start(); 
      } 
     } 


     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 tt = new Servo(Cpu.PWMChannel.PWM_5); 
      tt.Degree = 30; 
      tt.setRange(1000, 2000); 
      tt.Dispose(); 
     } 
0

나는 lib를 사용하지 않았지만 서보가 3.3v로 전원을 공급 받아서는 안되며, 5v 핀에 별도로 연결해야합니다.

당신이 시도 할 수있는 또 다른 것은 새로운 PWM 생성하는 것입니다 : 또한

PWM servo = new PWM(Pins.GPIO_PIN_D9); 

를, 그래서 우리는 당신이 그 동작을 설명한다 ... 그것은 기라도하면 도움이 될 수 있습니다, 천천히 이동 뭔가 ... 플러스 당신이 그것을 연결 한 방법 (다이어그램, 사진).

+0

PWM은 하나의 매개 변수만을 허용하지 않습니다. PWM _serv = 새 PWM (Cpu.PWMChannel.PWM_5, 20000, 1500, PWM.ScaleFactor.Microseconds, false); – Dorathoto