Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void IKMovementUpdate(void){
- int maxSize = 10;
- int segmentSize = maxSize/5; // Always divide into 5 movement segments with different velocities
- int segmentIndex = 0;
- uint16_t m_velocity = g_velocity;
- int posIndex = 0;
- float floatXActualPos3 = 0;
- static uint32_t lastTick = 0;
- uint32_t currentTick = HAL_GetTick();
- bool posReached = false;
- for(int i = 1; i < 11; i++){
- motorData3.positionBuffer[i-1] = 1500 * i;
- //motorData3.velocityBuffer[i] = 2;
- }
- float velocityBuffer[10] = {0.5, 0.5, 1, 1, 1.5, 1.5, 1, 1, 0.5, 0.5};
- setPos(motorData3.positionBuffer[0], m_velocity, MOTOR3);
- while(g_IKinProgress){
- if (currentTick - lastTick >= 500) { // 10 ms interval
- lastTick = currentTick;
- posReached = getIfPosReached(MOTOR3);
- floatXActualPos3 = getPosition(MOTOR3);
- }
- XActualPos3 = (int)floatXActualPos3;
- // floatXActualPos3 = getPosition(MOTOR3);
- //
- // XActualPos3 = (int)floatXActualPos3;
- //
- // posReached = getIfPosReached(MOTOR3);
- // MOTOR3
- if(XActualPos3 >= motorData3.positionBuffer[posIndex]){
- //if(posReached && posIndex < 10){
- switch (segmentIndex) {
- case 0:
- m_velocity = g_velocity * 0.5f;
- break;
- case 1:
- m_velocity = g_velocity * 1;
- break;
- case 2:
- m_velocity = g_velocity * 1.5f;
- break;
- case 3:
- m_velocity = g_velocity * 1;// * motorData3.speedBuffer[posIndex];
- break;
- case 4:
- m_velocity = g_velocity * 0.5f;
- g_IKinProgress = false;
- break;
- default:
- break;
- }
- posIndex++;
- //_velocity = (uint16_t) (g_velocity * velocityBuffer[posIndex]);
- setPos(motorData3.positionBuffer[posIndex], m_velocity, MOTOR3);
- if (posIndex != 0 && posIndex % segmentSize == 0) {
- segmentIndex++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement