Skip to content

Commit 4d3814d

Browse files
committed
Add ks101 functions
1 parent 08b1841 commit 4d3814d

File tree

9 files changed

+516
-27
lines changed

9 files changed

+516
-27
lines changed

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ CFLAGS:=$(DEBUG_FLAGS) $(INCLUDE_FLAGS) $(OPTIMIZE_FLAGS) $(WARNING_FLAGS)
99

1010
all: libapt.a
1111

12-
libapt.a: libapt.o kpz101.o
13-
ar -cr libapt.a libapt.o kpz101.o; rm -r *.o
12+
libapt.a: libapt.o kpz101.o kst101.o
13+
ar -cr libapt.a libapt.o kpz101.o kst101.o; rm -r *.o
1414

1515
libapt.o: libapt.cpp
1616
$(CXX) $(CFLAGS) -c libapt.cpp $(LIBRARY_FLAGS)
1717

1818
kpz101.o: kpz101.cpp
1919
$(CXX) $(CFLAGS) -c kpz101.cpp $(LIBRARY_FLAGS)
2020

21+
kst101.o: kst101.cpp
22+
$(CXX) $(CFLAGS) -c kst101.cpp $(LIBRARY_FLAGS)
23+
2124
clean:
2225
rm -f libapt.a *.o
2326

examples/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ CFLAGS:=$(DEBUG_FLAGS) $(INCLUDE_FLAGS) $(OPTIMIZE_FLAGS) $(WARNING_FLAGS)
99
APT_LIB=-L.. -lapt
1010
APT_INCLUDE=-I..
1111

12-
TESTS = test_kpz101
12+
TESTS = test_kpz101 test_kst101
1313

1414
all: $(TESTS)
1515

1616
test_kpz101: libapt.a test_kpz101.cpp
1717
$(CXX) $(CFLAGS) $(APT_INCLUDE) -o test_kpz101 test_kpz101.cpp $(APT_LIB) $(LIBRARY_FLAGS)
1818

19+
test_kst101: libapt.a test_kst101.cpp
20+
$(CXX) $(CFLAGS) $(APT_INCLUDE) -o test_kst101 test_kst101.cpp $(APT_LIB) $(LIBRARY_FLAGS)
21+
1922
libapt.a:
2023
make -C ..
2124

examples/test_kst101.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <iostream>
2+
#include <unistd.h>
3+
4+
#include "kpz101.h"
5+
#include "kst101.h"
6+
7+
using namespace std;
8+
9+
// 1365330 = 0.0625mm on display
10+
// 136533 = 1 mm on zfs25
11+
12+
int main() {
13+
14+
aptserial::KST101 stepper1("/dev/ttyUSB1");
15+
sleep(1);
16+
cout << "-------------------------------------------------------" << "\n";
17+
cout << "HWInfo : [" << stepper1.getHWInfo().toString() << "]" << "\n";
18+
stepper1.setActuatorType(ST_ACTUATOR_TYPE::ACTUATOR_TYPE_ZFS_NEW_25MM);
19+
// stepper1.moveHome();
20+
cout << "absolute position : [" << (float)stepper1.getPosition_mm() << "]" << "\n";
21+
stepper1.setPositionAbsolute_mm(7);
22+
cout << "absolute position : [" << (float)stepper1.getPosition_mm() << "]" << "\n";
23+
stepper1.setPositionRelative_mm(-1.5);
24+
cout << "absolute position : [" << (float)stepper1.getPosition_mm() << "]" << "\n";
25+
26+
27+
aptserial::KST101 stepper2("/dev/ttyUSB2");
28+
sleep(1);
29+
cout << "-------------------------------------------------------" << "\n";
30+
cout << "HWInfo : [" << stepper2.getHWInfo().toString() << "]" << "\n";
31+
stepper2.setActuatorType(ST_ACTUATOR_TYPE::ACTUATOR_TYPE_ZFS_NEW_25MM);
32+
// stepper2.moveHome();
33+
cout << "absolute position : [" << (float)stepper2.getPosition_mm() << "]" << "\n";
34+
stepper2.setPositionAbsolute_mm(7);
35+
cout << "absolute position : [" << (float)stepper2.getPosition_mm() << "]" << "\n";
36+
stepper2.setPositionRelative_mm(-1.5);
37+
cout << "absolute position : [" << (float)stepper2.getPosition_mm() << "]" << "\n";
38+
39+
return 0;
40+
}

kpz101.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ const bool aptserial::stringToPositionControlMode(const std::string _positionCtr
6969
}
7070
return false;
7171
}
72+
// ====================================================================================================================
73+
7274

7375

76+
77+
// ====================================================================================================================
7478
aptserial::KPZ101::KPZ101(const std::string _deviceFileName) : APTDevice(_deviceFileName, APT_MGMSG_SRC_DEST_GENERIC_USB) {
7579
updateHWInfo();
7680
updateIOSettings();
@@ -92,7 +96,7 @@ void aptserial::KPZ101::setIOSettings(const PZ_VOLTAGE_RANGE _vRange, const PZ_A
9296

9397

9498
void aptserial::KPZ101::getIOSettings(PZ_VOLTAGE_RANGE& _vRange, PZ_ANALOG_INPUT_SOURCE& _analogInputSource) {
95-
std::vector<char> replyData = WriteRead(APT_MGMSG_PZ_REQ_TPZ_IOSETTINGS, APT_MGMSG_PZ_GET_TPZ_IOSETTINGS, m_idSrcDest, sizeof(uHeader)+sizeof(stChannelIOSettings));
99+
std::vector<char> replyData = Try_Write_Read(APT_MGMSG_PZ_REQ_TPZ_IOSETTINGS, APT_MGMSG_PZ_GET_TPZ_IOSETTINGS, m_idSrcDest, sizeof(uHeader)+sizeof(stChannelIOSettings));
96100

97101
if (replyData.size() == 0)
98102
throw SerialPortException("kpz101.cpp", "getIOSettings()", "Reply not received");
@@ -127,7 +131,7 @@ void aptserial::KPZ101::setInputVoltageSource(const PZ_INPUT_VOLTAGE_SOURCE _inp
127131

128132

129133
void aptserial::KPZ101::getInputVoltageSource(PZ_INPUT_VOLTAGE_SOURCE& _inputVoltageSource) {
130-
std::vector<char> replyData = WriteRead(APT_MGMSG_PZ_REQ_INPUTVOLTSSRC, APT_MGMSG_PZ_GET_INPUTVOLTSSRC, m_idSrcDest, sizeof(uHeader)+sizeof(stChannelSource));
134+
std::vector<char> replyData = Try_Write_Read(APT_MGMSG_PZ_REQ_INPUTVOLTSSRC, APT_MGMSG_PZ_GET_INPUTVOLTSSRC, m_idSrcDest, sizeof(uHeader)+sizeof(stChannelSource));
131135

132136
if (replyData.size() == 0)
133137
throw SerialPortException("kpz101.cpp", "getInputVoltageSource()", "Reply not received");
@@ -157,7 +161,7 @@ void aptserial::KPZ101::setPositionControlMode(const PZ_POSITION_CONTROL_MODE _p
157161

158162

159163
void aptserial::KPZ101::getPositionControlMode(PZ_POSITION_CONTROL_MODE& _positionControlMode) {
160-
std::vector<char> replyData = WriteRead(APT_MGMSG_PZ_REQ_POSCONTROLMODE, APT_MGMSG_PZ_GET_POSCONTROLMODE, m_idSrcDest);
164+
std::vector<char> replyData = Try_Write_Read(APT_MGMSG_PZ_REQ_POSCONTROLMODE, APT_MGMSG_PZ_GET_POSCONTROLMODE, m_idSrcDest);
161165

162166
if (replyData.size() == 0)
163167
throw SerialPortException("kpz101.cpp", "getPositionControlMode()", "Reply not received");
@@ -188,7 +192,7 @@ void aptserial::KPZ101::setOutputVoltage(const uint16_t _voltage_adu) {
188192

189193

190194
void aptserial::KPZ101::getOutputVoltage(uint16_t& _voltage_adu) {
191-
std::vector<char> replyData = WriteRead(APT_MGMSG_PZ_REQ_OUTPUTVOLTS, APT_MGMSG_PZ_GET_OUTPUTVOLTS, m_idSrcDest, sizeof(uHeader)+sizeof(stChannelValue));
195+
std::vector<char> replyData = Try_Write_Read(APT_MGMSG_PZ_REQ_OUTPUTVOLTS, APT_MGMSG_PZ_GET_OUTPUTVOLTS, m_idSrcDest, sizeof(uHeader)+sizeof(stChannelValue));
192196

193197
if (replyData.size() == 0)
194198
throw SerialPortException("kpz101.cpp", "getOutputVoltage()", "Reply not received");

kpz101.h

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "libapt.h"
77

8+
// KPZ101 - PREFIX : PZ
9+
810
typedef APT_STATE PZ_STATE;
911
#define PZ_STATE_LABELS APT_STATE_LABELS
1012

@@ -70,6 +72,7 @@ namespace aptserial {
7072

7173
const std::string positionControlModeToString(const PZ_POSITION_CONTROL_MODE _positionCtrlMode);
7274
const bool stringToPositionControlMode(const std::string _positionCtrlModeString, PZ_POSITION_CONTROL_MODE& _positionCtrlMode);
75+
// ==================================================================================================================
7376

7477
class KPZ101 : public APTDevice { // Piezo Controller
7578
struct stChannelValue { // page 174

0 commit comments

Comments
 (0)