Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Software Defined Radio
r0tor
Commits
fc4a6e57
Commit
fc4a6e57
authored
Jul 14, 2019
by
markus
Browse files
Refactor Rotor to have multiple Motors
parent
4b08b578
Changes
8
Hide whitespace changes
Inline
Side-by-side
shackremote_arduino/control.cpp
View file @
fc4a6e57
...
...
@@ -66,7 +66,7 @@ Control::hamlibError Control::executeCommandString(String *command_string, Commu
}
else
if
(
substring
==
"getpos"
)
{
// GNAAAARRR
communicator
->
sendMessage
(
String
(
rotor_
->
getA
ctualA
zimuth
())
+
"
.00
;"
+
String
(
rotor_
->
get
Actual
Elevation
())
+
"
.00
;"
);
communicator
->
sendMessage
(
String
(
rotor_
->
getAzimuth
())
+
";"
+
String
(
rotor_
->
getElevation
())
+
";"
);
}
else
if
(
substring
.
startsWith
(
"setaz"
)
)
{
if
(
substring
.
length
()
<
7
)
...
...
shackremote_arduino/control.h
View file @
fc4a6e57
...
...
@@ -24,8 +24,8 @@ private:
hamlibError
executeCommandString
(
String
*
,
Communicator
*
);
Rotor
*
rotor_
;
Serial
Communicator
*
serial_communicator_
;
UDP
Communicator
*
udp_communicator_
;
Communicator
*
serial_communicator_
;
Communicator
*
udp_communicator_
;
int
debugTime_
;
};
...
...
shackremote_arduino/hamlib.cpp
View file @
fc4a6e57
...
...
@@ -76,7 +76,7 @@ CHamlib::hamlibError CHamlib::parseHamlibPacket()
sendHamlibPacket
();
}
else
if
(
token
==
"get position"
)
{
sprintf
(
tx_packet_
,
"%f %f"
,
rotor_
->
getA
ctualA
zimuth
(),
rotor_
->
get
Actual
Elevation
());
sprintf
(
tx_packet_
,
"%f %f"
,
rotor_
->
getAzimuth
(),
rotor_
->
getElevation
());
packet_parsed_
=
true
;
sendHamlibPacket
();
}
...
...
shackremote_arduino/motor.cpp
0 → 100644
View file @
fc4a6e57
#include "motor.h"
Motor
::
Motor
(
double
max
,
double
min
,
int
down_pin
,
int
up_pin
,
int
break_pin
,
int
sensor_pin
,
double
degree
,
double
resolution
,
double
span
)
{
max_
=
max
;
min_
=
min
;
span_
=
span
;
degree_
=
degree
;
up_pin_
=
up_pin
;
down_pin_
=
down_pin
;
break_pin_
=
break_pin
;
sensor_pin_
=
sensor_pin
;
resolution_
=
resolution
;
//Pin Settings
pinMode
(
up_pin_
,
OUTPUT
);
pinMode
(
down_pin_
,
OUTPUT
);
pinMode
(
break_pin_
,
OUTPUT
);
//All Relais Off
digitalWrite
(
up_pin_
,
HIGH
);
digitalWrite
(
down_pin_
,
HIGH
);
digitalWrite
(
break_pin_
,
HIGH
);
should_rotate_
=
false
;
}
void
Motor
::
doMotor
()
{
double
diff
;
readMotSensor
();
if
(
should_rotate_
)
{
diff
=
position_
-
destination_
;
if
(
abs
(
diff
)
<
resolution_
)
stop
();
else
{
if
(
diff
>
0
)
rotateDown
();
else
rotateUp
();
}
}
}
Motor
::
motorError
Motor
::
rotateUp
()
{
releaseBreak
();
digitalWrite
(
down_pin_
,
HIGH
);
digitalWrite
(
up_pin_
,
LOW
);
return
Motor
::
ROT_OK
;
}
Motor
::
motorError
Motor
::
rotateDown
()
{
releaseBreak
();
digitalWrite
(
up_pin_
,
HIGH
);
digitalWrite
(
down_pin_
,
LOW
);
return
Motor
::
ROT_OK
;
}
void
Motor
::
releaseBreak
()
{
digitalWrite
(
break_pin_
,
LOW
);
}
void
Motor
::
tightenBreak
()
{
digitalWrite
(
break_pin_
,
HIGH
);
}
void
Motor
::
stop
()
{
should_rotate_
=
false
;
tightenBreak
();
digitalWrite
(
down_pin_
,
HIGH
);
digitalWrite
(
up_pin_
,
HIGH
);
}
double
Motor
::
getPosition
()
const
{
return
position_
;
}
Motor
::
motorError
Motor
::
setPosition
(
double
destination
)
{
if
(
destination
>=
min_
&&
destination
<=
max_
)
{
destination_
=
destination
;
if
(
abs
(
destination_
-
position_
)
>
span_
)
{
should_rotate_
=
true
;
return
Motor
::
ROT_OK
;
}
return
Motor
::
ROT_ALREADY_IN_SPAN
;
}
return
Motor
::
ROT_VAL_OUT_OF_RANGE
;
}
Motor
::
motorError
Motor
::
readMotSensor
()
{
position_
=
readADC
(
sensor_pin_
)
/
degree_
;
return
Motor
::
ROT_OK
;
}
double
Motor
::
readADC
(
int
AdcPin
)
{
//Read ADC 10 times and calculate average
uint32_t
adcValue
=
0
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
adcValue
+=
analogRead
(
AdcPin
);
delay
(
1
);
return
(((
double
)
adcValue
)
/
10
);
}
shackremote_arduino/motor.h
0 → 100644
View file @
fc4a6e57
#ifndef MOTOR_H
#define MOTOR_H
#include "Arduino.h"
class
Motor
{
public:
enum
motorError
{
ROT_OK
,
ROT_NOK
,
ROT_VAL_OUT_OF_RANGE
,
ROT_BREAK_NOT_RELEASED
,
ROT_ALREADY_IN_SPAN
};
Motor
(
double
max
,
double
min
,
int
down_pin
,
int
up_pin
,
int
break_pin
,
int
sensor_pin
,
double
degree
,
double
resolution
,
double
span
);
void
doMotor
();
double
getPosition
()
const
;
void
releaseBreak
();
void
tightenBreak
();
void
stop
();
motorError
setPosition
(
double
);
motorError
rotateUp
();
motorError
rotateDown
();
private:
motorError
readMotSensor
();
double
readADC
(
int
);
double
max_
;
double
min_
;
int
down_pin_
;
int
up_pin_
;
int
break_pin_
;
int
sensor_pin_
;
double
position_
;
double
destination_
;
double
degree_
;
double
resolution_
;
double
span_
;
byte
should_rotate_
;
};
#endif //MOTOR_H
shackremote_arduino/rotor.cpp
View file @
fc4a6e57
///
/// @file rotor.cpp
/// @copyright Christian Obersteiner, Andreas Müller - CC-BY-SA 4.0
///
/// @brief Contains all kind of rotor functions
///
#include "rotor.h"
///
/// @brief Constructor
///
Rotor
::
Rotor
()
{
initRotor
();
azimuth_
=
new
Motor
(
AZIM_MAX
,
AZIM_MIN
,
AZIM_RE_CW
,
AZIM_RE_CCW
,
AZIM_RE_BREAK
,
AZIM_POT
,
AZIM_DEG
,
AZIM_RES
,
AZIM_SPAN
);
elevation_
=
new
Motor
(
ELEV_MAX
,
ELEV_MIN
,
ELEV_RE_DWN
,
ELEV_RE_UP
,
ELEV_RE_BREAK
,
ELEV_POT
,
ELEV_DEG
,
ELEV_RES
,
ELEV_SPAN
);
}
///
/// @brief Initialize all ADC Values and set Arduino Pins to a defined value.
///
void
Rotor
::
initRotor
()
{
if
(
AZIM
)
{
//Pin Settings
pinMode
(
AZIM_RE_CW
,
OUTPUT
);
pinMode
(
AZIM_RE_CCW
,
OUTPUT
);
pinMode
(
AZIM_RE_BREAK
,
OUTPUT
);
//All Relais Off
digitalWrite
(
AZIM_RE_CW
,
HIGH
);
digitalWrite
(
AZIM_RE_CCW
,
HIGH
);
digitalWrite
(
AZIM_RE_BREAK
,
HIGH
);
//Initial Values
m_bAzimuthBreakReleased
=
0
;
m_bAzimuthCurrentlyRotating
=
0
;
m_bAzimuthShouldRotate
=
0
;
}
if
(
ELEV
)
{
//Pin Settings
pinMode
(
ELEV_RE_UP
,
OUTPUT
);
pinMode
(
ELEV_RE_DWN
,
OUTPUT
);
pinMode
(
ELEV_RE_BREAK
,
OUTPUT
);
//All Relais Off
digitalWrite
(
ELEV_RE_UP
,
HIGH
);
digitalWrite
(
ELEV_RE_DWN
,
HIGH
);
digitalWrite
(
ELEV_RE_BREAK
,
HIGH
);
//Initial Values
m_bElevationBreakReleased
=
0
;
m_bElevationCurrentlyRotating
=
0
;
m_bElevationShouldRotate
=
0
;
}
}
///
/// @brief Does all the rotor movement stuff
///
void
Rotor
::
doRotor
()
{
int
diff_elev
,
diff_azim
;
readRotSensors
();
if
(
AZIM
&&
m_bAzimuthShouldRotate
)
{
diff_azim
=
m_uActualAzimuth
-
m_uSetAzimuth
;
if
(
m_bAzimuthCurrentlyRotating
)
{
if
(
abs
(
diff_azim
)
<
AZIM_RES
)
stopAzimuth
();
else
{
if
(
diff_azim
>
0
)
rotateCW
();
else
rotateCCW
();
}
}
else
{
if
(
abs
(
diff_azim
)
>
AZIM_SPAN
)
{
releaseBreakAzimuth
();
if
(
diff_azim
>
0
)
rotateCW
();
else
rotateCCW
();
}
}
}
if
(
ELEV
&&
m_bElevationShouldRotate
)
{
diff_elev
=
m_uActualElevation
-
m_uSetElevation
;
if
(
m_bElevationCurrentlyRotating
)
{
if
(
abs
(
diff_elev
)
<
ELEV_RES
)
stopElevation
();
else
{
if
(
diff_elev
>
0
)
rotateDown
();
else
rotateUp
();
}
}
else
{
if
(
abs
(
diff_elev
)
>
ELEV_SPAN
)
{
releaseBreakElevation
();
if
(
diff_elev
>
0
)
rotateDown
();
else
rotateUp
();
}
}
}
if
(
!
m_bAzimuthCurrentlyRotating
&&
!
m_bElevationCurrentlyRotating
)
{
tightenBreakAzimuth
();
tightenBreakElevation
();
}
azimuth_
->
doMotor
();
elevation_
->
doMotor
();
}
void
Rotor
::
releaseBreakAzimuth
()
{
m_bAzimuthBreakReleased
=
1
;
digitalWrite
(
AZIM_RE_BREAK
,
LOW
);
azimuth_
->
releaseBreak
();
}
void
Rotor
::
releaseBreakElevation
()
{
m_bElevationBreakReleased
=
1
;
digitalWrite
(
ELEV_RE_BREAK
,
LOW
);
elevation_
->
releaseBreak
();
}
void
Rotor
::
tightenBreakAzimuth
()
{
m_bAzimuthBreakReleased
=
0
;
digitalWrite
(
AZIM_RE_BREAK
,
HIGH
);
azimuth_
->
tightenBreak
();
}
void
Rotor
::
tightenBreakElevation
()
{
m_bElevationBreakReleased
=
0
;
digitalWrite
(
ELEV_RE_BREAK
,
HIGH
);
elevation_
->
tightenBreak
();
}
void
Rotor
::
stopAzimuth
()
{
digitalWrite
(
AZIM_RE_CW
,
HIGH
);
digitalWrite
(
AZIM_RE_CCW
,
HIGH
);
m_bAzimuthCurrentlyRotating
=
0
;
m_bAzimuthShouldRotate
=
0
;
azimuth_
->
stop
();
}
void
Rotor
::
stopElevation
()
{
digitalWrite
(
ELEV_RE_UP
,
HIGH
);
digitalWrite
(
ELEV_RE_DWN
,
HIGH
);
m_bElevationCurrentlyRotating
=
0
;
m_bElevationShouldRotate
=
0
;
}
Rotor
::
rotorError
Rotor
::
rotateCW
()
{
if
(
m_bAzimuthBreakReleased
==
0
)
return
Rotor
::
ROT_BREAK_NOT_RELEASED
;
digitalWrite
(
AZIM_RE_CW
,
LOW
);
digitalWrite
(
AZIM_RE_CCW
,
HIGH
);
m_bAzimuthCurrentlyRotating
=
1
;
return
Rotor
::
ROT_OK
;
}
Rotor
::
rotorError
Rotor
::
rotateCCW
()
{
if
(
m_bAzimuthBreakReleased
==
0
)
return
Rotor
::
ROT_BREAK_NOT_RELEASED
;
digitalWrite
(
AZIM_RE_CW
,
HIGH
);
digitalWrite
(
AZIM_RE_CCW
,
LOW
);
m_bAzimuthCurrentlyRotating
=
1
;
return
Rotor
::
ROT_OK
;
elevation_
->
stop
();
}
R
otor
::
r
otorError
Rotor
::
rotate
Up
()
M
otor
::
m
otorError
Rotor
::
rotate
CW
()
{
if
(
m_bElevationBreakReleased
==
0
)
return
Rotor
::
ROT_BREAK_NOT_RELEASED
;
digitalWrite
(
ELEV_RE_UP
,
LOW
);
digitalWrite
(
ELEV_RE_DWN
,
HIGH
);
m_bElevationCurrentlyRotating
=
1
;
return
Rotor
::
ROT_OK
;
return
azimuth_
->
rotateDown
();
}
R
otor
::
r
otorError
Rotor
::
rotate
Down
()
M
otor
::
m
otorError
Rotor
::
rotate
CCW
()
{
if
(
m_bElevationBreakReleased
==
0
)
return
Rotor
::
ROT_BREAK_NOT_RELEASED
;
digitalWrite
(
ELEV_RE_UP
,
HIGH
);
digitalWrite
(
ELEV_RE_DWN
,
LOW
);
m_bElevationCurrentlyRotating
=
1
;
return
Rotor
::
ROT_OK
;
return
azimuth_
->
rotateUp
();
}
///
/// @brief Serial Debug output Function
///
void
Rotor
::
debugOut
()
Motor
::
motorError
Rotor
::
rotateUp
()
{
//debug Out
readRotSensors
();
Serial
.
println
(
"-----------------"
);
Serial
.
print
(
"Azim Value: "
);
Serial
.
println
(
m_uActualAzimuth
);
Serial
.
print
(
"Elev Value: "
);
Serial
.
println
(
m_uActualElevation
);
return
elevation_
->
rotateUp
();
}
///
/// @brief Returns the actual Azimuth value in degree
///
/// @return uint16 actual Azimuth value in degree
///
uint16
Rotor
::
getActualAzimuth
()
const
Motor
::
motorError
Rotor
::
rotateDown
()
{
return
m_uActualAzimuth
;
return
elevation_
->
rotateDown
()
;
}
///
/// @brief Returns the actual Elevation value in degree
///
/// @return actual Elevation value in degree
///
uint16
Rotor
::
getActualElevation
()
const
double
Rotor
::
getAzimuth
()
const
{
return
m_uActualEleva
tion
;
return
azimuth_
->
getPosi
tion
()
;
}
///
/// @brief Sets the actual Azimuth value in degree and checks valid range
///
/// @param pAzimuth Azimuth value to be set
///
/// @return Error Code
///
Rotor
::
rotorError
Rotor
::
setAzimuth
(
uint16
pAzimuth
)
double
Rotor
::
getElevation
()
const
{
if
(
pAzimuth
>=
AZIM_MIN
&&
pAzimuth
<=
AZIM_MAX
)
{
m_uSetAzimuth
=
pAzimuth
;
m_bAzimuthShouldRotate
=
1
;
return
Rotor
::
ROT_OK
;
}
else
{
return
Rotor
::
ROT_VAL_OUT_OF_RANGE
;
}
return
elevation_
->
getPosition
();
}
///
/// @brief Sets the actual Elevation value in degree and checks valid range
///
/// @param pElevation Elevation value to be set
///
/// @return Error Code
///
Rotor
::
rotorError
Rotor
::
setElevation
(
uint16
pElevation
)
Motor
::
motorError
Rotor
::
setAzimuth
(
double
pAzimuth
)
{
if
(
pElevation
>=
ELEV_MIN
&&
pElevation
<=
ELEV_MAX
)
{
m_uSetElevation
=
pElevation
;
m_bElevationShouldRotate
=
1
;
return
Rotor
::
ROT_OK
;
}
else
{
return
Rotor
::
ROT_VAL_OUT_OF_RANGE
;
}
return
azimuth_
->
setPosition
(
pAzimuth
);
}
///
/// @brief Reads out the Sensor values and stores them
///
/// @return Error Code
///
Rotor
::
rotorError
Rotor
::
readRotSensors
()
{
if
(
AZIM
)
m_uActualAzimuth
=
(
uint16
)(
readADC
(
AZIM_POT
)
/
AZIM_DEG
);
if
(
ELEV
)
m_uActualElevation
=
(
uint16
)(
readADC
(
ELEV_POT
)
/
ELEV_DEG
);
return
Rotor
::
ROT_OK
;
}
///
/// @brief Reads out an ADC Pin 4 times and returns the average
///
/// @param AdcPin ADC Pin to read
///
/// @return average ADC value
///
uint16
Rotor
::
readADC
(
int
AdcPin
)
Motor
::
motorError
Rotor
::
setElevation
(
double
pElevation
)
{
//Read ADC 4 times and calculate average
uint32_t
adcValue
=
0
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
adcValue
+=
analogRead
(
AdcPin
);
delay
(
1
);
adcValue
=
adcValue
/
10
;
return
(
uint16
)
adcValue
;
return
elevation_
->
setPosition
(
pElevation
);
}
shackremote_arduino/rotor.h
View file @
fc4a6e57
...
...
@@ -9,21 +9,16 @@
#define ROTOR_H
#include "settings.h"
#include "
Arduino
.h"
#include "
motor
.h"
class
Rotor
{
public:
enum
rotorError
{
ROT_OK
,
ROT_NOK
,
ROT_VAL_OUT_OF_RANGE
,
ROT_BREAK_NOT_RELEASED
};
Rotor
();
void
initRotor
();
void
doRotor
();
void
debugOut
();
uint16
getActual
Azimuth
()
const
;
uint16
getActual
Elevation
()
const
;
double
get
Azimuth
()
const
;
double
get
Elevation
()
const
;
void
releaseBreakAzimuth
();
void
releaseBreakElevation
();
...
...
@@ -32,27 +27,16 @@ public:
void
stopAzimuth
();
void
stopElevation
();
r
otorError
setAzimuth
(
uint16
);
r
otorError
setElevation
(
uint16
);
Motor
::
m
otorError
setAzimuth
(
double
);
Motor
::
m
otorError
setElevation
(
double
);
r
otorError
rotateCW
();
r
otorError
rotateCCW
();
r
otorError
rotateUp
();
r
otorError
rotateDown
();
Motor
::
m
otorError
rotateCW
();
Motor
::
m
otorError
rotateCCW
();
Motor
::
m
otorError
rotateUp
();
Motor
::
m
otorError
rotateDown
();
private:
rotorError
readRotSensors
();
uint16
readADC
(
int
);
uint16
m_uActualAzimuth
;
uint16
m_uActualElevation
;
uint16
m_uSetAzimuth
;
uint16
m_uSetElevation
;
byte
m_bAzimuthBreakReleased
;
byte
m_bElevationBreakReleased
;
byte
m_bAzimuthCurrentlyRotating
;
byte
m_bElevationCurrentlyRotating
;
byte
m_bAzimuthShouldRotate
;
byte
m_bElevationShouldRotate
;
Motor
*
azimuth_
;
Motor
*
elevation_
;
};
#endif //ROTOR_H
shackremote_arduino/shackremote_arduino.ino
View file @
fc4a6e57
...
...
@@ -13,7 +13,6 @@
#include "control.h"
#include "rotor.h"
#include "hamlib.h"
// Network Settings
/// @todo move to settings.h
...
...
@@ -22,15 +21,12 @@ IPAddress ip(83,133,178,126);
unsigned
int
localPort
=
51337
;
Rotor
rotor
;
CHamlib
hamlib
;
EthernetUDP
udp
;
Control
control
(
&
rotor
);
int
debugTime
;
void
setup
()
{
// Init
rotor
.
initRotor
();
// Open serial communications and wait for port to open:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment