⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ampstruct.cpp

📁 美国COPLEY驱动器,程序开发工具之一.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/************************************************************/
/*                                                          */
/*  Copley Motion Libraries                                 */
/*                                                          */
/*  Author: Stephen Glow                                    */
/*                                                          */
/*  Copyright (c) 2002-2005 Copley Controls Corp.           */
/*                          http://www.copleycontrols.com   */
/*                                                          */
/************************************************************/

/***************************************************************************/
/** \file
This file contains the AMP object methods used to upload / download 
structures containing groups of amplifier parameters.
*/
/***************************************************************************/

#include "CML.h"

CML_NAMESPACE_USE();

#define VERSION( major, minor )    ((major<<8) | minor)

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/*
                   Amplifier & Motor information
*/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

/***************************************************************************/
/**
  Read the Amplifier information parameters from the drive.
  These parameters describe the amplifiers capabilities.  They 
  are read only.

  @param info A structure that will be filled with the amplifier info
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetAmpInfo( AmpInfo &info )
{
   int32 l;

   const Error *err = sdo.UpldString( OBJID_AMP_MODEL, 0, l=COPLEY_MAX_STRING, info.model   );
   if( !err ) err = sdo.UpldString( OBJID_AMP_MFG,   0, l=COPLEY_MAX_STRING, info.mfgName );
   if( !err ) err = sdo.UpldString( OBJID_AMP_WEB,   0, l=COPLEY_MAX_STRING, info.mfgWeb  );
   if( !err ) err = sdo.UpldString( OBJID_AMP_INFO,  2, l=COPLEY_MAX_STRING, info.mfgInfo );
   if( !err ) err = sdo.UpldString( 0x100A,          0, l=COPLEY_MAX_STRING, info.swVer   );
   if( !err ) err = sdo.Upld32( OBJID_AMP_MODES, 0, info.modes       );
   if( !err ) err = sdo.Upld32( OBJID_AMP_INFO,  1, info.serial      );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO,  3, info.crntPeak    );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO,  4, info.crntCont    );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO,  5, info.crntTime    );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO,  6, info.voltMax     );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO,  7, info.voltMin     );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO,  8, info.voltHyst    );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO,  9, info.tempMax     );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 10, info.tempHyst    );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 11, info.pwmPeriod   );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 12, info.servoPeriod );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 13, info.type        );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 14, info.crntScale   );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 15, info.voltScale   );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 16, info.refScale    );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 17, info.pwm_off     );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 18, info.pwm_dbcont  );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 19, info.pwm_dbzero  );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 20, info.regenPeak   );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 21, info.regenCont   );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 22, info.regenTime   );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 23, info.aencScale   );
   if( !err ) err = sdo.Upld16( OBJID_AMP_INFO, 24, info.swVerNum    );

   // OK, assuming the upload went well I'll just convert some
   // parameters into nice units and return
   if( err ) return err;


   return 0;
}

/***************************************************************************/
/**
  Motor info structure default constructor.  This simply initializes all members
  to legal default values.
  */
/***************************************************************************/
MtrInfo::MtrInfo( void )
{
   mfgName[0] = 0;
   model[0] = 0;

   hasBrake   = false;
   tempSensor = false;
   mtrReverse = false;
   encReverse = false;

   resistance = 100;
   inductance = 100;
   trqPeak = 10;
   trqCont = 10;
   trqConst = 100;
   backEMF = 1;
   inertia = 10;

   type  = 0;
   poles = 2;
   velMax = 1;
   hallType   = 1;
   hallWiring = 0;
   hallOffset = 0;
   stopTime = 0;
   brakeDelay = 0;
   brakeVel = 0;
   encType = 0;
   ctsPerRev = 4000;
   encUnits = 0;
   encRes = 100;
   eleDist = 100000;
   mtrUnits = 0;
   stepsPerRev = 4000;
   encShift = 0;
   ndxDist = 0;

   loadEncType = 0;
   loadEncRes = 0;
   loadEncReverse = false;

   gearRatio = 0x00010001;
   resolverCycles = 1;
   hallVelShift = 1;
}

/***************************************************************************/
/**
  Read the motor information structure from the amplifier.

  @param info A structure that will be filled with the motor info
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::GetMtrInfo( MtrInfo &info )
{
   int32 l;

   // Upload those parameters that can be mapped directly into the
   // MtrInfo structure with no translation.
   const Error *err = sdo.UpldString( OBJID_MOTOR_MODEL, 0, l=COPLEY_MAX_STRING, info.model );
   if( !err ) err = sdo.UpldString( OBJID_MOTOR_MFG,   0, l=COPLEY_MAX_STRING, info.mfgName );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO,  1, info.type );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO,  2, info.poles );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO,  4, info.hallType );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO,  5, info.hallWiring );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO,  6, info.hallOffset );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 17, info.stopTime   );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 18, info.brakeDelay );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 20, info.encType );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 21, info.encUnits );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 23, info.ctsPerRev );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 24, info.encRes );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 25, info.eleDist );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 26, info.ndxDist );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 27, info.mtrUnits );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 28, info.encShift );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 29, info.stepsPerRev );

   // Upload the rest of the parameters to temporary locations
   // and convert them into the units used in the MtrInfo structure.
   int16 wiring, tSense, brake, encDir;
   int32 maxVel, bVel;

   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO,  3, wiring   );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO,  7, info.resistance );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO,  8, info.inductance );

   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO,  9, info.inertia );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 10, info.backEMF );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 11, maxVel   );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 12, info.trqConst );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 13, info.trqPeak  );
   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 14, info.trqCont  );

   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 15, tSense   );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 16, brake    );

   if( !err ) err = sdo.Upld32( OBJID_MOTOR_INFO, 19, bVel     );
   if( !err ) err = sdo.Upld16( OBJID_MOTOR_INFO, 22, encDir   );

   if( err ) return err;

   // Now, convert the uploaded values to more convenient units.
   info.mtrReverse = wiring ? true : false;
   info.encReverse = encDir ? true : false;
   info.hasBrake   = brake ? false : true;
   info.tempSensor = tSense ? true : false;

   info.velMax     = VelMtr2User( maxVel );
   info.brakeVel   = VelMtr2User( bVel );

   // Check for some parameters that we added in later versions of firmware.
   uint8 ct;
   err = sdo.Upld8( OBJID_MOTOR_INFO,  0, ct );
   if( !err && (ct >=30) ) err = sdo.Upld16( OBJID_MOTOR_INFO, 30, info.loadEncType );
   if( !err && (ct >=31) ) err = sdo.Upld16( OBJID_MOTOR_INFO, 31, encDir );
   if( !err && (ct >=32) ) err = sdo.Upld32( OBJID_MOTOR_INFO, 32, info.loadEncRes  );
   info.loadEncReverse = encDir ? true : false;

   // Firmware versions before 4.42 had a bug which prevented reading the gear ratio
   // or resolver cycles/rev parameters.
   if( SwVersionNum < VERSION(4,42) )
      return err;

   if( !err && (ct >=33) ) err = sdo.Upld32( OBJID_MOTOR_INFO, 33, info.gearRatio );
   if( !err && (ct >=34) ) err = sdo.Upld16( OBJID_MOTOR_INFO, 34, info.resolverCycles );

   if( !err && (SwVersionNum >= VERSION(4,56)) )
      err = sdo.Upld16( OBJID_HALLVEL_SHIFT, 0, info.hallVelShift );

   return err;
}

/***************************************************************************/
/**
  Update the amplifier's motor information.

  @param info A structure that contains the motor info to be downloaded.
  @return A pointer to an error object, or NULL on success
  */
/***************************************************************************/
const Error *Amp::SetMtrInfo( MtrInfo &info )
{
   // Translate parameters into the proper units for upload.
   int16 wiring, tSense, brake, encDir;
   int32 maxVel, bVel;

   maxVel  = VelUser2Mtr( info.velMax );
   bVel    = VelUser2Mtr( info.brakeVel );

   wiring = (info.mtrReverse == true);
   encDir = (info.encReverse == true);
   brake  = (info.hasBrake   == false);
   tSense = (info.tempSensor == true);

   // Upload these parameters to the motor
   const Error *err = sdo.DnldString( OBJID_MOTOR_MODEL, 0, info.model   );
   if( !err ) err = sdo.DnldString( OBJID_MOTOR_MFG,   0, info.mfgName );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO,  1, info.type );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO,  2, info.poles );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO,  3, wiring   );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO,  4, info.hallType );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO,  5, info.hallWiring );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO,  6, info.hallOffset );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO,  7, info.resistance );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO,  8, info.inductance );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO,  9, info.inertia  );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 10, info.backEMF );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 11, maxVel   );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 12, info.trqConst );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 13, info.trqPeak  );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 14, info.trqCont  );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 15, tSense   );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 16, brake    );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 17, info.stopTime   );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 18, info.brakeDelay );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 19, bVel     );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 20, info.encType );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 21, info.encUnits );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 22, encDir   );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 23, info.ctsPerRev );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 24, info.encRes );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 25, info.eleDist );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 26, info.ndxDist );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 27, info.mtrUnits );
   if( !err ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 28, info.encShift );
   if( !err ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 29, info.stepsPerRev );
   if( err ) return err;

   // Update the load encoder settings if available in the firmware
   uint8 ct;
   err = sdo.Upld8( OBJID_MOTOR_INFO,  0, ct );

   encDir = (info.loadEncReverse == true);
   if( !err && (ct >= 30) ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 30, info.loadEncType );
   if( !err && (ct >= 31) ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 31, encDir );
   if( !err && (ct >= 32) ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 32, info.loadEncRes  );
   if( SwVersionNum < VERSION(4,42) )
      return err;

   if( !err && (ct >= 33) ) err = sdo.Dnld32( OBJID_MOTOR_INFO, 33, info.gearRatio );
   if( !err && (ct >= 34) ) err = sdo.Dnld16( OBJID_MOTOR_INFO, 34, info.resolverCycles );

   if( !err && (SwVersionNum >= VERSION(4,56)) )
      err = sdo.Dnld16( OBJID_HALLVEL_SHIFT, 0, info.hallVelShift );

   return err;
}

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/*
   Control loop gains (position, velocity & current)
   */
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

/***************************************************************************/
/**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -