HELP with servo on NP2 - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
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

HELP with servo on NP2


  • Please log in to reply
5 replies to this topic

#1 MrGringoPy

MrGringoPy

    New Member

  • Members
  • Pip
  • 8 posts

Posted 04 July 2013 - 03:08 AM

Hi

 

Am am new at this but have little bit of  experience in Visual Basic.

 

I am using  VB 2010 Express.

 

All I want is for my servo to move  :(  I have been at this for two days.

 

My servo is a Hitec HS-5645MG. Yellow is connected to Digital pin 9 and Black and red to a 6v external power.

I have also tried connecting power directly to the NP2. 

 

What is wrong with my code?

 

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino

Module Module1

  Sub Main()
  [color=#006400;]'Hitec HS-5645MG - Digital High Torque Servo ---Pulse Cycle:20 ms  Pulse Width:  900-2100 µs[/color]

  Dim pwm As New PWM(PWMChannels.PWM_PIN_D9, 20000, 1500, pwm.ScaleFactor.Microseconds, False)

  Const period As UInteger = 20 * 1000 * 1000 [color=#006400;] ' 20 ms[/color]

  Const duration As UInteger = 20 * 1000 * 1000[color=#006400;] ' 1 ms[/color]

  pwm.Duration = (period And duration)

  Thread.Sleep(100)

  End Sub

End Module

 

#2 Heroduino

Heroduino

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationGermany

Posted 04 July 2013 - 10:25 AM

Hello MrGringoPy,

 

you need to change the duration. So you use only the value duration.

 

To Control the Servo, you can change the duration between 1000 to 2000 (1ms to 2ms). The periode have you set and so you don't need to change it. ;)

 

 

 

Heroduino



#3 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 04 July 2013 - 07:32 PM

Also, you probably want to replace the Sleep(100) at the end of Main() with a Sleep(Timeout.Infinite) or your PWM object will fall out of scope after a 100ms worth of operation. Note that you will have to alter the duration for the servo to move back and forth. Any fixed duration will only make the servo move to a certain angle and then just sit there. The servo will try to maintain its position and so it will try to resist you trying to turn it away from the set position. Usually, 1ms, 1.5ms and 2ms correspond to angular positions of approximately -45, zero (center) and 45 degrees respectively yielding a dynamic range of 90 degrees. Be careful setting the duration outside these boundaries or you may end up damaging the servo since it might try to move beyond its own reach (there are usually blockings at the extremes) while trashing the gearbox. This has happened to me. You can power most servos with 4.8 - 6V so you can feed it directly from your Netduino (e.g. USB 5V) - just keep in mind that the servo will draw more current as you apply mechanical load to it so a separate supply is probably a good idea and 6V will give you a higher torque.

#4 Heroduino

Heroduino

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationGermany

Posted 04 July 2013 - 07:55 PM

Hello again MrGringoPy,

 

perhaps, write it in code is sometime easier to understand  ;)

 

Module Module1   Sub Main()

  Dim pwm As New PWM(PWMChannels.PWM_PIN_D9, 20000, 1500, pwm.ScaleFactor.Microseconds, False)  

' First Position (Duration for 1.0ms)   pwm.Duration = 1000   Thread.Sleep(100)

 

' Middle Position (Duration for 1.5ms)   pwm.Duration = 1500   Thread.Sleep(100)

 

  ' Last Position (Duration for 2.0ms)   pwm.Duration = 2000   Thread.Sleep(100)

  End Sub

 

 

sincerely,

Heroduino End Module



#5 MrGringoPy

MrGringoPy

    New Member

  • Members
  • Pip
  • 8 posts

Posted 05 July 2013 - 12:24 AM

Hi  Heroduino and Hanzibal

 

I very much appreciate  your help.  I have put in over 200 hour of reading and trying all sorts to make the servo just do at least one move.

 

The first time I run my program the servo made a minor move of say less than 2 degrees and never again. If I plug 6v external power in the servo resist hand moment. So I think motor is good.(It is a brand new servo.) 

 

Next I ran another program to test PMW_9 with a LED.  Yes PWM_9 works. LED Blinks. ( I thought maybe I toasted it I/O 9.) 

 

Program for LED.

Module Module1   Sub Main()   Dim button As New InputPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled)   Dim led As New OutputPort(Pins.GPIO_PIN_D9, False)   Dim buttonstate As Boolean = False   Do   buttonstate = button.Read()   If buttonstate = True Then   led.Write(True)   Thread.Sleep(50)   led.Write(False)   Thread.Sleep(100)   Else   End If   Loop   End Sub End Module

 

 

I am at a total loss here.  I do not know what to try any more. 

 

Is it possible that I have toasted the servos digital input by sending the wrong period ? 

 

Any help, program or idea is very welcome.

 

Thank and hope to hear from you soon.  :)



#6 MrGringoPy

MrGringoPy

    New Member

  • Members
  • Pip
  • 8 posts

Posted 05 July 2013 - 03:28 PM

Ok.... I found this code and I set it up as they said.  Now this happens ALL the time.  I past it, and it has a load of errors.  It beats me how it can work for some ells and not for me. 

 

As you said Heroduino, writing it in code is a lot easier to understand. So please if can please fix the code for me.

 

Here are the errors and the code. 

 

Error  1  Overload resolution failed because no accessible 'New' accepts this number of arguments.   Servo_AP.vb  41  25  Servo test 12 Warning  2  Using DirectCast operator to cast a value-type to the same type is obsolete.   Servo_AP.vb  41  44  Servo test 12 Error  3  The targeted platform does not support latebinding.   Servo test 12Servo_AP.vb  43  13  Servo test 12 Error  4  'SetDutyCycle' is not a member of 'Microsoft.SPOT.Hardware.PWM'.   Servo test 12Servo_AP.vb  66  13  Servo test 12 Error  5  'SetPulse' is not a member of 'Microsoft.SPOT.Hardware.PWM'.   Servo_AP.vb  87  17  Servo test 12

 

 

Imports Microsoft.SPOT Imports Microsoft.SPOT.Hardware Imports SecretLabs.NETMF.Hardware Imports SecretLabs.NETMF.Hardware.Netduino Module Module1   Sub Main()   Dim servo As New Servo_API.Servo(Pins.GPIO_PIN_D9)   Dim i As Integer = 0   Do While True   Do While i < 100   'Loop to fade from off to full on'   servo.Degree = i   'wait for 15 milliseconds'   Thread.Sleep(10)   i = i + 1   Loop   i = 100   Do While i > 0   'Loop to fade from full on to off'   servo.Degree = i   'wait for 15 milliseconds'   Thread.Sleep(10)   i = i - 1   Loop   Loop   End Sub End Module

 

 

--------------------------------------------------------------------------------------------------------------------------

' ' * 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) ' ' * Fileark: 2012-05-08 Converted to VB ( ' * ' ' * ' Imports Microsoft.SPOT.Hardware Imports SecretLabs.NETMF.Hardware Namespace Servo_API   Public Class Servo   Implements IDisposable   ' PWM handle'   Private servo As PWM   ' Timings range'   Private range As Long() = New Long(1) {}   ' Set servo inversion'   Public inverted As Boolean = False   ' Create the PWM pin, set it low and configure timings'   Public Sub New(ByVal pin As Cpu.Pin)   ' Init the PWM pin'   Dim servo = New PWM(DirectCast(pin, Cpu.Pin))   servo.SetDutyCycle(0)   ' Typical settings'   range(0) = 800   range(1) = 3200   End Sub   Public Sub Dispose() Implements IDisposable.Dispose   disengage()   servo.Dispose()   End Sub   ' Allow the user to set cutom timings'   Public Sub setRange(ByVal fullLeft As Long, ByVal fullRight As Long)   range(1) = fullLeft   range(0) = fullRight   End Sub   ' Disengage the servo. '   ' The servo motor will stop trying to maintain an angle'   Public Sub disengage()   servo.SetDutyCycle(0)   End Sub   ' Set the servo degree'   Public WriteOnly Property Degree() As Double   Set(ByVal value As Double)   ' Range checks'   If value > 180 Then   value = 180   End If   If value < 0 Then   value = 0   End If   ' Are we inverted?'   If inverted Then   value = 180 - value   End If   ' Set the pulse'   servo.SetPulse(20000, CUInt(map(CLng(Math.Truncate(value)), 0, 180, range(0), range(1))))   End Set   End Property   ' Used internally to map a value of one scale to another'   Private Function map(ByVal x As Long, ByVal in_min As Long, ByVal in_max As Long, ByVal out_min As Long, ByVal out_max As Long) As Long   Return (x - in_min) * (out_max - out_min) (in_max - in_min) + out_min   End Function   End Class End Namespace  






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.