Aufgrund einer Wartung wird GitLab am 25.01 zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 25.01 between 8:00 and 9:00 am.

Commit 5ffb29dc authored by Kai Volkenborn's avatar Kai Volkenborn
Browse files

changes 10.07

parent f9e26c33
#pragma once
extern bool debugEnabled;
#define PRINT(arg) if(debugEnabled) { Serial.print(arg); }
#define PRINTLN(arg) if(debugEnabled) { Serial.println(arg); }
\ No newline at end of file
......@@ -32,12 +32,6 @@ void DirectionControl::setup()
{
directionServo.attach(pin_servo, servoMinPulseWidth, servoMaxPulseWidth); // initialize servo
setDirection(0);
testServo();
}
void DirectionControl::updateController(double is)
{
}
/*
......@@ -56,8 +50,8 @@ int DirectionControl::getDirection()
*/
void DirectionControl::setDirection(int direction)
{
Serial.print("\t");
Serial.print(direction);
PRINT("\t");
PRINTLN(direction);
currentDirection = constrain(direction, directionLeft, directionRight);
if (currentDirection < directionServoCenter) {
const auto servoDir = map(direction,
......@@ -78,25 +72,18 @@ void DirectionControl::updateDirection()
{
const auto vLeft = analogRead(pin_spuleLeft);
const auto vRight = analogRead(pin_spuleRight);
Serial.print("Left: ");
Serial.print(vLeft);
Serial.print("\tRight: ");
Serial.print(vRight);
PRINT("Left: ");
PRINT(vLeft);
PRINT("\tRight: ");
PRINT(vRight);
const auto dif = vLeft - vRight;
const auto mappedDif = dif;
const auto out = controller.calcOutput(mappedDif);
const auto out = controller.calcOutput(dif);
setDirection(out);
}
//The following function needs modifications
void DirectionControl::testServo()
{
}
double DirectionControl::getControllerP()
{
return controller.getP();
......
......@@ -6,6 +6,7 @@
#include "PID.h"
#include <Servo.h>
#include "Debug.h"
extern const int pin_servo;
extern const int pin_spuleLeft;
......@@ -17,11 +18,9 @@ public:
DirectionControl();
void setup();
void testServo();
int getDirection();
void setDirection(int direction);
void updateDirection();
void updateController(double is);
double getControllerP();
double getControllerI();
......
......@@ -6,22 +6,22 @@
#include "uart.h"
bool debugEnabled = false;
// pin declaration
// do NOT use DigitalOut 0 & 1 (reserved for Serial)
const int pin_servo = 9;//pin for steering control
const int pin_motor = 6;//pin for motor control
const int pin_deadManSwitch = 13;//dead man swich pin
const int pin_spuleLeft = A0;//Left resonant circuit
const int pin_spuleRight = A1;//Right resonant circuit
const int pin_speedSensor = 3;//Input signal for speed sensor signal
constexpr int pin_servo = 9;//pin for steering control
constexpr int pin_motor = 6;//pin for motor control
constexpr int pin_deadManSwitch = 13;//dead man swich pin
constexpr int pin_spuleLeft = A0;//Left resonant circuit
constexpr int pin_spuleRight = A1;//Right resonant circuit
constexpr int pin_speedSensor = 3;//Input signal for speed sensor signal
// //init global variables and objects
DirectionControl directionControl = DirectionControl();
MotorControl motorControl = MotorControl();
SpeedSensor speedSensor = SpeedSensor();
void staticInitCode();
//The following function needs modifications
void setup()
{
......@@ -40,7 +40,7 @@ void setup()
//The following function needs modifications
void loop()
{
Serial.println();
//Serial.println();
//motorControl.setSpeed(100);
handleSerialInput();
//Serial.println(speedSensor.getSpeed());
......@@ -54,6 +54,7 @@ void loop()
}*/
directionControl.updateDirection();
motorControl.updateMotor();
delay(1);
}
//The following function needs modifications
......@@ -62,11 +63,6 @@ void speedInterrupt()
speedSensor.interrupt(micros());
}
//The following function needs modifications
int getAverage(int pin)
{
}
/**
* The following code must not be changed
......
......@@ -135,6 +135,7 @@
<ClInclude Include="..\..\..\..\Documents\Arduino\libraries\Servo\src\sam\ServoTimers.h" />
<ClInclude Include="..\..\..\..\Documents\Arduino\libraries\Servo\src\Servo.h" />
<ClInclude Include="..\..\..\..\Documents\Arduino\libraries\Servo\src\stm32f4\ServoTimers.h" />
<ClInclude Include="Debug.h" />
<ClInclude Include="DirectionControl.h">
<FileType>CppCode</FileType>
</ClInclude>
......
......@@ -138,6 +138,9 @@
<ClInclude Include="..\..\..\..\Documents\Arduino\libraries\Servo\src\stm32f4\ServoTimers.h">
<Filter>src\_micro-api-readonly\libraries\Servo</Filter>
</ClInclude>
<ClInclude Include="Debug.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DirectionControl.cpp">
......
......@@ -127,6 +127,24 @@ void setMotorSpeed(const char* args)
getMotorSpeed();
}
void getDebug(const char* args = nullptr)
{
Serial.print("debugEnabled = ");
Serial.println(debugEnabled);
Serial.flush();
}
void enableDebug(const char* args = nullptr)
{
debugEnabled = true;
getDebug();
}
void disableDebug(const char* args = nullptr)
{
debugEnabled = false;
getDebug();
}
#pragma endregion
//the following two arrays have to have the SAME number of elements each command corrosbinding to one function pointer
......@@ -135,6 +153,7 @@ const char* callbackName[] =
{ "getDirP","getDirI","getDirD","setDirP","setDirI","setDirD",
"getMotorP","getMotorI","getMotorD","setMotorP","setMotorI","setMotorD",
"getMotorSpeed", "setMotorSpeed",
"getDebug", "enableDebug", "disableDebug",
"help" };
//list of function pointer from above
// void (*callbackFunc[])(const char* args) =
......@@ -144,6 +163,7 @@ void (*callbackFunc[])(const char* args) =
{ getDirP, getDirI, getDirD, setDirP, setDirI, setDirD,
getMotorP, getMotorI, getMotorD, setMotorP, setMotorI, setMotorD,
getMotorSpeed, setMotorSpeed,
getDebug, enableDebug, disableDebug,
help };
......@@ -192,4 +212,4 @@ void handleSerialInput()
uartControl.bufferPos = 0;
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment