this code is for inverted pendulum balancer. it is based on two-loop PID controller. One controller is for Angle and another one is for velocity.

Dependencies:   HCSR04 L298HBridge mbed

distance/distance.cpp

Committer:
dudu941014
Date:
2017-08-25
Revision:
0:489498e8dae5

File content as of revision 0:489498e8dae5:

//////////////////////////////////////////////////////////////////////////////////
// Company: edinburgh of university
// Engineer: ZEjun DU
// 
// Create Date: 2017/08/20 13:06:52
// Design Name: Inverted Pendulum Balancer
// Module Name: acquiring real-time distance
// Tool Versions: “Keil 5” or “Mbed Complie Online”
// Description: this part is to get real-time distance from distance sensor
//                           
// 
//////////////////////////////////////////////////////////////////////////////////
#include "distance.h"

HCSR04 usensor(p10,p11);//this defines the pins of Distance sensor of HCSR04
float home = 0;//this is a offset to set the original
float distance;//this is final distance which should be outputed
float distance_original;     

////////////////////////////////////////////////////////////// 
////this part is to get distance without filter
//////////////////////////////////////////////////////////////
void get_distance(void){
    usensor.start();//start the distance sensor
    distance_original = usensor.get_dist_cm();//acquiring real-time distance
    distance =  distance_original - home ;//acquiring real-time distance after configuring the original
    }