00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "amtec_base.h"
00038 #include "amtec_io.h"
00039 #include "amtec_commands.h"
00040 #include "amtec_conversion.h"
00041 #include "amtec_settings.h"
00042
00043 void AMTEC_set_settings(amtec_powercube_device_p dev, amtec_powercube_setting_p settings, amtec_powercube_params_p params)
00044 {
00045 if(params->MinPos != settings->MinPos) {
00046 amtecSetMinPos(dev, params->id, settings->MinPos);
00047 params->MinPos = settings->MinPos;
00048 }
00049 if(params->MaxPos != settings->MaxPos) {
00050 amtecSetMaxPos(dev, params->id, settings->MaxPos);
00051 params->MaxPos = settings->MaxPos;
00052 }
00053 if(params->MaxAcc != settings->MaxAcc) {
00054 amtecSetMaxAcc(dev, params->id, settings->MaxAcc);
00055 params->MaxAcc = settings->MaxAcc;
00056 }
00057 if(params->MaxVel != settings->MaxVel) {
00058 amtecSetMaxVel(dev, params->id, settings->MaxVel);
00059 params->MaxVel = settings->MaxVel;
00060 }
00061 if(params->TargetAcc != settings->TargetAcc) {
00062 amtecSetTargetAcc(dev, params->id, settings->TargetAcc);
00063 params->TargetAcc = settings->TargetAcc;
00064 }
00065 if(params->TargetVel != settings->TargetVel) {
00066 amtecSetTargetVel(dev, params->id, settings->TargetVel);
00067 params->TargetVel = settings->TargetVel;
00068 }
00069 if(params->MaxCur != settings->MaxCur) {
00070 amtecSetMaxCur(dev, params->id, settings->MaxCur);
00071 params->MaxCur = settings->MaxCur;
00072 }
00073
00074 if (settings->C0 != 0 && params->ActC0 != settings->C0) {
00075 amtecSetActC0(dev, params->id, settings->C0);
00076 }
00077 if (settings->Damp != 0 && params->ActDamp != settings->Damp) {
00078 amtecSetActDamp(dev, params->id, settings->Damp);
00079 }
00080 if (settings->A0 != 0 && params->ActA0 != settings->A0) {
00081 amtecSetActA0(dev, params->id, settings->A0);
00082 }
00083
00084 amtecRecalcPIDParam(dev, params->id);
00085
00086
00087
00088
00089
00090
00091 }
00092
00093 void amtecSetSettings(amtec_powercube_p powercube)
00094 {
00095 AMTEC_set_settings(&powercube->dev, &powercube->panset, &powercube->pan);
00096 AMTEC_set_settings(&powercube->dev, &powercube->tiltset, &powercube->tilt);
00097 }
00098
00099 void AMTEC_get_params(amtec_powercube_device_p dev, amtec_powercube_params_p params)
00100 {
00101 params->DefHomeOffset = amtecGetDefHomeOffset(dev, params->id);
00102 params->DefGearRatio = amtecGetDefGearRatio(dev, params->id);
00103 params->DefLinRatio = amtecGetDefLinRatio(dev, params->id);
00104 params->DefMinPos = amtecGetDefMinPos(dev, params->id);
00105 params->DefMaxPos = amtecGetDefMaxPos(dev, params->id);
00106 params->DefMaxDeltaVel = amtecGetDefMaxDeltaVel(dev, params->id);
00107 params->DefTorqueRatio = amtecGetDefTorqueRatio(dev, params->id);
00108 params->DefCurRatio = amtecGetDefCurRatio(dev, params->id);
00109 params->DefMaxVel = amtecGetDefMaxVel(dev, params->id);
00110 params->DefMaxAcc = amtecGetDefMaxAcc(dev, params->id);
00111 params->DefMaxCur = amtecGetDefMaxCur(dev, params->id);
00112 params->DefHomeVel = amtecGetDefHomeVel(dev, params->id);
00113 params->DefHomeAcc = amtecGetDefHomeAcc(dev, params->id);
00114
00115 params->DefCubeSerial = amtecGetDefCubeSerial(dev, params->id);
00116 params->DefConfig = amtecGetDefConfig(dev, params->id);
00117 params->DefPulsesPerTurn = amtecGetDefPulsesPerTurn(dev, params->id);
00118 params->DefCubeVersion = amtecGetDefCubeVersion(dev, params->id);
00119 params->DefServiceInterval = amtecGetDefServiceInterval(dev, params->id);
00120 params->DefBrakeTimeOut = amtecGetDefBrakeTimeOut(dev, params->id);
00121 params->DefAddress = amtecGetDefAddress(dev, params->id);
00122 params->DefPrimBaud = amtecGetDefPrimBaud(dev, params->id);
00123
00124 params->PosCount = amtecGetPosCount(dev, params->id);
00125 params->RefPosCount = amtecGetRefPosCount(dev, params->id);
00126 params->DioSetup = amtecGetDioSetup(dev, params->id);
00127 params->CubeState = amtecGetCubeState(dev, params->id);
00128 params->TargetPosInc = amtecGetTargetPosInc(dev, params->id);
00129 params->TargetVelInc = amtecGetTargetVelInc(dev, params->id);
00130 params->TargetAccInc = amtecGetTargetAccInc(dev, params->id);
00131 params->StepInc = amtecGetStepInc(dev, params->id);
00132
00133
00134 params->ActPos = amtecGetActPos(dev, params->id);
00135 params->ActVel = amtecGetActVel(dev, params->id);
00136 params->MinPos = amtecGetMinPos(dev, params->id);
00137 params->MaxPos = amtecGetMaxPos(dev, params->id);
00138 params->MaxVel = amtecGetMaxVel(dev, params->id);
00139 params->MaxAcc = amtecGetMaxAcc(dev, params->id);
00140
00141
00142 params->MaxCur = amtecGetMaxCur(dev, params->id);
00143 params->Config = amtecGetConfig(dev, params->id);
00144 params->UseBreak = (int)(((params->Config)>>3)&1);
00145
00146 params->ActC0 = amtecGetActC0(dev, params->id);
00147 params->ActDamp = amtecGetActDamp(dev, params->id);
00148 params->ActA0 = amtecGetActA0(dev, params->id);
00149 }
00150
00151 void amtecGetParams(amtec_powercube_p powercube)
00152 {
00153 AMTEC_get_params(&powercube->dev, &powercube->pan);
00154 AMTEC_get_params(&powercube->dev, &powercube->tilt);
00155 }
00156
00157 void PRINT_CubeState(unsigned long state)
00158 {
00159 int i;
00160 unsigned long v = state;
00161
00162 for(i = 0; i < 32; i++)
00163 fprintf(stderr, " %s", (v>>i & 1)==1?"+":"-");
00164 fprintf(stderr, "\r");
00165 }
00166
00167
00168
00169
00170