amtec_commands.c
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2008, Robert Bosch LLC.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the Robert Bosch nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  *********************************************************************/
00036  
00037 #include "amtec_io.h"
00038 #include "amtec_conversion.h"
00039 #include "amtec_commands.h"
00040 
00041 /**********************************************************/
00042 /*               POWERCUBE COMMANDS */
00043 /**********************************************************/
00044 
00045 void cmdReset(amtec_powercube_device_p dev, int id)
00046 {
00047   unsigned char cmd[1];
00048   cmd[0] = CodeReset;
00049   amtecSendCommand(dev, id, cmd, 1);
00050 }
00051 
00052 void cmdHome(amtec_powercube_device_p dev, int id)
00053 {
00054   unsigned char cmd[1];
00055   cmd[0] = CodeHome;
00056   amtecSendCommand(dev, id, cmd, 1);
00057 }
00058 
00059 void cmdHalt(amtec_powercube_device_p dev, int id)
00060 {
00061   unsigned char cmd[1];
00062   cmd[0] = CodeHalt;
00063   amtecSendCommand(dev, id, cmd, 1);
00064 }
00065 
00066 void cmdRecalcPIDParam(amtec_powercube_device_p dev, int id)
00067 {
00068   unsigned char cmd[1];
00069   cmd[0] = CodeRecalcPIDParam;
00070   amtecSendCommand(dev, id, cmd, 1);
00071 }
00072 
00073 void cmdResetTime(amtec_powercube_device_p dev, int id)
00074 {
00075   unsigned char cmd[1];
00076   cmd[0] = CodeResetTime;
00077   amtecSendCommand(dev, id, cmd, 1);
00078 }
00079 
00080 void cmdGetExtended(amtec_powercube_device_p dev, int id, unsigned char code)
00081 {
00082   unsigned char cmd[2];
00083   cmd[0] = CodeGetExtended;
00084   cmd[1] = code;
00085   amtecSendCommand(dev, id, cmd, 2);
00086 }
00087 
00088 void cmdSetExtendedInt8(amtec_powercube_device_p dev, int id, unsigned char code, char val)
00089 {
00090   unsigned char cmd[3];
00091   cmd[0] = CodeSetExtended;
00092   cmd[1] = code;
00093   convertInt8(val, &(cmd[2]));
00094   amtecSendCommand(dev, id, cmd, 3);
00095 }
00096 
00097 void cmdSetExtendedUInt8(amtec_powercube_device_p dev, int id, unsigned char code, unsigned char val)
00098 {
00099   unsigned char cmd[3];
00100   cmd[0] = CodeSetExtended;
00101   cmd[1] = code;
00102   convertUInt8(val, &(cmd[2]));
00103   amtecSendCommand(dev, id, cmd, 3);
00104 }
00105 
00106 void cmdSetExtendedInt16(amtec_powercube_device_p dev, int id, unsigned char code, short val)
00107 {
00108   unsigned char cmd[4];
00109   cmd[0] = CodeSetExtended;
00110   cmd[1] = code;
00111   convertInt16(val, &(cmd[2]));
00112   amtecSendCommand(dev, id, cmd, 4);
00113 }
00114 
00115 void cmdSetExtendedUInt16(amtec_powercube_device_p dev, int id, unsigned char code, unsigned short val)
00116 {
00117   unsigned char cmd[4];
00118   cmd[0] = CodeSetExtended;
00119   cmd[1] = code;
00120   convertUInt16(val, &(cmd[2]));
00121   amtecSendCommand(dev, id, cmd, 3);
00122 }
00123 
00124 void cmdSetExtendedInt32(amtec_powercube_device_p dev, int id, unsigned char code, int val)
00125 {
00126   unsigned char cmd[6];
00127   cmd[0] = CodeSetExtended;
00128   cmd[1] = code;
00129   convertInt32(val, &(cmd[2]));
00130   amtecSendCommand(dev, id, cmd, 3);
00131 }
00132 
00133 void cmdSetExtendedUInt32(amtec_powercube_device_p dev, int id, unsigned char code, unsigned int val)
00134 {
00135   unsigned char cmd[6];
00136   cmd[0] = CodeSetExtended;
00137   cmd[1] = code;
00138   convertUInt32(val, &(cmd[2]));
00139   amtecSendCommand(dev, id, cmd, 6);
00140 }
00141 
00142 void cmdSetExtendedFloat(amtec_powercube_device_p dev, int id, unsigned char code, float val)
00143 {
00144   unsigned char cmd[6];
00145   cmd[0] = CodeSetExtended;
00146   cmd[1] = code;
00147   convertFloat(val, &(cmd[2]));
00148   amtecSendCommand(dev, id, cmd, 6);
00149 }
00150 
00151 void cmdSetMotionInt16(amtec_powercube_device_p dev, int id, unsigned char code, short val)
00152 {
00153   unsigned char cmd[4];
00154   cmd[0] = CodeSetMotion;
00155   cmd[1] = code;
00156   convertInt16(val, &(cmd[2]));
00157   amtecSendCommand(dev, id, cmd, 4);
00158 }
00159 
00160 void cmdSetMotionInt32(amtec_powercube_device_p dev, int id, unsigned char code, int val)
00161 {
00162   unsigned char cmd[6];
00163   cmd[0] = CodeSetMotion;
00164   cmd[1] = code;
00165   convertInt32(val, &(cmd[2]));
00166   amtecSendCommand(dev, id, cmd, 6);
00167 }
00168 
00169 void cmdSetMotionFloat(amtec_powercube_device_p dev, int id, unsigned char code, float val)
00170 {
00171   unsigned char cmd[6];
00172   cmd[0] = CodeSetMotion;
00173   cmd[1] = code;
00174   convertFloat(val, &(cmd[2]));
00175   amtecSendCommand(dev, id, cmd, 6);
00176 }
00177 
00178 void cmdSetFStepMotion(amtec_powercube_device_p dev, int id, unsigned char code, float val1, unsigned short val2)
00179 {
00180   unsigned char cmd[8];
00181   cmd[0] = CodeSetMotion;
00182   cmd[1] = code;
00183   convertFloat(val1, &(cmd[2]));
00184   convertUInt16(val2, &(cmd[6]));
00185   amtecSendCommand(dev, id, cmd, 8);
00186 }
00187 
00188 void cmdSetIStepMotion(amtec_powercube_device_p dev, int id, unsigned char code, int val1, unsigned short val2)
00189 {
00190   unsigned char cmd[8];
00191   cmd[0] = CodeSetMotion;
00192   cmd[1] = code;
00193   convertInt32(val1, &(cmd[2]));
00194   convertUInt16(val2, &(cmd[6]));
00195   amtecSendCommand(dev, id, cmd, 8);
00196 }
00197 
00198 void cmdSetMotionLoop(amtec_powercube_device_p dev, int id, unsigned char code, float pos, unsigned short period)
00199 {
00200   unsigned char cmd[8];
00201   cmd[0] = CodeSetMotion;
00202   cmd[1] = code;
00203   convertFloat(pos, &(cmd[2]));
00204   convertUInt16(period, &(cmd[6]));
00205   amtecSendCommand(dev, id, cmd, 8);
00206 }
00207 
00208 /**********************************************************/
00209 /*      POWERCUBE SPECIAL SET EXTENDED COMMANDS */
00210 /**********************************************************/
00211 
00212 void cmdSetMinPos(amtec_powercube_device_p dev, int id, float pos)
00213 {
00214   cmdSetExtendedFloat(dev, id, CodeMinPos, pos);
00215 }
00216 
00217 void cmdSetMaxPos(amtec_powercube_device_p dev, int id, float pos)
00218 {
00219   cmdSetExtendedFloat(dev, id, CodeMaxPos, pos);
00220 }
00221 
00222 void cmdSetMaxVel(amtec_powercube_device_p dev, int id, float vel)
00223 {
00224   cmdSetExtendedFloat(dev, id, CodeMaxVel, vel);
00225 }
00226 
00227 void cmdSetMaxAcc(amtec_powercube_device_p dev, int id, float acc)
00228 {
00229   cmdSetExtendedFloat(dev, id, CodeMaxAcc, acc);
00230 }
00231 
00232 void cmdSetMaxCur(amtec_powercube_device_p dev, int id, float cur)
00233 {
00234   cmdSetExtendedFloat(dev, id, CodeMaxCur, cur);
00235 }
00236 
00237 void cmdSetTargetVel(amtec_powercube_device_p dev, int id, float vel)
00238 {
00239   cmdSetExtendedFloat(dev, id, CodeTargetVel, vel);
00240 }
00241 
00242 void cmdSetTargetAcc(amtec_powercube_device_p dev, int id, float acc)
00243 {
00244   cmdSetExtendedFloat(dev, id, CodeTargetAcc, acc);
00245 }
00246 
00247 void cmdSetConfig(amtec_powercube_device_p dev, int id, unsigned int conf)
00248 {
00249   cmdSetExtendedUInt32(dev, id, CodeConfig, conf);
00250 }
00251 
00252 void cmdSetActC0(amtec_powercube_device_p dev, int id, short c0)
00253 {
00254   cmdSetExtendedInt16(dev, id, CodeActC0, c0);
00255 }
00256 
00257 void cmdSetActDamp(amtec_powercube_device_p dev, int id, short damp)
00258 {
00259   cmdSetExtendedInt16(dev, id, CodeActDamp, damp);
00260 }
00261 
00262 void cmdSetActA0(amtec_powercube_device_p dev, int id, short a0)
00263 {
00264   cmdSetExtendedInt16(dev, id, CodeActA0, a0);
00265 }
00266 
00267 /**********************************************************/
00268 /*                    CODE CHECK */
00269 /**********************************************************/
00270 int getCorrectResetCode(unsigned char *buf, int len)
00271 {
00272   if(len<3 || buf[2]!=CodeReset)
00273     return(0);
00274   return(1);
00275 }
00276 
00277 int getCorrectHomeCode(unsigned char *buf, int len)
00278 {
00279   if(len<3 || buf[2]!=CodeHome)
00280     return(0);
00281   return(1);
00282 }
00283 
00284 int getCorrectHaltCode(unsigned char *buf, int len)
00285 {
00286   if(len<3 || buf[2]!=CodeHalt)
00287     return(0);
00288   return(1);
00289 }
00290 
00291 int getCorrectRecalcPIDParam(unsigned char *buf, int len)
00292 {
00293   if(len<3 || buf[2]!=CodeRecalcPIDParam)
00294     return(0);
00295   return(1);
00296 }
00297 
00298 int getCorrectResetTime(unsigned char *buf, int len)
00299 {
00300   if(len<3 || buf[2]!=CodeResetTime)
00301     return(0);
00302   return(1);
00303 }
00304 
00305 int getCorrectSetExtCode(unsigned char *buf, int len, unsigned char code)
00306 {
00307   if(len<4 || buf[2]!=CodeSetExtended || buf[3]!=code)
00308     return(0);
00309   return(1);
00310 }
00311 
00312 int getCorrectSetMotionCode(unsigned char *buf, int len, unsigned char code)
00313 {
00314   if(len<4 || buf[2]!=CodeSetMotion || buf[3]!=code)
00315     return(0);
00316   return(1);
00317 }
00318 
00319 int getCorrectGetExtInt8(unsigned char *buf, int len, unsigned char code, char *val)
00320 {
00321   if(len<4 || buf[2]!=CodeGetExtended || buf[3]!=code)
00322     return(0);
00323   *val = convertBytes2Int8(&(buf[4]));
00324   return(1);
00325 }
00326 
00327 int getCorrectGetExtUInt8(unsigned char *buf, int len, unsigned char code, unsigned char *val)
00328 {
00329   if(len<4 || buf[2]!=CodeGetExtended || buf[3]!=code)
00330     return(0);
00331   *val = convertBytes2UInt8(&(buf[4]));
00332   return(1);
00333 }
00334 
00335 int getCorrectGetExtInt16(unsigned char *buf, int len, unsigned char code, short *val)
00336 {
00337   if(len<4 || buf[2]!=CodeGetExtended || buf[3]!=code)
00338     return(0);
00339   *val = convertBytes2Int16(&(buf[4]));
00340   return(1);
00341 }
00342 
00343 int getCorrectGetExtUInt16(unsigned char *buf, int len, unsigned char code, unsigned short *val)
00344 {
00345   if(len<4 || buf[2]!=CodeGetExtended || buf[3]!=code)
00346     return(0);
00347   *val = convertBytes2UInt16(&(buf[4]));
00348   return(1);
00349 }
00350 
00351 int getCorrectGetExtInt32(unsigned char *buf, int len, unsigned char code, int *val)
00352 {
00353   if(len<4 || buf[2]!=CodeGetExtended || buf[3]!=code)
00354     return(0);
00355   *val = convertBytes2Int32(&(buf[4]));
00356   return(1);
00357 }
00358 
00359 int getCorrectGetExtUInt32(unsigned char *buf, int len, unsigned char code, unsigned int *val)
00360 {
00361   if(len<4 || buf[2]!=CodeGetExtended || buf[3]!=code)
00362     return(0);
00363   *val = convertBytes2UInt32(&(buf[4]));
00364   return(1);
00365 }
00366 
00367 int getCorrectGetExtFloat(unsigned char *buf, int len, unsigned char code, float *val)
00368 {
00369   if(len<4 || buf[2]!=CodeGetExtended || buf[3]!=code)
00370     return(0);
00371   *val = convertBytes2Float(&(buf[4]));
00372   return(1);
00373 }
00374 
00375 /**********************************************************/
00376 /*               POWERCUBE GET INFORMATION */
00377 /**********************************************************/
00378 
00379 char amtecGetInt8(amtec_powercube_device_p dev, int id, unsigned char code)
00380 {
00381   static int len;
00382   static unsigned char buf[MAX_ACMD_SIZE];
00383   static char val;
00384   do {
00385     cmdGetExtended(dev, id, code);
00386     amtecGetAnswer(dev, buf, &len);
00387   } while(!getCorrectGetExtInt8(buf, len, code, &val));
00388   return(val);
00389 }
00390 
00391 unsigned char amtecGetUInt8(amtec_powercube_device_p dev, int id, unsigned char code)
00392 {
00393   static int len;
00394   static unsigned char buf[MAX_ACMD_SIZE];
00395   static unsigned char val;
00396   do {
00397     cmdGetExtended(dev, id, code);
00398     amtecGetAnswer(dev, buf, &len);
00399   } while(!getCorrectGetExtUInt8(buf, len, code, &val));
00400   return(val);
00401 }
00402 
00403 short amtecGetInt16(amtec_powercube_device_p dev, int id, unsigned char code)
00404 {
00405   static int len;
00406   static unsigned char buf[MAX_ACMD_SIZE];
00407   static short val;
00408   do {
00409     cmdGetExtended(dev, id, code);
00410     amtecGetAnswer(dev, buf, &len);
00411   } while(!getCorrectGetExtInt16(buf, len, code, &val));
00412   return(val);
00413 }
00414 
00415 unsigned short amtecGetUInt16(amtec_powercube_device_p dev, int id, unsigned char code)
00416 {
00417   static int len;
00418   static unsigned char buf[MAX_ACMD_SIZE];
00419   static unsigned short val;
00420   do {
00421     cmdGetExtended(dev, id, code);
00422     amtecGetAnswer(dev, buf, &len);
00423   } while(!getCorrectGetExtUInt16(buf, len, code, &val));
00424   return(val);
00425 }
00426 
00427 int amtecGetInt32(amtec_powercube_device_p dev, int id, unsigned char code)
00428 {
00429   static int len;
00430   static unsigned char buf[MAX_ACMD_SIZE];
00431   static int val;
00432   do {
00433     cmdGetExtended(dev, id, code);
00434     amtecGetAnswer(dev, buf, &len);
00435   } while(!getCorrectGetExtInt32(buf, len, code,  &val));
00436   return(val);
00437 }
00438 
00439 unsigned int amtecGetUInt32(amtec_powercube_device_p dev, int id, unsigned char code)
00440 {
00441   static int len;
00442   static unsigned char buf[MAX_ACMD_SIZE];
00443   static unsigned int val;
00444   do {
00445     cmdGetExtended(dev, id, code);
00446     amtecGetAnswer(dev, buf, &len);
00447   } while(!getCorrectGetExtUInt32(buf, len, code,  &val));
00448   return(val);
00449 }
00450 
00451 float amtecGetFloat(amtec_powercube_device_p dev, int id, unsigned char code)
00452 {
00453   int len;
00454   float val;
00455   unsigned char buf[MAX_ACMD_SIZE];
00456   do {
00457     cmdGetExtended(dev, id, code);
00458     amtecGetAnswer(dev, buf, &len);
00459   } while(!getCorrectGetExtFloat(buf, len, code,  &val));
00460   return(val);
00461 }
00462 
00463 /**********************************************************/
00464 /*        POWERCUBE GENERAL COMMANDS                      */
00465 /**********************************************************/
00466 int amtecReset(amtec_powercube_device_p dev, int id)
00467 {
00468   int len;
00469   unsigned char buf[MAX_ACMD_SIZE];
00470   do {
00471     cmdReset(dev, id);
00472     amtecGetAnswer(dev, buf, &len);
00473   } while(!getCorrectResetCode(buf, len));
00474   return 1;
00475 }
00476 
00477 int amtecHome(amtec_powercube_device_p dev, int id)
00478 {
00479   int len;
00480   unsigned char buf[MAX_ACMD_SIZE];
00481   do {
00482     cmdHome(dev, id);
00483     amtecGetAnswer(dev, buf, &len);
00484   } while(!getCorrectHomeCode(buf, len));
00485   return 1;
00486 }
00487 
00488 int amtecHalt(amtec_powercube_device_p dev, int id)
00489 {
00490   int len;
00491   unsigned char buf[MAX_ACMD_SIZE];
00492   do {
00493     cmdHalt(dev, id);
00494     amtecGetAnswer(dev, buf, &len);
00495   } while(!getCorrectHaltCode(buf, len));
00496   return 1;
00497 }
00498 
00499 int amtecRecalcPIDParam(amtec_powercube_device_p dev, int id)
00500 {
00501   int len;
00502   unsigned char buf[MAX_ACMD_SIZE];
00503   do {
00504     cmdRecalcPIDParam(dev, id);
00505     amtecGetAnswer(dev, buf, &len);
00506   } while(!getCorrectRecalcPIDParam(buf, len));
00507   return 1;
00508 }
00509 
00510 int amtecResetTime(amtec_powercube_device_p dev, int id)
00511 {
00512   int len;
00513   unsigned char buf[MAX_ACMD_SIZE];
00514   do {
00515     cmdResetTime(dev, id);
00516     amtecGetAnswer(dev, buf, &len);
00517   } while(!getCorrectResetTime(buf, len));
00518   return 1;
00519 }
00520 
00521 /**********************************************************/
00522 /*        POWERCUBE MOTION COMMANDS                       */
00523 /**********************************************************/
00524 int amtecMotionFRamp(amtec_powercube_device_p dev, int id, float position)
00525 {
00526   int len;
00527   unsigned char buf[MAX_ACMD_SIZE];
00528   do {
00529     cmdSetMotionFloat(dev, id, FRAMP_MODE, position);
00530     amtecGetAnswer(dev, buf, &len);
00531   } while(!getCorrectSetMotionCode(buf, len, FRAMP_MODE));
00532   return 1;
00533 }
00534 
00535 int amtecMotionFStep(amtec_powercube_device_p dev, int id, float position, unsigned short time)
00536 {
00537   int len;
00538   unsigned char buf[MAX_ACMD_SIZE];
00539   do {
00540     cmdSetFStepMotion(dev, id, FSTEP_MODE, position, time);
00541     amtecGetAnswer(dev, buf, &len);
00542   } while(!getCorrectSetMotionCode(buf, len, FSTEP_MODE));
00543   return 1;
00544 }
00545 
00546 int amtecMotionFVel(amtec_powercube_device_p dev, int id, float velocity)
00547 {
00548   int len;
00549   unsigned char buf[MAX_ACMD_SIZE];
00550   do {
00551     cmdSetMotionFloat(dev, id, FVEL_MODE, velocity);
00552     amtecGetAnswer(dev, buf, &len);
00553   } while(!getCorrectSetMotionCode(buf, len, FVEL_MODE));
00554   return 1;
00555 }
00556 
00557 int amtecMotionFCur(amtec_powercube_device_p dev, int id, float current)
00558 {
00559   int len;
00560   unsigned char buf[MAX_ACMD_SIZE];
00561   do {
00562     cmdSetMotionFloat(dev, id, FCUR_MODE, current);
00563     amtecGetAnswer(dev, buf, &len);
00564   } while(!getCorrectSetMotionCode(buf, len, FCUR_MODE));
00565   return 1;
00566 }
00567 
00568 int amtecMotionIRamp(amtec_powercube_device_p dev, int id, int ticks)
00569 {
00570   int len;
00571   unsigned char buf[MAX_ACMD_SIZE];
00572   do {
00573     cmdSetMotionInt32(dev, id, IRAMP_MODE, ticks);
00574     amtecGetAnswer(dev, buf, &len);
00575   } while(!getCorrectSetMotionCode(buf, len, IRAMP_MODE));
00576   return 1;
00577 }
00578 
00579 int amtecMotionIStep(amtec_powercube_device_p dev, int id, int ticks, unsigned short time)
00580 {
00581   int len;
00582   unsigned char buf[MAX_ACMD_SIZE];
00583   do {
00584     cmdSetIStepMotion(dev, id, ISTEP_MODE, ticks, time);
00585     amtecGetAnswer(dev, buf, &len);
00586   } while(!getCorrectSetMotionCode(buf, len, ISTEP_MODE));
00587   return 1;
00588 }
00589 
00590 int amtecMotionIVel(amtec_powercube_device_p dev, int id, int ticks)
00591 {
00592   int len;
00593   unsigned char buf[MAX_ACMD_SIZE];
00594   do {
00595     cmdSetMotionInt32(dev, id, IVEL_MODE, ticks);
00596     amtecGetAnswer(dev, buf, &len);
00597   } while(!getCorrectSetMotionCode(buf, len, IVEL_MODE));
00598   return 1;
00599 }
00600 
00601 int amtecMotionICur(amtec_powercube_device_p dev, int id, short digits)
00602 {
00603   int len;
00604   unsigned char buf[MAX_ACMD_SIZE];
00605   do {
00606     cmdSetMotionInt16(dev, id, ICUR_MODE, digits);
00607     amtecGetAnswer(dev, buf, &len);
00608   } while(!getCorrectSetMotionCode(buf, len, ICUR_MODE));
00609   return 1;
00610 }
00611 
00612 int amtecMotionFCosLoop(amtec_powercube_device_p dev, int id, float val, unsigned short period)
00613 {
00614   int len;
00615   unsigned char buf[MAX_ACMD_SIZE];
00616   do {
00617     cmdSetMotionLoop(dev, id, FCOSLOOP, val, period);
00618     amtecGetAnswer(dev, buf, &len);
00619   } while(!getCorrectSetMotionCode(buf, len, FCOSLOOP));
00620   return 1;
00621 }
00622 
00623 int amtecMotionFRampLoop(amtec_powercube_device_p dev, int id, float val)
00624 {
00625   int len;
00626   unsigned char buf[MAX_ACMD_SIZE];
00627   do {
00628     cmdSetMotionFloat(dev, id, FCUR_MODE, val);
00629     amtecGetAnswer(dev, buf, &len);
00630   } while(!getCorrectSetMotionCode(buf, len, FCUR_MODE));
00631 }
00632 
00633 /**********************************************************/
00634 /*        POWERCUBE SPECIAL GET INFORMATION               */
00635 /**********************************************************/
00636 
00637 float amtecGetDefHomeOffset(amtec_powercube_device_p dev, int id)
00638 {
00639   return(amtecGetFloat(dev, id, CodeDefHomeOffset));
00640 }
00641 
00642 float amtecGetDefGearRatio(amtec_powercube_device_p dev, int id)
00643 {
00644   return(amtecGetFloat(dev, id, CodeDefGearRatio));
00645 }
00646 
00647 float amtecGetDefLinRatio(amtec_powercube_device_p dev, int id)
00648 {
00649   return(amtecGetFloat(dev, id, CodeDefLinRatio));
00650 }
00651 
00652 float amtecGetDefMinPos(amtec_powercube_device_p dev, int id)
00653 {
00654   return(amtecGetFloat(dev, id, CodeDefMinPos));
00655 }
00656 
00657 float amtecGetDefMaxPos(amtec_powercube_device_p dev, int id)
00658 {
00659   return(amtecGetFloat(dev, id, CodeDefMaxPos));
00660 }
00661 
00662 float amtecGetDefMaxDeltaPos(amtec_powercube_device_p dev, int id)
00663 {
00664   return(amtecGetFloat(dev, id, CodeDefMaxDeltaPos));
00665 }
00666 
00667 float amtecGetDefMaxDeltaVel(amtec_powercube_device_p dev, int id)
00668 {
00669   return 0;//(amtecGetFloat(dev, id, CodeDefMaxDeltaVel));
00670 }
00671 
00672 float amtecGetDefTorqueRatio(amtec_powercube_device_p dev, int id)
00673 {
00674   return(amtecGetFloat(dev, id, CodeDefTorqueRatio));
00675 }
00676 
00677 float amtecGetDefCurRatio(amtec_powercube_device_p dev, int id)
00678 {
00679   return(amtecGetFloat(dev, id, CodeDefCurRatio));
00680 }
00681 
00682 float amtecGetDefMaxVel(amtec_powercube_device_p dev, int id)
00683 {
00684   return(amtecGetFloat(dev, id, CodeDefMaxVel));
00685 }
00686 
00687 float amtecGetDefMaxAcc(amtec_powercube_device_p dev, int id)
00688 {
00689   return(amtecGetFloat(dev, id, CodeDefMaxAcc));
00690 }
00691 
00692 float amtecGetDefMaxCur(amtec_powercube_device_p dev, int id)
00693 {
00694   return(amtecGetFloat(dev, id, CodeDefMaxCur));
00695 }
00696 
00697 float amtecGetDefHomeVel(amtec_powercube_device_p dev, int id)
00698 {
00699   return(amtecGetFloat(dev, id, CodeDefHomeVel));
00700 }
00701 
00702 float amtecGetDefHomeAcc(amtec_powercube_device_p dev, int id)
00703 {
00704   return(amtecGetFloat(dev, id, CodeDefHomeAcc));
00705 }
00706 
00707 unsigned int amtecGetDefCubeSerial(amtec_powercube_device_p dev, int id)
00708 {
00709   return(amtecGetUInt32(dev, id, CodeDefCubeSerial));
00710 }
00711 
00712 unsigned int amtecGetDefPulsesPerTurn(amtec_powercube_device_p dev, int id)
00713 {
00714   return(amtecGetUInt32(dev, id, CodeDefPulsesPerTurn));
00715 }
00716 
00717 unsigned int amtecGetDefConfig(amtec_powercube_device_p dev, int id)
00718 {
00719   return(amtecGetUInt32(dev, id, CodeDefConfig));
00720 }
00721 
00722 unsigned short amtecGetDefCubeVersion(amtec_powercube_device_p dev, int id)
00723 {
00724   return(amtecGetUInt16(dev, id, CodeDefCubeVersion));
00725 }
00726 
00727 unsigned short amtecGetDefServiceInterval(amtec_powercube_device_p dev, int id)
00728 {
00729   return 0;//(amtecGetUInt16(dev, id, CodeDefServiceInterval));
00730 }
00731 
00732 unsigned short amtecGetDefBrakeTimeOut(amtec_powercube_device_p dev, int id)
00733 {
00734   return(amtecGetUInt16(dev, id, CodeDefBrakeTimeOut));
00735 }
00736 
00737 unsigned char amtecGetDefAddress(amtec_powercube_device_p dev, int id)
00738 {
00739   return(amtecGetUInt8(dev, id, CodeDefAddress));
00740 }
00741 
00742 unsigned char amtecGetDefPrimBaud(amtec_powercube_device_p dev, int id)
00743 {
00744   return(amtecGetUInt8(dev, id, CodeDefPrimBaud));
00745 }
00746 
00747 unsigned char amtecGetDefScndBaud(amtec_powercube_device_p dev, int id)
00748 {
00749   return(amtecGetUInt8(dev, id, CodeDefScndBaud));
00750 }
00751 
00752 int amtecGetPosCount(amtec_powercube_device_p dev, int id)
00753 {
00754   return(amtecGetUInt8(dev, id, CodePosCount));
00755 }
00756 
00757 int amtecGetRefPosCount(amtec_powercube_device_p dev, int id)
00758 {
00759   return(amtecGetUInt8(dev, id, CodeRefPosCount));
00760 }
00761 
00762 unsigned int amtecGetDioSetup(amtec_powercube_device_p dev, int id)
00763 {
00764   return(amtecGetUInt32(dev, id, CodeDioSetup));
00765 }
00766 
00767 unsigned int amtecGetCubeState(amtec_powercube_device_p dev, int id)
00768 {
00769   return(amtecGetUInt32(dev, id, CodeCubeState));
00770 }
00771 
00772 unsigned int amtecGetTargetPosInc(amtec_powercube_device_p dev, int id)
00773 {
00774   return(amtecGetUInt32(dev, id, CodeTargetPosInc));
00775 }
00776 
00777 unsigned int amtecGetTargetVelInc(amtec_powercube_device_p dev, int id)
00778 {
00779   return(amtecGetUInt32(dev, id, CodeTargetVelInc));
00780 }
00781 
00782 unsigned int amtecGetTargetAccInc(amtec_powercube_device_p dev, int id)
00783 {
00784   return(amtecGetUInt32(dev, id, CodeTargetAccInc));
00785 }
00786 
00787 unsigned int amtecGetStepInc(amtec_powercube_device_p dev, int id)
00788 {
00789   return(amtecGetUInt32(dev, id, CodeStepInc));
00790 }
00791 
00792 
00793 float amtecGetMinPos(amtec_powercube_device_p dev, int id)
00794 {
00795   return(amtecGetFloat(dev, id, CodeMinPos));
00796 }
00797 
00798 float amtecGetMaxPos(amtec_powercube_device_p dev, int id)
00799 {
00800   return(amtecGetFloat(dev, id, CodeMaxPos));
00801 }
00802 
00803 float amtecGetMaxVel(amtec_powercube_device_p dev, int id)
00804 {
00805   return(amtecGetFloat(dev, id, CodeMaxVel));
00806 }
00807 
00808 float amtecGetMaxAcc(amtec_powercube_device_p dev, int id)
00809 {
00810   return(amtecGetFloat(dev, id, CodeMaxAcc));
00811 }
00812 
00813 float amtecGetTargetVel(amtec_powercube_device_p dev, int id)
00814 {
00815   return(amtecGetFloat(dev, id, CodeTargetVel));
00816 }
00817 
00818 float amtecGetTargetAcc(amtec_powercube_device_p dev, int id)
00819 {
00820   return(amtecGetFloat(dev, id, CodeTargetAcc));
00821 }
00822 
00823 float amtecGetMaxCur(amtec_powercube_device_p dev, int id)
00824 {
00825   return(amtecGetFloat(dev, id, CodeMaxCur));
00826 }
00827 
00828 float amtecGetActPos(amtec_powercube_device_p dev, int id)
00829 {
00830   return(amtecGetFloat(dev, id, CodeActPos));
00831 }
00832 
00833 unsigned int amtecGetConfig(amtec_powercube_device_p dev __attribute__ ((unused)),
00834                              int id __attribute__ ((unused)))
00835 {
00836   return(0);
00837 }
00838 
00839 float amtecGetActVel(amtec_powercube_device_p dev, int id)
00840 {
00841   return(amtecGetFloat(dev, id, CodeActVel));
00842 }
00843 
00844 float amtecGetCur(amtec_powercube_device_p dev, int id)
00845 {
00846   return(amtecGetFloat(dev, id, CodeCur));
00847 }
00848 
00849 short amtecGetActC0(amtec_powercube_device_p dev, int id)
00850 {
00851   return amtecGetInt16(dev, id, CodeActC0);
00852 }
00853 
00854 short amtecGetActDamp(amtec_powercube_device_p dev, int id)
00855 {
00856   return amtecGetInt16(dev, id, CodeActDamp);
00857 }
00858 
00859 short amtecGetActA0(amtec_powercube_device_p dev, int id)
00860 {
00861   return amtecGetInt16(dev, id, CodeActA0);
00862 }
00863 
00864 /**********************************************************/
00865 /*              POWERCUBE SET VALUES */
00866 /**********************************************************/
00867 
00868 void amtecSetMinPos(amtec_powercube_device_p dev, int id, float val)
00869 {
00870   int len;
00871   unsigned char buf[MAX_ACMD_SIZE];
00872   do {
00873     cmdSetMinPos(dev, id, val);
00874     amtecGetAnswer(dev, buf, &len);
00875   } while(!getCorrectSetExtCode(buf, len, CodeMinPos));
00876 }
00877 
00878 void amtecSetMaxPos(amtec_powercube_device_p dev, int id, float val)
00879 {
00880   int len;
00881   unsigned char buf[MAX_ACMD_SIZE];
00882   do {
00883     cmdSetMaxPos(dev, id, val);
00884     amtecGetAnswer(dev, buf, &len);
00885   } while(!getCorrectSetExtCode(buf, len, CodeMaxPos));
00886 }
00887 
00888 void amtecSetMaxAcc(amtec_powercube_device_p dev, int id, float val)
00889 {
00890   int len;
00891   unsigned char buf[MAX_ACMD_SIZE];
00892   do {
00893     cmdSetMaxAcc(dev, id, val);
00894     amtecGetAnswer(dev, buf, &len);
00895   } while(!getCorrectSetExtCode(buf, len, CodeMaxAcc));
00896 }
00897 
00898 void amtecSetMaxVel(amtec_powercube_device_p dev, int id, float val)
00899 {
00900   int len;
00901   unsigned char buf[MAX_ACMD_SIZE];
00902   do {
00903     cmdSetMaxVel(dev, id, val);
00904     amtecGetAnswer(dev, buf, &len);
00905   } while(!getCorrectSetExtCode(buf, len, CodeMaxVel));
00906 }
00907 
00908 void amtecSetTargetAcc(amtec_powercube_device_p dev, int id, float val)
00909 {
00910   int len;
00911   unsigned char buf[MAX_ACMD_SIZE];
00912   do {
00913     cmdSetTargetAcc(dev, id, val);
00914     amtecGetAnswer(dev, buf, &len);
00915   } while(!getCorrectSetExtCode(buf, len, CodeTargetAcc));
00916 }
00917 
00918 void amtecSetTargetVel(amtec_powercube_device_p dev, int id, float val)
00919 {
00920   int len;
00921   unsigned char buf[MAX_ACMD_SIZE];
00922   do {
00923     cmdSetTargetVel(dev, id, val);
00924     amtecGetAnswer(dev, buf, &len);
00925   } while(!getCorrectSetExtCode(buf, len, CodeTargetVel));
00926 }
00927 
00928 void amtecSetMaxCur(amtec_powercube_device_p dev, int id, float val)
00929 {
00930   int len;
00931   unsigned char buf[MAX_ACMD_SIZE];
00932   do {
00933     cmdSetMaxCur(dev, id, val);
00934     amtecGetAnswer(dev, buf, &len);
00935   } while(!getCorrectSetExtCode(buf, len, CodeMaxCur));
00936 }
00937 
00938 void amtecSetConfig(amtec_powercube_device_p dev, int id, unsigned int conf)
00939 {
00940   int len;
00941   unsigned char buf[MAX_ACMD_SIZE];
00942   do {
00943     cmdSetConfig(dev, id, conf);
00944     amtecGetAnswer(dev, buf, &len);
00945   } while(!getCorrectSetExtCode(buf, len, CodeConfig));
00946 }
00947 
00948 
00949 void amtecSetActC0(amtec_powercube_device_p dev, int id, short c0)
00950 {
00951   int len;
00952   unsigned char buf[MAX_ACMD_SIZE];
00953   do {
00954     cmdSetActC0(dev, id, c0);
00955     amtecGetAnswer(dev, buf, &len);
00956   } while(!getCorrectSetExtCode(buf, len, CodeActC0));
00957 }
00958 
00959 void amtecSetActDamp(amtec_powercube_device_p dev, int id, short damp)
00960 {
00961   int len;
00962   unsigned char buf[MAX_ACMD_SIZE];
00963   do {
00964     cmdSetActDamp(dev, id, damp);
00965     amtecGetAnswer(dev, buf, &len);
00966   } while(!getCorrectSetExtCode(buf, len, CodeActDamp));
00967 }
00968 
00969 void amtecSetActA0(amtec_powercube_device_p dev, int id, short a0)
00970 {
00971   int len;
00972   unsigned char buf[MAX_ACMD_SIZE];
00973   do {
00974     cmdSetActA0(dev, id, a0);
00975     amtecGetAnswer(dev, buf, &len);
00976   } while(!getCorrectSetExtCode(buf, len, CodeActA0));
00977 }


amtec
Author(s): Charles DuHadway, Benjamin Pitzer (Maintained by Benjamin Pitzer)
autogenerated on Mon Oct 6 2014 10:10:36