This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Controlling Acc/Decc/Jerk and speed problem

Genius 5910 points


Hi,

I'm trying to write a control value to the controller and read it back again. But the values are not the same.

I added this code in LAB_13B (mainloop):

        {
            ST_Obj *stObj = (ST_Obj *)stHandle;

          STPOSMOVE_setVelocityLimit(stObj->posMoveHandle, _IQmpy(_IQ(2), _IQ(ST_SPEED_PU_PER_KRPM)));
          STPOSMOVE_setAccelerationLimit(stObj->posMoveHandle, _IQmpy(_IQ(3), _IQ(ST_SPEED_PU_PER_KRPM)));
          STPOSMOVE_setDecelerationLimit(stObj->posMoveHandle, _IQmpy(_IQ(4), _IQ(ST_SPEED_PU_PER_KRPM)));
          STPOSMOVE_setJerkLimit(stObj->posMoveHandle, _IQ20mpy(_IQ20(5), _IQ20(ST_SPEED_PU_PER_KRPM)));

          gMotorVars.MaxVel_krpm = STPOSMOVE_getVelocityMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);
          gMotorVars.MaxAccel_krpmps = STPOSMOVE_getAccelerationMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);
          gMotorVars.MaxDecel_krpmps = STPOSMOVE_getDecelerationMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);
          gMotorVars.MaxJrk_krpmps2 = STPOSMOVE_getJerkMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);
      }

// ST_SPEED_PU_PER_KRPM = 0.1333

This is the result in the expression window:

gMotorVars.MaxVel_krpm = 3.576278687e-07

gMotorVars.MaxAccel_krpmps= 4.470348358e-06

gMotorVars.MaxDecel_krpmps=4.470348358e-06

gMotorVars.MaxJrk_krpmps2= 2.765655518e-05

If I change the code to this: (only reading the value)

          gMotorVars.MaxVel_krpm = STPOSMOVE_getVelocityMaximum(stObj->posMoveHandle);
          gMotorVars.MaxAccel_krpmps = STPOSMOVE_getAccelerationMaximum(stObj->posMoveHandle);
          gMotorVars.MaxDecel_krpmps = STPOSMOVE_getDecelerationMaximum(stObj->posMoveHandle);
          gMotorVars.MaxJrk_krpmps2 = STPOSMOVE_getJerkMaximum(stObj->posMoveHandle);

gMotorVars.MaxVel_krpm = 0.8000000715

gMotorVars.MaxAccel_krpmps= 10

gMotorVars.MaxDecel_krpmps= 10

gMotorVars.MaxJrk_krpmps2= 62.5

 I have no Idea what I problem is.

  • Evs,

    There are a couple of issues here.  The main one is that there is a difference between Maximum and Limit in SpinTAC.  The maximums tell you how large the limit can be, while the limits are what is used as part of profile generation.

    evs said:
    gMotorVars.MaxVel_krpm = STPOSMOVE_getVelocityMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);
              gMotorVars.MaxAccel_krpmps = STPOSMOVE_getAccelerationMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);
              gMotorVars.MaxDecel_krpmps = STPOSMOVE_getDecelerationMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);
              gMotorVars.MaxJrk_krpmps2 = STPOSMOVE_getJerkMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);

    This code is reading the maximum allowable Velocity, Acceleration, Deceleration, and Jerk limits in SpinTAC Move.  Which is different from the limits that you set with the following code:

    evs said:
     STPOSMOVE_setVelocityLimit(stObj->posMoveHandle, _IQmpy(_IQ(2), _IQ(ST_SPEED_PU_PER_KRPM)));
              STPOSMOVE_setAccelerationLimit(stObj->posMoveHandle, _IQmpy(_IQ(3), _IQ(ST_SPEED_PU_PER_KRPM)));
              STPOSMOVE_setDecelerationLimit(stObj->posMoveHandle, _IQmpy(_IQ(4), _IQ(ST_SPEED_PU_PER_KRPM)));
              STPOSMOVE_setJerkLimit(stObj->posMoveHandle, _IQ20mpy(_IQ20(5), _IQ20(ST_SPEED_PU_PER_KRPM)));

    Also the expression you are using when you read the maximum isn't handling the data types correctly.  

    gMotorVars.MaxVel_krpm = STPOSMOVE_getVelocityMaximum(stObj->posMoveHandle) / _IQ(ST_SPEED_PU_PER_KRPM);

    Is dividing an int32_t variable by an int32_t variable and placing the result in an int32_t variable.  So you are doing integer division and not fixed-point division.  You should replace the expression with the following:

    gMotorVars.MaxVel_krpm = _IQdiv(STPOSMOVE_getVelocityMaximum(stObj->posMoveHandle), _IQ(ST_SPEED_PU_PER_KRPM));

    This will give you the fixed-point result.  

    In the spintac_pos_move.h header file there are not inline functions that return the profile limits, but you can view those values by directly accessing the structure members according to the following:

    sttObj->pos.move.VelLim -> Velocity Limit

    sttObj->pos.move.AccLim -> Acceleration Limit

    sttObj->pos.move.DecLim -> Deceleration Limit

    sttObj->pos.move.JrkLim -> Jerk Limit

  • Adam, Thanks for the reply that explains a lot!