Commit fb78804d authored by markus's avatar markus

Fix ADC values and 0 destination

parent 4c0b9205
......@@ -87,10 +87,10 @@ Control::hamlibError Control::executeActiveCommandSubstring(String substring)
Motor::motorError err;
float dst = 0.0;
if (substring.startsWith("setaz") || substring.startsWith("setel")) {
if( substring.length() < 7 )
if( substring.length() < 6 )
return HAMLIB_NOK;
dst = substring.substring(5).toFloat();
if ( dst == 0 && substring.substring(5) != "0" )
if ( dst == 0 && (substring.substring(5) != "0"))
return HAMLIB_NOK;
if(substring.startsWith("setaz"))
err = rotor_->setAzimuth(dst);
......
#include "motor.h"
Motor::Motor(double max, double min, int down_pin, int up_pin, Brake* brake, int sensor_pin, double degree, double resolution, double span)
Motor::Motor(double max, double min, int down_pin, int up_pin, Brake* brake, int sensor_pin, double degree, int adc_offset, double resolution, double span)
{
max_ = max;
min_ = min;
......@@ -9,6 +9,7 @@ Motor::Motor(double max, double min, int down_pin, int up_pin, Brake* brake, int
degree_ = degree;
up_pin_ = up_pin;
down_pin_ = down_pin;
adc_offset_ = adc_offset;
sensor_pin_ = sensor_pin;
resolution_ = resolution;
......@@ -102,7 +103,7 @@ Motor::motorError Motor::setPosition(double destination)
Motor::motorError Motor::readMotSensor()
{
position_ = readADC(sensor_pin_)/degree_;
position_ = (readADC(sensor_pin_) - adc_offset_)/degree_;
return Motor::ROT_OK;
}
......
......@@ -12,7 +12,7 @@ public:
ROT_VAL_OUT_OF_RANGE,
ROT_BREAK_NOT_RELEASED,
ROT_ALREADY_IN_SPAN };
Motor(double max, double min, int down_pin, int up_pin, Brake *brake, int sensor_pin, double degree, double resolution, double span);
Motor(double max, double min, int down_pin, int up_pin, Brake *brake, int sensor_pin, double degree, int adc_offset, double resolution, double span);
void doMotor();
void stop();
double getPosition() const;
......@@ -32,6 +32,7 @@ private:
int down_pin_;
int up_pin_;
int sensor_pin_;
int adc_offset_;
double position_;
double destination_;
double degree_;
......
......@@ -3,8 +3,8 @@
Rotor::Rotor()
{
brake_ = new Brake(AZIM_RE_BREAK, 10000);
azimuth_ = new Motor(AZIM_MAX, AZIM_MIN, AZIM_RE_CW, AZIM_RE_CCW, brake_, AZIM_POT, AZIM_DEG, AZIM_RES, AZIM_SPAN);
elevation_ = new Motor(ELEV_MAX, ELEV_MIN, ELEV_RE_DWN, ELEV_RE_UP, brake_, ELEV_POT, ELEV_DEG, ELEV_RES, ELEV_SPAN);
azimuth_ = new Motor(AZIM_MAX, AZIM_MIN, AZIM_RE_CW, AZIM_RE_CCW, brake_, AZIM_POT, AZIM_DEG, AZIM_ADC_MIN, AZIM_RES, AZIM_SPAN);
elevation_ = new Motor(ELEV_MAX, ELEV_MIN, ELEV_RE_DWN, ELEV_RE_UP, brake_, ELEV_POT, ELEV_DEG, ELEV_ADC_MIN, ELEV_RES, ELEV_SPAN);
}
void Rotor::doRotor()
......
......@@ -20,8 +20,8 @@
#define ELEV_BREAK 1
// Allowed span in degree
#define AZIM_SPAN 5
#define ELEV_SPAN 3
#define AZIM_SPAN 1
#define ELEV_SPAN 1
// Max Values
#define AZIM_MIN 0.0
#define AZIM_MAX 359.0
......@@ -33,8 +33,8 @@
// ADC Values
#define AZIM_ADC_MIN 0
#define AZIM_ADC_MAX 1024
#define ELEV_ADC_MIN 0
#define ELEV_ADC_MAX 921
#define ELEV_ADC_MIN 98
#define ELEV_ADC_MAX 1013
#define AZIM_DEG ((AZIM_ADC_MAX-AZIM_ADC_MIN)/(AZIM_MAX-AZIM_MIN))
#define ELEV_DEG ((ELEV_ADC_MAX-ELEV_ADC_MIN)/(ELEV_MAX-ELEV_MIN))
......
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