Fezhat 1.2

Hello guys,

I purchased FezHat 1.2 and I mainly would like to use it as motor controller. Could you describe me in depth those lines of codes:

        this.hat.S1.SetLimits(500, 2400, 0, 180);
        this.hat.S2.SetLimits(500, 2400, 0, 180);

        this.hat.S1.Position += 1.0;
        this.hat.S2.Position += 1.0;

Thank you for your time. This is my firs experience with Windows IOT and working with controllers.

@ nepuan - The first two parameters to SetLimits are the minimum and maximum pulse width expressed in milliseconds of your specific servo respectively.

The last two parameters are used to set the scale of the Position property. In the example below, 0 and 180 are passed as the scale range. That means that the lowest value that Position can be set to is 0 and the highest is 180. When Position is at its lowest value, the servo pin will have a pulse length of the minimum pulse length you provided to SetLimits and similarly for when Position is at its highest value.

So with the SetLimits you provided, when you set Position to 0, the pulse width will be 500ms. When it is set to 180, it will be 2400ms. When it is set to 90, the pulse width will be 1450ms.

You can figure the pulse width using the following equation: ((maxPulseWidth - minPulseWidth) * (desiredPosition / (maxPosition - minPosition))) + minPulseWidth. Substituting the provided values: ((2400 - 500) * (90 / (180 - 0))) + 500 = 1450.

You can see the implementation of that method at https://bitbucket.org/ghi_elect/windows-iot/src/446f393eff4a92ebd27eddae96c9a02c2476d18b/GHIElectronics.UWP.Shields.FEZHAT/FEZHAT.cs?at=master&fileviewer=file-view-default#FEZHAT.cs-421

To use the FEZ HAT as a motor controller, FEZHAT.Motor may be more suitable to your needs.