Skip to content

Commit

Permalink
changing function heading
Browse files Browse the repository at this point in the history
  • Loading branch information
KATTA-00 committed Sep 6, 2023
1 parent 1b558f3 commit 30ce281
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/components/motors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void Motor::motorWrite(int16_t leftSpeed, int16_t rightSpeed)

// update the output variable
// update the angle and use it with pid
double Motor::updateOutput(){
void Motor::updateOutput(){

if (!goingStraight)
{
Expand Down
33 changes: 16 additions & 17 deletions src/components/motors.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,37 @@

#include "define.h"

// define the const for the pid
#define KP_FOWARD 0.5 // 0.6
// define the const for the pid
#define KP_FOWARD 0.5 // 0.6
#define KI_FOWARD 0.005 // 0.01
#define KD_FOWARD 0.005 // 0.01
// define the rates of kp, ki and kd
#define KP_RATE 0.02
#define KI_RATE 0.005
#define KD_RATE 0.005
#define KI_RATE 0.005
#define KD_RATE 0.005

#define SET_TIME_FOWARD 20

// motor class that contains basic functionality for the motors
class Motor
{
public:
Motor();
public:
Motor();

void setup_motors(); // initalize the left and right motor
void ML(int16_t val); // write to left motor
void MR(int16_t val); // write to right motor
void setup_motors(); // initalize the left and right motor
void ML(int16_t val); // write to left motor
void MR(int16_t val); // write to right motor

void motorWrite(int16_t leftSpeed, int16_t rightSpeed); // write to left motor and right motor
void motorWrite(int16_t leftSpeed, int16_t rightSpeed); // write to left motor and right motor

double updateOutput(); // update to output respect to the angle error and const
void tunning(int16_t leftSpeed, int16_t rightSpeed); // tune the Kp, KI and Kd
void updateOutput(); // update to output respect to the angle error and const
void tunning(int16_t leftSpeed, int16_t rightSpeed); // tune the Kp, KI and Kd

private:
bool goingStraight = false; // check if the bot is going staight forward
double setPoint, input, output;
private:
bool goingStraight = false; // check if the bot is going staight forward
double setPoint, input, output;

PID pid = PID(&input, &output, &setPoint, KP_FOWARD, KI_FOWARD, KD_FOWARD, DIRECT); // pid instance for the motors

PID pid = PID(&input, &output, &setPoint, KP_FOWARD, KI_FOWARD, KD_FOWARD, DIRECT); // pid instance for the motors
};

void pulse(int pulsetime, int time);
Expand Down
17 changes: 13 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,18 @@ void setup()
void loop()
{
// Serial.println("Loop");
motor.motorWrite(80, 80);
delay(5000);
motor.motorWrite(-80,-80);
delay(5000);
unsigned long startTime = millis();
while ((millis() - startTime) < 3000)
{
motor.motorWrite(80, 80);
delay(10);
}

startTime = millis();

while ((millis() - startTime) < 3000)
{
motor.motorWrite(-80, -80);
delay(10);
}
}

0 comments on commit 30ce281

Please sign in to comment.