Buy me a cup of coffee 

Software development is powered by coffee... if you use any of our open source pojects, it would make my day if you'd buy me a cup (or several). Just click on the coffee cup.

Motor Control for .NET MicroFramework

Tags: open-source, free software, source code, software, ASCOM, astronomy, focuser

Motor Control With a Difference

This library provides very flexible general purpose motor control, including stepper motors with acceleration and deceleration, full stepping, half stepping and microstepping.

The code is developed in C# and runs within the .NET MicroFramework on devices such as the Netduino Plus 2, from Secret Labs. The Netduino 2 and Plus 2 are the recommended targets for this library as the predecessors are not really fast enough to get acceptable stepping rates.

We have carefully designed the code using modern objected-oriented practices so that it doesn't depend on any particular hardware. It is very easy to adapt for different shields and we provide drivers for the Sparkfun Ardumoto shield and the Adafruit Motor Control Shield (version 2).

We have used this library internally to produce a focus controller for a telescope, complete with an ASCOM driver.

ASCOM compatible focus controller

There is a NuGet package available and the source code is published on BitBucket.

What is this repository for?

Motors are objects, too! There is a lot of micro-framework code out there that looks like it was written in Fortran in the 1960s. Rather than just port an existing library directly to C#, we have tried to take a more object oriented approach to this library and we've created it from the ground up using SOLID design principles.

Some features and aims of this library:

  • Object oriented: we strive to give each class a single responsibility and basically follow the SOLID best practices.
  • Clean code: we strive to maintain 'clean code' that is well documented, readable by human beings and easy to maintain.
  • Asynchronous non-blocking: Where it makes sense, we try to make operations autonomous and non-blocking. For example, when commanding a stepper motor to move to a certain position, the motor runs autonomously under control of a timer without any further interaction from user code. The acceleration and deceleration happens automatically and an event is fired when the motor stops. No 'call this method repeatedly from your main loop' type of requirements.
  • General purpose: where possible, we have tried to avoid hard-coding things like hardware addresses. Where possible, dependencies are passed into the constructor, so that for example, multiple motors can be controlled simply by newing up multiple instances of the classes.
  • Community involvement welcome: We would love to get some pull requests!
  • Permissive license: All code in this repository is covered by the MIT license, which is a permissive license. In summary, anyone can do anything at all with this code with proper attribution and with no warranty. Commercial use is specifically allowed.

How do I get set up?

The projects are configured for Netduino Plus 2 hardware and .net MicroFramework 4.3. There are instructions on setting up Visual Studio 2012 on the Netduino forums. You should be able to clone the code, build it in Visual Studio 2012 or later and deploy it to your Netduino Plus.

Note: Netduino support for Visual Studio 2013 is experimental, but we've found it works brilliantly. If you are using VS2013, there are special instructions on setting up.

Get the Binaries

If you just want to get going quickly with motor control and you don't need to build the source, then we have provided a NuGet package. Support for NuGet is built into Visual Studio, just search for "Motor Control" and you should find it.

Contribution guidelines

We invite and encourage pull requests. Each request will undergo code review before being merged. We use GitFlow, which reserves the master branch for published releases. Therefore, please push your code to develop or a feature branch off develop. Atlassian SourceTree has built-in support for GitFlow and makes it all very simple, but there is nothing special about GitFlow branches, they are just ordinary Git branches with an implied naming convention.

When you push code or submit a pull request to this repository, you are agreeing that your code is irrevocably donated to the project under the project's MIT License. Note that the license allows for commercial use of the code. Please don't submit code if you are not comfortable with that.

What needs to be done?

Some ideas for future work:

  • Additional motor types
    • DC motors
    • Servo motors
  • Other motor shields
    • Sparkfun motor control shield (part complete - stepper motor implemented)
    • Adafruit motor shiled V1 - abandoned due to the product becoming obsolete.
    • Adafruit motor shield V2 - part complete (stepper motor implemented).
  • Unit tests: We love unit tests, but haven't found a good way of doing that with micro-framework projects. We would love some contribution in this area. Can you work out how we could unit test a micro-framework project?
  • Make the code cleaner - we try to write clean code but there is always room for improvement.
  • Remove any SOLID violations. Again, always room for improvement.

Who do I talk to?

This project is licensed under the MIT license

TeamCity Build Status

Let Us Help You

Find us on Facebook