Commit 19226815 authored by gdargaud's avatar gdargaud
Browse files

Removed all non-ascii characters. Changed a few parameters to global variables for easier setup

parent d0b9c22b
......@@ -45,11 +45,11 @@
#if defined(REMOTE) and REMOTE==1 // Use "make REMOTE=1"
// When in use through a ssh port redirection such as:
// ssh -YCL 5906:localhost:5900 -L 5001:192.168.0.20:5001 -L 22222:192.168.0.31:22222 -L 10011:192.168.0.11:23 -L 10012:192.168.0.12:23 -L 10013:192.168.0.13:23 ccob@lpsc2006x
static char IP[]="127.0.0.1";
static int Port=22222;
char Phytron_IP[]="127.0.0.1";
int Phytron_Port=22222;
#else // When in direct use
static char IP[]="192.168.0.31"; // This is defined by the dhcp server configuration. See /etc/dhcp/dhcpd.conf file
static int Port=22222;
char Phytron_IP[]="192.168.0.31"; // This is defined by the dhcp server configuration. See /etc/dhcp/dhcpd.conf file
int Phytron_Port=22222;
#endif
......@@ -64,20 +64,21 @@ static char Tabs[]="\t\t";
#define ID '0' // Device address
// For X command, see PH_AxisStatusRequest()
enum TcheckAxisStatus { powStageErr, powStageNormal,
enum TcheckAxisStatus { powStageErr, powStageNormal,
axisOnStandstill, axisInMotion,
axisAtMax, axisAtMin,
axisAtMax, axisAtMin,
checkStepFailure, checkStepSuccess,
emergencyStop, normalStop };
emergencyStop, normalStop };
enum { D_ALL, D_NO_REPLY, D_NONE }; // Display cmd&reply, just cmd or neither
static int Display=D_ALL; // Global to skip displaying some commands or replies
static int sock=0; // Socket
static int msWait=10; // Min delay between command and reply and new command. 50ms seems safe enough except for a few slow commands (see BigReply)
int Phytron_msWait=10; // Min delay between command and reply and new command. 50ms seems safe enough except for a few slow commands (see BigReply)
#define msleep(ms) usleep((ms)*1000) // ms sleep
static int msMotionPolling=500; // Same as above, but higher value to limit the number of polling messages
int Phytron_msMotionPolling=500; // Same as above, but higher value to limit the number of polling messages
static int Enabled=0;
static char LastErrMsg[1024]="";
#define PrintErr(f_, ...) sprintf(LastErrMsg, (f_), ##__VA_ARGS__), printf(BLD RED "%s%s\n" NRM, Tabs, LastErrMsg)
......@@ -113,13 +114,13 @@ int PH_Init(void) {
printf("%sSocket created for Phytron\n", Tabs);
// Prepare the sockaddr_in structure
server.sin_addr.s_addr = inet_addr(IP);
server.sin_addr.s_addr = inet_addr(Phytron_IP);
server.sin_family = AF_INET;
server.sin_port = htons( Port );
server.sin_port = htons( Phytron_Port );
// Connect to remote server
if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
PrintErr("Connect to %s:%d failed: %s", IP, Port, strerror(errno));
PrintErr("Connect to %s:%d failed: %s", Phytron_IP, Phytron_Port, strerror(errno));
return errno;
}
......@@ -171,7 +172,7 @@ int PH_SendCommand(char* Reply, const char* Command, ... ) {
}
if (Display!=D_NONE)
printf("Sent :%s%s\n", Tabs, Cmd);
msleep(msWait);
msleep(Phytron_msWait);
// Receive a reply from the server
// if (recv(sock, Reply, MAX_REPLY, 0) < 0) {
......@@ -195,7 +196,7 @@ int PH_SendCommand(char* Reply, const char* Command, ... ) {
if (Display==D_ALL)
printf("Reply:%s%s\n", Tabs, Reply);
msleep(msWait);
msleep(Phytron_msWait);
return 0;
}
......@@ -397,13 +398,13 @@ static char *ParameterTxt[NbP]={ // PT[n] indicates optional argument list, se
"not used",
"not used",
"Emergency stop ramp (in 4000-Hz/sec-steps)",
"fmax MØP run frequency during initializing (referencing) (Hz).",
"Ramp MØP (in 4000-Hz/sec-steps)",
"fmax M0P run frequency during initializing (referencing) (Hz).",
"Ramp M0P (in 4000-Hz/sec-steps)",
// 10
"fmin MØP Run frequency for leaving the limit switch range (Hz)",
"MØP offset for limit switch direction +",
"MØP offset for limit switch direction –",
"Recovery time MØP (msec)",
"fmin M0P Run frequency for leaving the limit switch range (Hz)",
"M0P offset for limit switch direction +",
"M0P offset for limit switch direction –",
"Recovery time M0P (msec)",
"fmax Run frequency during program operation (Hz)",
"Ramp for run frequency (P14) (in 4000-Hz/sec-steps (4000 to 500000 Hz/sec))",
"Recovery time position (ms)",
......@@ -411,7 +412,7 @@ static char *ParameterTxt[NbP]={ // PT[n] indicates optional argument list, se
"not used",
"Electronical zero counter (for setting operating points)", // FLOAT
// 20
"Mechanical zero counter (number of steps referred to the MØP)",
"Mechanical zero counter (number of steps referred to the M0P)",
"Absolute counter",
"Encoder counter", // Indicates the true encoder position.
"Axial limitation pos. direction + (0=no limitation)", // If the number of steps is reached, the run in + direction is aborted. 0 = no limitation
......@@ -442,7 +443,7 @@ static char *ParameterTxt[NbP]={ // PT[n] indicates optional argument list, se
"Current Shaping (CS), also see appendix A", // PT[46]
"Chopper frequency", // PT[47]
"Power stage type (read only)", // PT[48]
"Power stage temperature (°C)" // (only for linear power stage type)
"Power stage temperature (degC)" // (only for linear power stage type)
};
static char *PT[NbP][5]={ [1]={"rotational", "linear"},
......@@ -556,7 +557,7 @@ double PH_DbgGetPosition(double *P) {
P[19]=PH_GetParamValueF(19); // Electronical zero counter. Used for setting operating points. At standstill of the axis, P19 can be read or programmed during program execution.
// This has only a precision of 1 step
P[20]=PH_GetParamValue(20); // Mechanical zero counter. This counter contains the number of steps referred to the mechanical zero (MØP). Can be read at axis standstill. If the axis reaches the MØP, P20 will be set to zero.
P[20]=PH_GetParamValue(20); // Mechanical zero counter. This counter contains the number of steps referred to the mechanical zero (M0P). Can be read at axis standstill. If the axis reaches the M0P, P20 will be set to zero.
// This has only a precision of 1 step. Seems to be always the same as P[20]
P[21]=PH_GetParamValue(21); // Absolute counter. Encoder, multi turn and also for single turn.
......@@ -564,7 +565,7 @@ double PH_DbgGetPosition(double *P) {
// Only available if encoder is used, but... WTF is this value ? Seems to be P[19]*333.6
P[22]=PH_GetParamValue(22);
printf(BLD PRP "Pos:%s%.1f\n" NRM, Tabs, P2D(P[19])); // or 21 ?
printf(BLD PRP "Pos:%s%.1fdeg\n" NRM, Tabs, P2D(P[19])); // or 21 ?
return P2D(P[19]);
}
......@@ -575,7 +576,7 @@ double PH_GetPosition(void) {
// This is a double with 2 digits precision (so 1/100th step in theory),
// it's the most precise positioning parameter but must be zeroed at start
double P=PH_GetParamValueF(19); // Electronical zero counter. Used for setting operating points. At standstill of the axis, P19 can be read or programmed during program execution.
printf(BLD PRP "Pos:%s%.1f\n" NRM, Tabs, P2D(P));
printf(BLD PRP "Pos:%s%.1fdeg\n" NRM, Tabs, P2D(P));
return P2D(P);
}
......@@ -606,7 +607,7 @@ int PH_DoGetGeneralStatus(void) {
// For parameter values, see MA 1240-A008 EN, section 5
PH_SetParamValue(27, 0); // Initiator type, 0 = PNP normally closed contact (NCC)
PH_SetParamValue(8, 400); // fmax MØP (mechanical zero point). Run frequency during initializing (referencing) in Hz
PH_SetParamValue(8, 400); // fmax M0P (mechanical zero point). Run frequency during initializing (referencing) in Hz
for (int i=0; i<NbP; i++) // Get all parameters (and store them in an array)
if (0!=strcmp(ParameterTxt[i], "not used")) {
......@@ -676,8 +677,8 @@ int main(int argc, const char* argv[]) {
// PH_DoAct();
Ret|=PH_MoveToLimit(-1); // If no contactor, will stop after a timeout (18s I think. It's one of the parameters)
msleep(msMotionPolling);
while (PH_GetStatusAxes()) msleep(msMotionPolling);
msleep(Phytron_msMotionPolling);
while (PH_GetStatusAxes()) msleep(Phytron_msMotionPolling);
// PH_DbgGetPosition(Q[i]);
PAUSE;
......@@ -687,17 +688,17 @@ int main(int argc, const char* argv[]) {
double POS=90.;
Ret|=PH_SetParamValue(45, 1); // Full step. Default was 4
TB_Phytron_MoveAbs(POS);
printf("StepRes=%d, %.02f=%.02fpos, current=%.02f\n", StepRes, POS, D2P(POS), PH_GetPosition());
printf("StepRes=%d, %.02fdeg=%.02fpos, current=%.02fdeg\n", StepRes, POS, D2P(POS), PH_GetPosition());
TB_Phytron_MoveAbs(0);
Ret|=PH_SetParamValue(45, 10/*4*/); // Default
TB_Phytron_MoveAbs(POS);
printf("StepRes=%d, %.02f=%.02fpos, current=%.02f\n", StepRes, POS, D2P(POS), PH_GetPosition());
printf("StepRes=%d, %.02fdeg=%.02fpos, current=%.02fdeg\n", StepRes, POS, D2P(POS), PH_GetPosition());
TB_Phytron_MoveAbs(0);
Ret|=PH_SetParamValue(45, 100/*256*/); // Max resolution, very slow
TB_Phytron_MoveAbs(POS);
printf("StepRes=%d, %.02f=%.02fpos, current=%.02f\n", StepRes, POS, D2P(POS), PH_GetPosition());
printf("StepRes=%d, %.02fdeg=%.02fpos, current=%.02fdeg\n", StepRes, POS, D2P(POS), PH_GetPosition());
TB_Phytron_MoveAbs(0);
exit(1);
#endif
......@@ -708,12 +709,12 @@ int main(int argc, const char* argv[]) {
printf("\nArgv:%s%s\n", Tabs, argv[i]);
if (argv[i][0]=='@') { // If @ as first char: arbitrary command
PH_SendCommand(Reply, "%s", argv[i]+1);
//msleep(msMotionPolling);
//msleep(Phytron_msMotionPolling);
} else { // Otherwise assume numerical absolute moves
Ret|=PH_AbsPosition(atof(argv[i]));
if (Ret) break;
msleep(msMotionPolling);
while (PH_GetStatusAxes()) msleep(msMotionPolling);
msleep(Phytron_msMotionPolling);
while (PH_GetStatusAxes()) msleep(Phytron_msMotionPolling);
PH_DbgGetPosition(P[i]);
}
PAUSE;
......@@ -726,8 +727,8 @@ int main(int argc, const char* argv[]) {
for (i=1; i<argc; i++) {
Ret|=PH_AbsPosition(atof(argv[i]));
if (Ret) break;
msleep(msMotionPolling);
while (PH_GetStatusAxes()) msleep(msMotionPolling);
msleep(Phytron_msMotionPolling);
while (PH_GetStatusAxes()) msleep(Phytron_msMotionPolling);
PH_DbgGetPosition(Q[i]);
PAUSE;
}
......@@ -740,7 +741,7 @@ int main(int argc, const char* argv[]) {
Ret|=PH_EnAxisPowerStage(0); // Turn off
// Print positionnning test results. The first argv should be 0 for referencing
printf("\nParam:\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t22/19", 19, 19, 20, 20, 21, 21, 22, 22);
printf("\nParam:\t%d\t%ddeg\t%d\t%ddeg\t%d\t%ddeg\t%d\t%ddeg\t22/19", 19, 19, 20, 20, 21, 21, 22, 22);
for (i=1; i<argc; i++) {
double *p=P[i];
printf("\nArg:\t\t%.2f", atof(argv[i]));
......@@ -765,9 +766,9 @@ int main(int argc, const char* argv[]) {
Perr+=fabs(P2D(p[19])-atof(argv[i]));
}
if (argc>1) {
printf("\nnoenc average positionning error at StepRes=%d:\t%.2f\n\n", StepRes, Perr/(argc-1));
printf("\nnoenc average positionning error at StepRes=%d:\t%.2fdeg\n\n", StepRes, Perr/(argc-1));
#ifdef USE_ENCODER
printf("\nenc average positionning error at StepRes=%d:\t%.2f\n\n", StepRes, Qerr/(argc-1));
printf("\nenc average positionning error at StepRes=%d:\t%.2fdeg\n\n", StepRes, Qerr/(argc-1));
#endif
printf(BLD WHT "%s\n" NRM, TB_Phytron_Status());
......@@ -855,9 +856,9 @@ char* TB_Phytron_Status(void) {
int TB_Phytron_MoveAbs(double Angle) {
int Ret;
if (!Enabled) { PrintErr("The system is not ready, call TB_Phytron_Init() before"); return 1; }
// TODO: sanity check, but not really necessary as we have full 360 motion
// TODO: sanity check, but not really necessary as we have full 360deg motion
if ((Ret=PH_AbsPosition(Angle))) return Ret;
while (PH_GetStatusAxes()) msleep(msMotionPolling);
while (PH_GetStatusAxes()) msleep(Phytron_msMotionPolling);
// PH_DbgGetPosition(P[i]);
return 0;
}
......
#ifndef __TB_PHYTRON_H
#define __TB_PHYTRON_H
extern char Phytron_IP[80]; // This is defined by the dhcp server configuration. See /etc/dhcp/dhcpd.conf file
extern int Phytron_Port;
extern int Phytron_msWait; // Min delay between command and reply and new command. 50ms seems safe enough except for a few slow commands (see BigReply)
extern int Phytron_msMotionPolling; // Same as above, but higher value to limit the number of polling messages
// Low level commands
extern int PH_Init(void);
extern int PH_CloseAll(void);
......
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