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

Code Help

Pulse width modulation in 4.3

Best Answer Chris Walker, 04 June 2013 - 08:05 PM

Hi Bradski, .NET MF 4.3 has new integrated PWM classes, but we provide backwards-compatibility classes as well. Here's what you need to do: 1. Add "SecretLabs.NETMF.Hardware.PWM.dll" as an assembly to your project references. 2. Add the text "SecretLabs.NETMF.Hardware." before "PWM" when you initialize your PWM objects. Does that get you up and running alright? Chris Go to the full post


  • Please log in to reply
4 replies to this topic

#1 Bradski

Bradski

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationUSA

Posted 01 June 2013 - 05:58 PM

Anyone have any suggestions on this code to run on the new 4.3 version plus2
 
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO.Ports;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
 
 
namespace NetduinoRobot
{
    public class Program
    {
        public static void Main()
        {
            uint watchdogTimer = 200;
 
            PWM leftDrive = new PWM(Pins.GPIO_PIN_D5);
            PWM rightDrive = new PWM(Pins.GPIO_PIN_D6);          ??
 
            Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            receiveSocket.Bind(new IPEndPoint(IPAddress.Any, 4444));
            byte[] rxData = new byte[10]; // Incoming data buffer
 
            while (true) /* Main program loop */
            {
                /* Try to receive new data - spend 100uS waiting */
                if (receiveSocket.Poll(100, SelectMode.SelectRead))
                {
                    int rxCount = receiveSocket.Receive(rxData);
                    watchdogTimer = 0;
                }
 
                if (watchdogTimer < 200)   // Only enable the robot if data was received recently
                {
                    // 900 (full rev) to 2100 (full fwd), 1500 is neutral
                    leftDrive.SetPulse(20000, map((uint)rxData[0], 0, 255, 900, 2100));
                    rightDrive.SetPulse(20000, map((uint)rxData[2], 0, 255, 900, 2100));   ???
                    watchdogTimer++;
                }
                else
                {
                    // Disable the robot
                    leftDrive.SetDutyCycle(0);
                    rightDrive.SetDutyCycle(0); ????
                }
            }
        }
 
        public static uint map(uint x, uint in_min, uint in_max, uint out_min, uint out_max)
        {
            return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
        }
    }
}

 



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 June 2013 - 08:05 PM   Best Answer

Hi Bradski, .NET MF 4.3 has new integrated PWM classes, but we provide backwards-compatibility classes as well. Here's what you need to do: 1. Add "SecretLabs.NETMF.Hardware.PWM.dll" as an assembly to your project references. 2. Add the text "SecretLabs.NETMF.Hardware." before "PWM" when you initialize your PWM objects. Does that get you up and running alright? Chris

#3 Bradski

Bradski

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationUSA

Posted 04 June 2013 - 11:26 PM

That did the trick! Thanks you are the Master!



#4 AarifSaiyed

AarifSaiyed

    New Member

  • Members
  • Pip
  • 1 posts

Posted 03 March 2014 - 01:49 AM

Could i please have the signature of the SecretLabs SetPulse method



#5 Bradski

Bradski

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationUSA

Posted 06 March 2014 - 03:34 AM

  private static void Driveline()
        {
          
            SecretLabs.NETMF.Hardware.PWM leftTrack = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5);
            SecretLabs.NETMF.Hardware.PWM rightTrack = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D6);
            
____________________________________________________________________________________________________
 
 
// 900 (full rev) to 2100 (full fwd), 1500 is neutral
                    leftTrack.SetPulse(20000, map((uint)rxData[0], 0, 255, 1200, 1800));
                    rightTrack.SetPulse(20000, map((uint)rxData[2], 0, 255, 1200, 1800));





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.