Skip to content

Commit 8ed7bf5

Browse files
Merge branch 'master'.
1 parent b479c74 commit 8ed7bf5

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

lib/pid/PID_v1.cpp renamed to lib/pid/pid_v1.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
* based on Arduino PID Library - Version 1.1.1 by Brett Beauregard <br3ttb@gmail.com> brettbeauregard.com, licensed under a GPLv3 License
1111
*/
1212

13-
#include "PID_v1.h"
13+
#include "pid_v1.h"
1414

1515

16-
Pid::Pid(pid_t& input, pid_t& output, pid_t &setpoint, const pid_t kp, const pid_t ki, const pid_t kd, const bool direction) :
17-
input_ { input }, output_ { output }, setpoint_ { setpoint }, out_min_ { 0 }, out_max_ { 255 }, in_auto_ { false },
18-
direction_ { direction }, sample_time_ { 100 }, last_time_ { 0 } {
16+
Pid::Pid(pid_t& input, pid_t& output, pid_t& setpoint, const pid_t kp, const pid_t ki, const pid_t kd, const bool direction)
17+
: input_ { input }, output_ { output }, setpoint_ { setpoint }, out_min_ { 0 }, out_max_ { 255 }, in_auto_ { false }, direction_ { direction },
18+
sample_time_ { 100 }, last_time_ { 0 } {
1919
set_tunings(kp, ki, kd);
2020

2121
initialize();
2222
}
2323

2424
bool Pid::compute(const uint32_t time_ms) {
25-
if (! in_auto_) {
25+
if (!in_auto_) {
2626
return false;
2727
}
2828

@@ -73,7 +73,7 @@ void Pid::set_tunings(const pid_t kp, const pid_t ki, const pid_t kd) {
7373
ki_ = ki * sample_time_s;
7474
kd_ = kd / sample_time_s;
7575

76-
if (! direction_) {
76+
if (!direction_) {
7777
kp_ = (0.f - kp_);
7878
ki_ = (0.f - ki_);
7979
kd_ = (0.f - kd_);
@@ -111,7 +111,7 @@ void Pid::set_output_limits(const pid_t min, const pid_t max) {
111111

112112
void Pid::set_mode(const Modes new_mode) {
113113
const bool new_auto { new_mode == Modes::AUTOMATIC };
114-
if (new_auto && ! in_auto_) {
114+
if (new_auto && !in_auto_) {
115115
/* we just went from manual to auto mode */
116116
initialize();
117117
}

lib/pid/PID_v1.h renamed to lib/pid/pid_v1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#ifndef PID_v1_h
1313
#define PID_v1_h
14-
#define LIBRARY_VERSION 1.2.0
14+
#define LIBRARY_VERSION 1.2.0
1515

1616
#include <cstdint>
1717

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
; http://docs.platformio.org/page/projectconf.html
1010

1111
[env:1284p16m]
12-
platform = atmelavr
12+
platform = https://github.com/tsandmann/platform-atmelavr.git
1313
board = 1284p16m
1414
board_build.f_cpu = 16000000UL
1515
;board_build.f_cpu = 20000000UL
1616
;build_unflags = -std=gnu++11 -flto
1717
build_unflags = -std=gnu++11
18-
build_flags = -std=gnu++14 -flto -Wextra
18+
build_flags = -std=gnu++14 -Wextra
1919
;build_flags = -std=gnu++14
2020
;build_flags = -std=gnu++14 -save-temps -fverbose-asm -dA

src/speed_control.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@
2626
#include "ctbot.h"
2727
#include "scheduler.h"
2828

29-
#include <PID_v1.h>
29+
#include <pid_v1.h>
3030
#include <cmath>
3131

3232

3333
namespace ctbot {
3434

3535
std::list<SpeedControl*> SpeedControl::controller_list_;
3636

37-
SpeedControl::SpeedControl(Encoder& wheel_enc, Motor& motor) : direction_ { true }, setpoint_ { 0.f }, kp_ { 40 }, ki_ { 30 }, kd_ { 0 },
38-
p_pid_controller_ { new Pid(input_, output_, setpoint_, kp_, ki_, kd_, true) }, wheel_encoder_ { wheel_enc }, motor_ { motor } {
39-
if (! p_pid_controller_) {
37+
SpeedControl::SpeedControl(Encoder& wheel_enc, Motor& motor)
38+
: direction_ { true }, setpoint_ {}, input_ {}, output_ {}, kp_ { 40.f }, ki_ { 30.f }, kd_ { 0.f },
39+
p_pid_controller_ { new Pid(input_, output_, setpoint_, kp_, ki_, kd_, true) }, wheel_encoder_ { wheel_enc }, motor_ { motor } {
40+
if (!p_pid_controller_) {
4041
return;
4142
}
4243

@@ -57,7 +58,7 @@ SpeedControl::~SpeedControl() {
5758
}
5859

5960
void SpeedControl::run() {
60-
if (! p_pid_controller_) {
61+
if (!p_pid_controller_) {
6162
return;
6263
}
6364

@@ -76,7 +77,7 @@ void SpeedControl::run() {
7677
}
7778

7879
void SpeedControl::set_parameters(const float kp, const float ki, const float kd) {
79-
if (! p_pid_controller_) {
80+
if (!p_pid_controller_) {
8081
return;
8182
}
8283

@@ -87,8 +88,6 @@ void SpeedControl::set_parameters(const float kp, const float ki, const float kd
8788
}
8889

8990
void SpeedControl::controller(void*) {
90-
// std::cout << "SpeedControl::controller(): running speed controller at " << Timer::get_ms() << " ms\n";
91-
9291
for (auto p_ctrl : controller_list_) {
9392
p_ctrl->run();
9493
}

0 commit comments

Comments
 (0)