loading
 
GetVariables
Anonymous
17 year
Ive looked at the API example on getting variables from roborealm but am having problems using these values once I have used the GetVariables function to get them. How do you save the array pointer results from getvariables into a char array so that you can use the values in c++. This is my funstion for getting values from Roborealm:

void Robovariables(char input[5][32])
{
    //Initialises results pointer and a buffer resultBuffer to get variables from Roborealm
    
    char resultsBuffer[300]=("");
    char *variables[6];
    variables[0]=resultsBuffer;
    variables[1]=&resultsBuffer[32];
    variables[2]=&resultsBuffer[64];
    variables[3]=&resultsBuffer[98];
    variables[4]=&resultsBuffer[128];
    variables[5]=&resultsBuffer[192];

    //Gets the Variable values from Roborealm using the Roborealm API
    if (rr.getVariables("laser1, laser2, FACE_POSITION, turn_bias, COLOUR_COG_X, FACE_POSITION", variables,300, 6)!=6)
    {
        System::Windows::Forms::MessageBox::Show(L"Error Receiving variables from Roborealm",
        L"RoboRealm Error", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
        exit(0);
    }
    else
    {
        
        int i;
        int j;
        //Loops through wariables 2d array pointer and allocates these values to the input pointer
        for(i=0; i<6;i++)
        {
            for(j=0;j<32;j++)
            {
                input[i][j]=variables[i][j];
            }
        }        
    }

}

Am I doing this the best way? I know that this isnt the proper way to do this so what is? I looked at the API main.cpp to do this
Anonymous 17 year
another thing to note is that when I initiate resultsBuffer without making it equal to "" It ends ub being filled with rubbish characters, i noticed in the API example the buffer is filled with funny I symbols.
Anonymous 17 year
Yes, you need to initialize the resultsBuffer to zero ... typically this is done using


memset(resultsBuffer, 0, sizeof(resultsBuffer))

otherwise the results will just be full of garbage.

Once you have the results as strings you can convert them to float or ints/chars by using the

atof()

or

atoi()

C/C++ functions on each element of that array.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index