Skip to content
This repository was archived by the owner on Sep 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5ca0674
feat: first draft; includes stub implementation; TODO: modify Unit Tests
akhopkar01 Sep 23, 2020
bb1d89c
fix: minor design changes
akhopkar01 Sep 23, 2020
bdc2f59
feat: Unit test implementation; work in progress
akhopkar01 Sep 23, 2020
712d5c4
feat: Added additional features to the class, refactored code
akhopkar01 Sep 23, 2020
d7680b3
feat: added Unit tests; work in progress
akhopkar01 Sep 23, 2020
9d2597b
feat: included UML diagram
akhopkar01 Sep 23, 2020
b82f447
Update readme.md
akhopkar01 Sep 23, 2020
0c231da
fix: Fixed error in test build
akhopkar01 Sep 24, 2020
0bf35ce
refactor: Minor design changes
akhopkar01 Sep 24, 2020
0e5d5d2
Update readme.md
akhopkar01 Sep 24, 2020
b0948da
Update readme.md
akhopkar01 Sep 24, 2020
d0be33a
Update readme.md
akhopkar01 Sep 24, 2020
cb587fd
Update readme.md
akhopkar01 Sep 24, 2020
5dbf17c
Update readme.md
akhopkar01 Sep 24, 2020
78cd8a3
Update readme.md
selyard Sep 25, 2020
b20fe2e
Add PID controller function; modify constructor/destructor for PID cl…
selyard Sep 25, 2020
f865154
Update readme.md
selyard Sep 25, 2020
3e16d09
Update readme.md
selyard Sep 25, 2020
aad6065
Adding Coveralls config file.
selyard Sep 25, 2020
f5e35a6
Merge branch 'master' of https://github.com/selyard/PID_controller
selyard Sep 25, 2020
7d6202c
Update .travis.yml
selyard Sep 25, 2020
1c81cec
Update author fields, add ToDo to readme.
selyard Sep 26, 2020
443d0a5
Update Travis, Coveralls tokens.
selyard Sep 26, 2020
044f9e2
Merge pull request #1 from selyard/master
akhopkar01 Sep 26, 2020
d611ead
Naming convention-handled; minor changes
akhopkar01 Sep 28, 2020
c8b7a1b
coveralls-test
Sep 29, 2020
14b7227
updated travis-coverall links
Sep 29, 2020
803727e
Update readme.md
akhopkar01 Sep 29, 2020
a13f84b
Update .travis.yml
akhopkar01 Sep 29, 2020
f111d3e
Update .coveralls.yml
akhopkar01 Sep 29, 2020
eba3bb3
Code Coverage test
akhopkar01 Sep 29, 2020
a7496c6
Update readme.md
akhopkar01 Sep 29, 2020
31f11cc
Update .travis.yml
akhopkar01 Sep 29, 2020
8306a7e
Delete .coveralls.yml
akhopkar01 Sep 29, 2020
b0414a6
changed include path
akhopkar01 Sep 29, 2020
faae3ab
Merge branch 'master' of https://github.com/akhopkar01/PID_controller
akhopkar01 Sep 29, 2020
3a22623
Update readme.md
akhopkar01 Sep 29, 2020
8ce353d
fix: Minor change Ln 24
akhopkar01 Sep 29, 2020
23c3c80
Update readme.md
akhopkar01 Sep 29, 2020
fa9a814
Update readme.md
akhopkar01 Sep 29, 2020
0595295
Update readme.md
akhopkar01 Sep 29, 2020
5f1904f
Update readme.md
akhopkar01 Sep 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ matrix:

before_install:
- pip install --user cpp-coveralls
- sudo -H pip install --upgrade requests[security]

install:
- sudo apt-get install -y -qq lcov
script:
Expand All @@ -35,6 +37,5 @@ script:

after_success:
- coveralls --root .. -E ".*external.*" -E ".*CMakeFiles.*" -E ".*test/.*.cpp.*"

notifications:
email: false
53 changes: 37 additions & 16 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,47 @@
"${workspaceRoot}/vendor/boost",
"/usr/include"
],
"browse" : {
"limitSymbolsToIncludedHeaders" : true,
"databaseFilename" : ""
}
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"intelliSenseMode": "clang-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14"
},
{
"name": "Linux",
"includePath": ["/usr/include"],
"browse" : {
"limitSymbolsToIncludedHeaders" : true,
"databaseFilename" : ""
}
"includePath": [
"/usr/include"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14"
},
{
"name": "Win32",
"includePath": ["c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"],
"browse" : {
"limitSymbolsToIncludedHeaders" : true,
"databaseFilename" : ""
}
"includePath": [
"c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"intelliSenseMode": "msvc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14"
}
]
}
],
"version": 4
}
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// cpp general
"C_Cpp.clang_format_style": "visual studio",
"C_Cpp.clang_format_style": "Google",

// cmake
"cmake.generator.all": "ninja",
Expand All @@ -22,5 +22,6 @@
"ms-vscode.cpptools",
"RichardHe.you-complete-me",
"vector-of-bool.cmake-tools"
]
],
"C_Cpp.clang_format_fallbackStyle": "Google"
}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (COVERAGE)
include(CodeCoverage)
set(LCOV_REMOVE_EXTRA "'vendor/*'")
setup_target_for_coverage(code_coverage test/cpp-test coverage)
set(COVERAGE_SRCS app/main.cpp include/lib.hpp)
set(COVERAGE_SRCS app/main.cpp app/PID.cpp include/PID.h)

SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
Expand Down
Binary file added UML_TDD.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(shell-app main.cpp)
add_executable(shell-app main.cpp PID.cpp)
include_directories(
${CMAKE_SOURCE_DIR}/include
)
53 changes: 53 additions & 0 deletions app/PID.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2020 <Aditya Khopkar> <Rajeshwar N S>
* */

/**
* @file: PID.cpp
* @brief: Contains the class definition of PID control
* @author: Part 1 : Aditya Khopkar (driver), Rajeshwar N S (navigator)
* @author: Part 2 - Spencer Elyard (driver), Daniel Sahu (navigator)
* */

#include "PID.h"

// constructor
control::PID::PID() {
kp_ = 1.2;
ki_ = 0.4;
kd_ = 0.2;
dt_ = 1;
prev_error_ = 0.0;
integral_error_ = 0.0;
}

void control::PID::SetKp(double kp) { this->kp_ = kp; }

void control::PID::SetKd(double kd) { this->kd_ = kd; }

void control::PID::SetKi(double ki) { this->ki_ = ki; }

double control::PID::Compute(double feedback, double setpoint) {
// calculate current error
double current_error = setpoint - feedback;
// Proportional controller portion
double proportional = kp_ * current_error;
// Integral controller portion
double integral = ki_ * (integral_error_ + current_error * dt_);
// Derivative
double derivative = kd_ * ((current_error - prev_error_) / dt_);
// calculate output
double output = proportional + integral + derivative;
// save error as previous prev_error_
prev_error_ = current_error;
return output;
}

const double& control::PID::GetKp() { return this->kp_; }

const double& control::PID::GetKd() { return this->kd_; }

const double& control::PID::GetKi() { return this->ki_; }

// destructor
control::PID::~PID() {}
30 changes: 25 additions & 5 deletions app/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
/**
* Copyright 2020 <Aditya Khopkar> <Rajeshwar N S>
* */

/**
* @file: main.cpp
* @brief: Contains the main function of the program
* @author: Part 1 - Aditya Khopkar (driver), Rajeshwar N S (navigator)
* @author: Part 2 - Spencer Elyard (driver), Daniel Sahu (navigator)
* */

#include <iostream>
#include <lib.hpp>
#include <vector>

#include "../include/PID.h"

int main()
{
dummy();
return 0;
/**
* @brief: main function
* @param: None
* @return: 0
* */
int main() {
control::PID controller;
double new_velocity = controller.Compute(4.0, 8.0);
std::cout << "Actual Velocity: " << 4.0 << " Desired Velocity: " << 8.0
<< " New Velocity: " << new_velocity << std::endl;
return 0;
}
89 changes: 89 additions & 0 deletions include/PID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Copyright 2020 <Aditya Khopkar> <Rajeshwar N S>
* */

/**
* @file: PID.h
* @brief: Contains the class declaration of PID control
* @author: Part 1 : Aditya Khopkar (driver), Rajeshwar N S (navigator)
* @author: Part 2 - Spencer Elyard (driver), Daniel Sahu (navigator)
* */

#pragma once

namespace control {
class PID {
private:
double kp_;
double ki_;
double kd_;
double dt_;
double prev_error_;
double integral_error_;

public:
/**
* @brief: Setter for kp
* @param: kp: double
* @return: None
* */
void SetKp(double);

/**
* @brief: Setter for kd
* @param: kd: double
* @return: None
* */
void SetKd(double);

/**
* @brief: Setter for ki
* @param: ki: double
* @return: None
* */
void SetKi(double);

/**
* @brief: Computes the new value of velocity given a setpoint and current
* value
* @param: feedback: double, setpoint: double
* @return: new velocity: double
* */
double Compute(double, double);

/**
* @brief: Getter for kp
* @param: None
* @return: const double value
* */
const double& GetKp();

/**
* @brief: Getter for kd
* @param: None
* @return: const double value
* */
const double& GetKd();

/**
* @brief: Getter for ki
* @param: None
* @return: const double value
* */
const double& GetKi();

/**
* @brief: Implementation of constructor
* @param: None
* @return: None
* */
PID();

/**
* @brief: Destructor call of class
* @param: None
* @return: None
* */
virtual ~PID();
};
} // namespace control
8 changes: 0 additions & 8 deletions include/lib.hpp

This file was deleted.

58 changes: 17 additions & 41 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# C++ Boilerplate
[![Build Status](https://travis-ci.org/dpiet/cpp-boilerplate.svg?branch=master)](https://travis-ci.org/dpiet/cpp-boilerplate)
[![Coverage Status](https://coveralls.io/repos/github/dpiet/cpp-boilerplate/badge.svg?branch=master)](https://coveralls.io/github/dpiet/cpp-boilerplate?branch=master)
# PID Controller (Test Driven Development)
[![Build Status](https://travis-ci.org/akhopkar01/PID_controller.svg?branch=master)](https://travis-ci.org/github/akhopkar01/PID_controller)
[![Coverage Status](https://coveralls.io/repos/github/akhopkar01/PID_controller/badge.svg?branch=master)](https://coveralls.io/github/akhopkar01/PID_controller?branch=master)
---

## Overview

Simple starter C++ project with:
This project is worked in groups to carry out TDD. We have implemented a PID controller with Unit Tests to validate software quality.

- cmake
- googletest
### Authors:
[ Part 1 ] Aditya Khopkar (driver), Rajeshwar N S (navigator)

[ Part 2 ] Spencer Elyard (driver), Daniel Sahu (navigator)

### TO-DO for future:
Investigate additional test-cases for compute

## Standard install via command-line
```
git clone --recursive https://github.com/dpiet/cpp-boilerplate
cd <path to repository>
git clone --recursive https://github.com/akhopkar01/PID_controller
cd PID_controller
mkdir build
cd build
cmake ..
Expand All @@ -39,24 +44,24 @@ In your Eclipse workspace directory (or create a new one), checkout the repo (an
```
mkdir -p ~/workspace
cd ~/workspace
git clone --recursive https://github.com/dpiet/cpp-boilerplate
git clone --recursive https://github.com/danielmohansahu/mobile-pid-controller
```

In your work directory, use cmake to create an Eclipse project for an [out-of-source build] of cpp-boilerplate
In your work directory, use cmake to create an Eclipse project for an [out-of-source build] of mobile-pid-controller

```
cd ~/workspace
mkdir -p boilerplate-eclipse
cd boilerplate-eclipse
cmake -G "Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug -D CMAKE_ECLIPSE_VERSION=4.7.0 -D CMAKE_CXX_COMPILER_ARG1=-std=c++14 ../cpp-boilerplate/
cmake -G "Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug -D CMAKE_ECLIPSE_VERSION=4.7.0 -D CMAKE_CXX_COMPILER_ARG1=-std=c++14 ../mobile-pid-controller/
```

## Import

Open Eclipse, go to File -> Import -> General -> Existing Projects into Workspace ->
Select "boilerplate-eclipse" directory created previously as root directory -> Finish

# Edit
## Edit

Source files may be edited under the "[Source Directory]" label in the Project Explorer.

Expand Down Expand Up @@ -95,32 +100,3 @@ debugger window.
7. Press Terminate icon to terminate debugging and press C/C++ icon to switch back to C/C++
perspetive view (or Windows->Perspective->Open Perspective->C/C++).


## Plugins

- CppChEclipse

To install and run cppcheck in Eclipse

1. In Eclipse, go to Window -> Preferences -> C/C++ -> cppcheclipse.
Set cppcheck binary path to "/usr/bin/cppcheck".

2. To run CPPCheck on a project, right click on the project name in the Project Explorer
and choose cppcheck -> Run cppcheck.


- Google C++ Sytle

To include and use Google C++ Style formatter in Eclipse

1. In Eclipse, go to Window -> Preferences -> C/C++ -> Code Style -> Formatter.
Import [eclipse-cpp-google-style][reference-id-for-eclipse-cpp-google-style] and apply.

2. To use Google C++ style formatter, right click on the source code or folder in
Project Explorer and choose Source -> Format

[reference-id-for-eclipse-cpp-google-style]: https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-cpp-google-style.xml

- Git

It is possible to manage version control through Eclipse and the git plugin, but it typically requires creating another project. If you're interested in this, try it out yourself and contact me on Canvas.
Loading