Coder Social home page Coder Social logo

pid-control-system's Introduction

Raspberry Pi 3 Closed-Loop Control Demo

This project showcases how to use Windows 10 IoT Core on a Raspberry Pi 3 to spin a motor by providing input to a motor controller and then measuring the speed of the spinning motor using a digital encoder. We use the digital encoder feedback in a PID loop to control the speed of the motor and by doing this, created a closed loop control system!

Aside from that, it demonstrates the Windows 10 IoT Core's capabilities to provide and interact with a Remote UI and sensors.

NOTE: The demo code in this repository uses certain Windows IoT Core features that are not yet available. This notice will be removed as soon as all dependent features have been released.

Get the Code

This repository contains references to submodules. Be sure to use the --recursive flag when cloning.

git clone --recursive https://github.com/ms-iot/pid-control-system.git

Hardware Build

For information on the hardware build see our post on Hackster.io.

DemoApp

This project contains the main UI for the demo and includes the Motor and PidController projects. The demo can run in two modes. In throttle mode the slider will adjust the throttle of the motor between 0 and 100%. While the motor controllers used are capable of driving the motor in reverse, this project doesn't use that functionality but it can easily be achieved by setting a negative percentage as the motor throttle. In closed-loop mode the application will control the motor throttle to achieve the desired RPM which is again set with the slider control.

Motor

This project contains the logic for getting the RPM of the motor shaft and controlling the motor throttle. Throttle is controlled using a PWM-controlled motor controller which is attached to an Adafruit PWM Servo Hat. The RPM value is calculated using Lightning and an optical encoder. Knowing the pulses per revolution value of the encoder along with the elapsed time between interrupts we can easily calculate the RPM. This results in the RPM being calculated hundreds of times a second which can lead to a very noisy output so we used an exponential moving average to smooth it out.

Example

Motor motor = new Motor(0, 36, 250);
await motor.Initialize();
motor.Throttle = 50.0; // Set the throttle to 50%
var rpm = motor.RPM;   // Get the current RPM

Constructor

Motor motor = new Motor(int motorPin, int encoderPin, int encoderPPR);
  • motorPin - The PWM channel on the HAT to which the motor is connected
  • encoderPin - The pin to which the optical encoder channel is connected
  • encoderPPR - The pulses per revolution value of the encoder used (found in the datasheet)

Methods

Method Description
Initialize() Initializes the motor. Must be called before any other operations are performed on the Motor object.

Properties

Property Type Access Description
Throttle double get/set The throttle of the motor as a percentage between -100.0 and 100.0. -100.0 is full reverse, 0 is stopped, and 100.0 is full forward.
RPM double get The current RPM of the motor.

PidController

This project contains the PID logic for achieving closed loop control of the motor RPM and is documented here.

Microsoft.IoT.Lightning.Providers

This project is the WinRT layer that connects to the underlying Lightning (DMAP) layer and is documented here.

pid-control-system's People

Contributors

sidwarkd avatar anthonyngu avatar anthony-ngu avatar zfields avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.