60 void Sleep(
int msecs){usleep(1000*msecs);}
69 msg.
set(1,0,0,0,0,0,0,0);
83 m_MotionCtrlType = POS_CTRL;
100 bool success =
false;
101 if (m_Joint != NULL) {
104 m_Joint->IntprtSetInt(8,
'I',
'L', 2, 7);
109 m_Joint->IntprtSetInt(8,
'I',
'L', 1, 6);
112 m_Joint->initHoming();
117 printf(
"ElmoCtrl: Home(): Homing Vel = %f\n",m_HomingDir*0.3);
118 m_Joint->setGearVelRadS(m_HomingDir*0.3);
121 success = m_Joint->execHoming();
122 m_Joint->setGearVelRadS(0.0);
134 while(m_CanCtrl->receiveMsg(&m_CanMsgRec) ==
true) {
137 bRet |= m_Joint->evalReceivedMsg(m_CanMsgRec);
140 }
else std::cout <<
"cob_head_axis: Unknown CAN-msg: " << m_CanMsgRec.m_iID <<
" " << (int)m_CanMsgRec.getAt(0) <<
" " << (int)m_CanMsgRec.getAt(1) << std::endl;
150 bool success =
false;
151 printf(
"Resetting motor ...\n");
152 success = m_Joint->start();
156 printf(
"successful\n");
157 m_Joint->setGearVelRadS(0);
165 bool success =
false;
172 if (params == NULL) {
173 printf(
"ElmoCtrlParams:Error:%s:%d:, invalid parameters!\n",__FILE__,__LINE__);
180 printf(
"------------ ElmoCtrl Init ---------------\n");
195 if (CanIniFile.length() == 0) {
196 printf(
"%s,%d:Error: Parameter 'CanIniFile' not given!\n",__FILE__,__LINE__);
201 if (CanDevice.length() == 0) {
202 printf(
"%s,%d:Error: Parameter 'Can-Device' not given!\n",__FILE__,__LINE__);
208 printf(
"%s,%d:Error: Parameter 'Baud-Rate' not given!\n",__FILE__,__LINE__);
220 printf(
"The following parameters were successfully read from the parameter server (given through *params): \n");
221 printf(
"CanIniFile: %s\n",CanIniFile.c_str());
222 printf(
"CanDieODvice: %s\n",CanDevice.c_str());
223 printf(
"Baudrate: %d\n",baudrate);
224 printf(
"Module ID: %d\n",m_CanBaseAddress);
225 printf(
"Max Vel: %f\n",m_MaxVel);
226 printf(
"Homing Dir: %d\n",m_HomingDir);
227 printf(
"HomingDigIn: %d\n",m_HomingDigIn);
228 printf(
"Offset/Limit(min/max) %f/(%f,%f)\n",m_JointOffset,m_LowerLimit,m_UpperLimit);
237 if (m_CanCtrl == NULL) {
238 printf(
"%s,%d:Error: Could not open Can Device!\n",__FILE__,__LINE__);
252 m_CanAddress.TxPDO1 = 0x181 + m_CanBaseAddress -1;
253 m_CanAddress.TxPDO2 = 0x281 + m_CanBaseAddress -1;
254 m_CanAddress.RxPDO2 = 0x301 + m_CanBaseAddress -1;
255 m_CanAddress.TxSDO = 0x581 + m_CanBaseAddress -1;
256 m_CanAddress.RxSDO = 0x601 + m_CanBaseAddress -1;
257 m_Joint->setCanItf(m_CanCtrl);
258 m_Joint->setCanOpenParam(m_CanAddress.TxPDO1,
262 m_CanAddress.RxSDO );
264 printf(
"CanAdresses set to %d (Base), %x, %x, %x, %x, %x...\n", m_CanBaseAddress,
274 success = sendNetStartCanOpen(m_CanCtrl);
315 m_JointParams->setParam(
333 m_Joint->setDriveParam(*m_JointParams);
338 printf(
"Init motor ...\n");
339 success = m_Joint->init();
346 printf(
"successful\n");
351 success = SetMotionCtrlType(m_MotionCtrlType);
352 if(!success) std::cout <<
"Failed to SetMotionCtrlType to " << m_MotionCtrlType << std::endl;
356 printf(
"Starting motor ..\n");
357 success = m_Joint->start();
364 printf(
"successful\n");
365 m_Joint->setGearVelRadS(0);
373 std::cout <<
"Start homing procedure now.." << std::endl;
379 pthread_mutex_init(&m_Mutex,NULL);
388 m_MotionCtrlType = type;
389 bool success =
false;
390 if (type == POS_CTRL)
392 success = m_Joint->shutdown();
398 success = m_Joint->start();
401 else if (type == VEL_CTRL)
404 printf(
"%s%d:Error: Velocity control not implemented yet!\n",__FILE__,__LINE__);
413 return m_MotionCtrlType;
418 return m_Joint->isError();
428 m_Joint->getGearPosVelRadS(pdAngleGearRad, pdVelGearRadS);
429 *pdAngleGearRad = *pdAngleGearRad - m_JointOffset;
439 if(dPosRad< m_LowerLimit) {
440 std::cout <<
"Position under LowerBound -> set up" << std::endl;
441 dPosRad = m_LowerLimit;
442 }
else if(dPosRad > m_UpperLimit) {
443 std::cout <<
"Position over UpperBound -> set down" << std::endl;
444 dPosRad = m_UpperLimit;
447 if(dVelRadS > m_MaxVel)
449 else if(dVelRadS < -m_MaxVel)
450 dVelRadS = -m_MaxVel;
455 printf(
"ElmoCtrl:setGearPosVelRadS: dPosRad %f with vel %f\n",dPosRad, dVelRadS);
456 m_Joint->setGearPosVelRadS(m_HomingDir * dPosRad + m_JointOffset, dVelRadS);
465 m_Joint->getGearPosVelRadS(&pos,&vel);
466 m_Joint->setGearPosVelRadS(pos,0);
bool Init(ElmoCtrlParams *params, bool home=true)
int getGearPosVelRadS(double *pdAngleGearRad, double *pdVelGearRadS)
bool sendNetStartCanOpen(CanItf *canCtrl)
int setGearPosVelRadS(double dPosRad, double dVelRadS)
bool SetMotionCtrlType(int type)
int GetEncoderIncrements()
std::string GetCanIniFile()
std::string GetCanDevice()
void set(BYTE Data0=0, BYTE Data1=0, BYTE Data2=0, BYTE Data3=0, BYTE Data4=0, BYTE Data5=0, BYTE Data6=0, BYTE Data7=0)
bool RecoverAfterEmergencyStop()
virtual bool transmitMsg(CanMsg CMsg, bool bBlocking=true)=0