Advertisement
goodvibes2298

Martin help prosim

Mar 26th, 2025
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. void IKMovementUpdate(void){
  2.     int maxSize = 10;
  3.     int segmentSize = maxSize/5; // Always divide into 5 movement segments with different velocities
  4.     int segmentIndex = 0;
  5.     uint16_t m_velocity = g_velocity;
  6.     int posIndex = 0;
  7.     float floatXActualPos3 = 0;
  8.  
  9.     static uint32_t lastTick = 0;
  10.     uint32_t currentTick = HAL_GetTick();
  11.  
  12.     bool posReached = false;
  13.  
  14.     for(int i = 1; i < 11; i++){
  15.         motorData3.positionBuffer[i-1] = 1500 * i;
  16.  
  17.         //motorData3.velocityBuffer[i] = 2;
  18.     }
  19.  
  20.     float velocityBuffer[10] = {0.5, 0.5, 1, 1, 1.5, 1.5, 1, 1, 0.5, 0.5};
  21.  
  22.     setPos(motorData3.positionBuffer[0], m_velocity, MOTOR3);
  23.  
  24.     while(g_IKinProgress){
  25.  
  26.  
  27.         if (currentTick - lastTick >= 500) { // 10 ms interval
  28.             lastTick = currentTick;
  29.             posReached = getIfPosReached(MOTOR3);
  30.             floatXActualPos3 = getPosition(MOTOR3);
  31.  
  32.  
  33.         }
  34.         XActualPos3 = (int)floatXActualPos3;
  35.  
  36.  
  37.  
  38. //        floatXActualPos3 = getPosition(MOTOR3);
  39. //
  40. //        XActualPos3 = (int)floatXActualPos3;
  41. //
  42. //        posReached = getIfPosReached(MOTOR3);
  43.  
  44.         // MOTOR3
  45.         if(XActualPos3 >= motorData3.positionBuffer[posIndex]){
  46.         //if(posReached && posIndex < 10){
  47.             switch (segmentIndex) {
  48.                     case 0:
  49.                         m_velocity = g_velocity * 0.5f;
  50.                         break;
  51.                     case 1:
  52.                         m_velocity = g_velocity * 1;
  53.                         break;
  54.                     case 2:
  55.                         m_velocity = g_velocity * 1.5f;
  56.                         break;
  57.                     case 3:
  58.                         m_velocity = g_velocity * 1;// * motorData3.speedBuffer[posIndex];
  59.                         break;
  60.                     case 4:
  61.                         m_velocity = g_velocity * 0.5f;
  62.                         g_IKinProgress = false;
  63.                         break;
  64.                     default:
  65.                         break;
  66.                 }
  67.  
  68.             posIndex++;
  69.             //_velocity = (uint16_t) (g_velocity * velocityBuffer[posIndex]);
  70.             setPos(motorData3.positionBuffer[posIndex], m_velocity, MOTOR3);
  71.  
  72.  
  73.             if (posIndex != 0 && posIndex % segmentSize == 0) {
  74.                 segmentIndex++;
  75.             }
  76.         }
  77.  
  78.  
  79.  
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement