Fingers Controlling Individually

From the GUI

Switch to Dialog tab which is a dialog I developed to test all of the features. Use the text box to input velocity value for each fingers and the corresponding buttons to execute the commands (fold or unfold the fingers.) Use RFx All to control them all with the velocity values set in the text boxes.

Video

Code walkthrough

To accomplish this, I defined two new variables in the PSHARED_DATA structure in SharedMemory.h:

int RFxDataFloat[5];   // store the velocity values for each finger
int RFxSelect;         // store the command targetL RF1..5 or -1 for all fingers

Next, define new command flags in COMMAND_FLAG enum in CommonDefinition.h named: RFx_CMD_OPEN and RFx_CMD_FOLD.

Next, add two cases to the switch statement in main()

case RFx_CMD_FOLD:
     if (pSharedMemory->RFxSelect == -1)
          for(i=RF1;i<=RF5;i++) Joint[i].RefVelCurrent = -pSharedMemory->RFxDataFloat[i-28];
     else Joint[pSharedMemory->RFxSelect].RefVelCurrent = -pSharedMemory->CommandDataFloat[0];

     MoveJMC(EJMC4);
     pSharedMemory->CommandFlag = NO_ACT;
     break;
case RFx_CMD_OPEN:
     if (pSharedMemory->RFxSelect == -1)
         for(i=RF1;i<=RF5;i++) Joint[i].RefVelCurrent = pSharedMemory->RFxDataFloat[i-28];
     else Joint[pSharedMemory->RFxSelect].RefVelCurrent = pSharedMemory->CommandDataFloat[0];

     MoveJMC(EJMC4);
     pSharedMemory->CommandFlag = NO_ACT;
     break;

Finally, add button controls and click events to the GUI

void CHandDlg::OnRf1fold()
{
    // TODO: Add your control notification handler code here
    CString buttonText;

    GetDlgItem(IDC_RF1CURRENT)->GetWindowText(buttonText);
    pSharedMemory->CommandDataFloat[0] = (float)atof(buttonText);
    Sleep(10);

    GetDlgItem(IDC_RF1FOLD)->GetWindowText(buttonText);
    pSharedMemory->RFxSelect = RF1;

    if(pSharedMemory->CommandFlag == NO_ACT)
    {
        if(buttonText == "RF1 Fold")
        {
            GetDlgItem(IDC_RF1FOLD)->SetWindowText("RF1 Open");
            pSharedMemory->CommandFlag = RFx_CMD_FOLD;
        }
        else
        {
            GetDlgItem(IDC_RF1FOLD)->SetWindowText("RF1 Fold");
            pSharedMemory->CommandFlag = RFx_CMD_OPEN;
        }
        Sleep(10);
    }
    else AfxMessageBox("Other Command is activated..!!");
}

void CHandDlg::OnRf2fold()
{
    // TODO: Add your control notification handler code here
    CString buttonText;

    GetDlgItem(IDC_RF2CURRENT)->GetWindowText(buttonText);
    pSharedMemory->CommandDataFloat[0] = (float)atof(buttonText);
    Sleep(10);

    GetDlgItem(IDC_RF2FOLD)->GetWindowText(buttonText);
    pSharedMemory->RFxSelect = RF2;

    if(pSharedMemory->CommandFlag == NO_ACT)
    {
        if(buttonText == "RF2 Fold")
        {
            GetDlgItem(IDC_RF2FOLD)->SetWindowText("RF2 Open");
            pSharedMemory->CommandFlag = RFx_CMD_FOLD;
        }
        else
        {
            GetDlgItem(IDC_RF2FOLD)->SetWindowText("RF2 Fold");
            pSharedMemory->CommandFlag = RFx_CMD_OPEN;
        }
        Sleep(10);
    }
    else AfxMessageBox("Other Command is activated..!!");
}

void CHandDlg::OnRf3fold()
{
    // TODO: Add your control notification handler code here
    CString buttonText;

    GetDlgItem(IDC_RF3CURRENT)->GetWindowText(buttonText);
    pSharedMemory->CommandDataFloat[0] = (float)atof(buttonText);
    Sleep(10);

    GetDlgItem(IDC_RF3FOLD)->GetWindowText(buttonText);
    pSharedMemory->RFxSelect = RF3;

    if(pSharedMemory->CommandFlag == NO_ACT)
    {
        if(buttonText == "RF3 Fold")
        {
            GetDlgItem(IDC_RF3FOLD)->SetWindowText("RF3 Open");
            pSharedMemory->CommandFlag = RFx_CMD_FOLD;
        }
        else
        {
            GetDlgItem(IDC_RF3FOLD)->SetWindowText("RF3 Fold");
            pSharedMemory->CommandFlag = RFx_CMD_OPEN;
        }
        Sleep(10);
    }
    else AfxMessageBox("Other Command is activated..!!");
}

void CHandDlg::OnRf4fold()
{
    // TODO: Add your control notification handler code here
    CString buttonText;

    GetDlgItem(IDC_RF4CURRENT)->GetWindowText(buttonText);
    pSharedMemory->CommandDataFloat[0] = (float)atof(buttonText);
    Sleep(10);

    GetDlgItem(IDC_RF4FOLD)->GetWindowText(buttonText);
    pSharedMemory->RFxSelect = RF4;

    if(pSharedMemory->CommandFlag == NO_ACT)
    {
        if(buttonText == "RF4 Fold")
        {
            GetDlgItem(IDC_RF4FOLD)->SetWindowText("RF4 Open");
            pSharedMemory->CommandFlag = RFx_CMD_FOLD;
        }
        else
        {
            GetDlgItem(IDC_RF4FOLD)->SetWindowText("RF4 Fold");
            pSharedMemory->CommandFlag = RFx_CMD_OPEN;
        }
        Sleep(10);
    }
    else AfxMessageBox("Other Command is activated..!!");
}

void CHandDlg::OnRf5fold()
{
    // TODO: Add your control notification handler code here
    CString buttonText;

    GetDlgItem(IDC_RF5CURRENT)->GetWindowText(buttonText);
    pSharedMemory->CommandDataFloat[0] = (float)atof(buttonText);
    Sleep(10);

    GetDlgItem(IDC_RF5FOLD)->GetWindowText(buttonText);
    pSharedMemory->RFxSelect = RF5;

    if(pSharedMemory->CommandFlag == NO_ACT)
    {
        if(buttonText == "RF5 Fold")
        {
            GetDlgItem(IDC_RF5FOLD)->SetWindowText("RF5 Open");
            pSharedMemory->CommandFlag = RFx_CMD_FOLD;
        }
        else
        {
            GetDlgItem(IDC_RF5FOLD)->SetWindowText("RF5 Fold");
            pSharedMemory->CommandFlag = RFx_CMD_OPEN;
        }
        Sleep(10);
    }
    else AfxMessageBox("Other Command is activated..!!");
}

void CHandDlg::OnRfallstop()
{
    // TODO: Add your control notification handler code here

    if(pSharedMemory->CommandFlag == NO_ACT)
    {
        pSharedMemory->CommandFlag = GRIP_STOP;
        Sleep(10);
    }
    else AfxMessageBox("Other Command is activated..!!");
}

void CHandDlg::OnRfall()
{
    // TODO: Add your control notification handler code here
    CString buttonText;

    GetDlgItem(IDC_RF1CURRENT)->GetWindowText(buttonText);
    pSharedMemory->RFxDataFloat[0] = (float)atof(buttonText);
    GetDlgItem(IDC_RF2CURRENT)->GetWindowText(buttonText);
    pSharedMemory->RFxDataFloat[1] = (float)atof(buttonText);
    GetDlgItem(IDC_RF3CURRENT)->GetWindowText(buttonText);
    pSharedMemory->RFxDataFloat[2] = (float)atof(buttonText);
    GetDlgItem(IDC_RF4CURRENT)->GetWindowText(buttonText);
    pSharedMemory->RFxDataFloat[3] = (float)atof(buttonText);
    GetDlgItem(IDC_RF5CURRENT)->GetWindowText(buttonText);
    pSharedMemory->RFxDataFloat[4] = (float)atof(buttonText);
    Sleep(10);

    GetDlgItem(IDC_RFALL)->GetWindowText(buttonText);
    pSharedMemory->RFxSelect = -1;

    if(pSharedMemory->CommandFlag == NO_ACT)
    {
        if(buttonText == "RFx All")
        {
            GetDlgItem(IDC_RFALL)->SetWindowText("RFx Open");
            pSharedMemory->CommandFlag = RFx_CMD_FOLD;
        }
        else
        {
            GetDlgItem(IDC_RFALL)->SetWindowText("RFx All");
            pSharedMemory->CommandFlag = RFx_CMD_OPEN;
        }
        Sleep(10);
    }
    else AfxMessageBox("Other Command is activated..!!");
}

~