Code Monkey home page Code Monkey logo

motor_pid's Introduction

Motor_PID HG7881_L9110

this library let you control motor with pwm signal

library works with HG7881 module double H bridge L9110S

usage

EXAMPLE HG7881 module double H bridge L9110S

#include <Motor_PID.h>
#define ENCA 33  // YELLOW from polulu
#define ENCB 34  // WHITE from polulu

#define IN2 11  //B1-A
#define IN1 10  //A1-A

int target = 100;

// PID constants
float kp = 8;
float kd = 1;
float ki = 0.01;

Motor motor1(ENCA, ENCB, IN1, IN2);

void setup() {
    motor1.init(kp, ki, kd);
    motor1.set_target(target);
}
void loop() {
    motor1.start();
}

L298N driver example

// remember that l298n need 3 volt over DC motor nominal voltage to run full speed 
//you can supply even more voltage but then limit it with pwm like i did here
#include <Motor_PID.h>
#define ENCA 2 // YELLOW from polulu encoder
#define ENCB 3 // WHITE from polulu encoder

#define IN2 10 //in2 from driver // pins to control direction
#define IN1 11 //in1 from driver // pins to control direction
#define PWM_PIN 5 //pwm to control speed

int target = 900;

// PID constants
float kp = 1;
float kd = 0.1;
float ki = 0.02;

int pwm_lower_limit = 0;//full range
int pwm_upper_limit = 255;//full range

Motor motor1(ENCA, ENCB, IN2, IN1, PWM_PIN, pwm_lower_limit, pwm_upper_limit);
void setup()
{
   motor1.init(kp, kd, ki);
   motor1.set_target(target);
}
void loop()
{
   motor1.start();
   if (motor1.get_position() == target) motor1.turn_off();
}

motor_pid's People

Contributors

natnqweb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

motor_pid's Issues

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.