-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTM_Communicator.h
176 lines (150 loc) · 5.09 KB
/
STM_Communicator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* STM_Communicator.h
* ------------------
* Header file for the STM_Communicator class. This object manages
* communication with the force clamp via TCP/IP communication.
*
* Created by John Whitworth on 8/26/14.
* Copyright 2015 Eileen Mazzochette, et al <[email protected]>
*/
#pragma once
#include "STM Convert.h"
#include "STMDispatch.h"
#include "STMSession.h"
using namespace System;
/* Class: STM_Communicator
* -----------------------
* This object inherits from the STMDispatch class and uses STM
* flatten and unflatten protocols to send and receive packets of
* data over TCP/IP.
*/
class STM_Communicator : public STMDispatch {
//properties
public:
//indicates if the HAWK is connected to the force clamp
bool connected;
//indicates if an actuation has been completed
bool stimulusCompleted;
//indicates if an actuation has started.
bool stimulusStarted;
//indicates the curent status of the actuator
int moving;
bool dataRead;
vector<double> piezoSignalData;
vector<double> actuatorPositionData;
vector<double> actuatorCommandData;
vector<double> desiredSignalData;
int messageReceivedCount;
double P_Parameter;
double I_Parameter;
double D_Parameter;
double clampModeParameter;
double triggerModeParameter;
double acquisitionFreqParameter;
double actuatorFreqParameter;
double waveTablePresentParameter;
double fifoMemoryFullParameter; // should be false, if true, there is a problem with the FPGA, don't trust data
double actuatorMovingParameter;
int reportedStimNum;
vector<double> reportedPiezoSignalData;
vector<double> reportedActuatorPositionData;
vector<double> reportedActuatorCommandData;
vector<double> reportedDesiredSignalData;
private:
//a communication session with the force clamp
STMSession STM;
//prototypes
public:
/* Function: STM_Communicator
* --------------------------
* Constructor for a STM_Communicator object. Sets the dispast for STM to this object,
* and connects to the IP and port of the force clamp.
*/
STM_Communicator();
/* Function: ~STM_Communicator
* ---------------------------
* Deconstructor for a STM_Communicator object. Disconnects before
* deconstruction.
*/
~STM_Communicator();
/* Function: triggerStimulus
* -------------------------
* Writes the write_Actuate command with a 1 argument.
*/
bool triggerStimulus(void);
/* Function: cancelStimulus
* ------------------------
* Writes the write_Actuate command with a 0 argument.
*/
void cancelStimulus(void);
/* Function: sendActuatorPosition
* ------------------------------
* Writes the write_ActuatorManual command along with the position to move
* the actuator to.
*/
void sendActuatorPosition(double position);
/* Function: sendWaveTable
* -----------------------
* Writes the write_ActuatorWaveTable command along with the waveTable in the
* message data.
*/
void sendWaveTable(double *waveTable, int arrSize);
/* Function: sendWaveInterval
* --------------------------
* Writes the write_WaveTableInterval command along with the time interval in
* microseconds between data points in the wave table. Possible values
* are 100, 1000, 10000, 100000, 1000000.
*/
void sendWaveInterval(int deltaT);
/* Function: sendAcquisitionInterval
* -----------------------
* Select the interval (int) between each acquired point in us. Maximum is 100 (10 kHz)
*/
void sendAcquisitionInterval(int deltaAcqusitionT);
/* Function: sendPIDParameters
* ---------------------------
* Writes the array of PID parameters: update the PID gains with an array of double (Pgain,Intgain,Derivgain,Anti-Windup)
*/
void sendPIDParameters(double *PIDParameters, int arrSize);
/* Function: sendTriggerMode
* -------------------------
* Select the trigger mode with an int (0:manual mode/no trigger, 1: wave table/1 trigger per table, 2: wave table/1 trigger per point)
*/
void sendTriggerMode(int triggerMode);
/* Function: write_ClampMode
*
* select the clamp mode with an int (0: open loop, 1: displacement clamp, 2: force clamp)
*/
void sendClampMode(int clampMode);
/* Function: getfpgaData
* --------------------------
* Get the data from the FPGA to be written to disk.
*/
void getfpgaData(int stimNum, vector<double> piezoSignalData, vector<double> actuatorPositionData, vector<double> actuatorCommandData, vector<double> desiredSignalData);
private:
/* Function: OnConnect
* -------------------
* Overwrites the OnConnect from STMDispatch. Sets the connected flag to true.
*/
void OnConnect();
/* Function: OnClose
* -----------------
* Overwrites the OnClose from STMDispatch. Sets the connected flag to false.
*/
void OnClose();
/* Function: OnNewData
* -------------------
* Overwrites the OnNewData from STMDispatch. Receives commands from the
* force clamp and handles them appropriately.
*/
void OnNewData(CString MetaName, CByteArray *MsgData);
/* Function: connect
* -----------------
* Connects to the force clamp via STM.
*/
void connect(CString ip, int port);
/* Function: disconnect
* --------------------
* Disconnects to the force clamp via STM.
*/
void disconnect(void);
};