loading
 
Programming Irobot Create via C
Nimit from United States  [3 posts]
15 year
Hi,

I'm trying to program the irobot create and I wanted to use the GUI from roborealm to do this. The concept which I am using is writing C code which changes the value of the GUI controls, which in turn change the values on the irobot create. My problem is that when I run a C program, it changes the values in the GUI but then the connection is lost ie OI mode changes to Safe and the COM port changes to some unused port. I cant seem to understand why this might be happening. Any help would be appreciated. Thanks. Following is my C code.

#include<stdio.h>
#include "RR_API.h"

void main(){
    RR_API rr;
    char *name[1];    
    char ip_add[24] = "127.0.0.1";
    
    while(!rr.connect(ip_add, 6060)){
        printf("not connecting");
    }
    
    name[0] = "IRobot_Create";
    rr.setParameter(name[0], 1, "left_motor_value", "90");
}
Anonymous 15 year
Nimit,

You got the right idea but that technique is a final resort technique when you cannot change the parameters using other means. What is happening is that when you use both the API and the interface things can get confused. When the API executes that command it will cause the rest of the interface to return to the way it was when the interface first poped up. UNLESS you press Ok, and then reedit the interface. I.e. the interface reverts back to the last saved configuration (you save it by pressing the ok button).

However, I'd recommend a completely different technique. Select a variable in that GUI or type one in like "left_motor". The rest of the interface for that motor will become disabled. Then use the API to set that variables value using

rr.SetVariable("left_motor", "90")

which is the recommended way of doing this ... and also about 100x faster than the SetParameter technique which has to update a lot of GUI components.

i.e. you provide the variable that the interface should use to get the motor value and you then use the API to change that value.

STeven.
Nimit from United States  [3 posts] 15 year
Hi Steven,

Thanks for the answer. On the lines of accessing variables, I want to access the values of the sensors like Distance, Angle, Bump Left etc. In the GUI, there is a drop down called Sensor Name. When I set the variable to look at any of the sensor values, the variable once initialized never changes value. Thus I cant get live values from the sensors. Is there a way to do this?

Thanks,
Nimit
Anonymous 15 year
Nimit,

We cannot seem to replicate the issue. We attached two variables to the bump sensors and ran the below robofile (you will have to change the port number) and using the watch module we could see the bump changes.

Perhaps you can include your robofile so that we can test that?

STeven.
program.robo
Nimit from United States  [3 posts] 15 year
Hi Steven,

I've attached my .robo file. Presently I am trying to read distance and angle information. But I would eventually need information on bump sensors too. It seems that the Java API files are working but the C API files are unable to read the variable values. Any reason why this might be happening?

Regards,
Nimit
Nimit from United States  [3 posts] 15 year
Hi Steven,

I am attaching my .robo file. Presently am trying to read only distance and angle sensors. But eventually I would require information from bump sensors too. I am trying to run both the C and Java APIs and I could get the variable values from the Java API but not for the C API. The way I had to do it is to start the server (click Start in the GUI), then assign the sensors to particular variables. This allows me to read the values using the Java API but the C API is still unable to get the variable values.

Regards,
Nimit
program.robo
Anonymous 15 year
Nimit,

Ok, then you don't have an issue with the Create module but an issue with the C++ API?

Are you running the Java and the C++ api calls at the same time? If so you will need to increase the number of threads in the API server. See the Options Button->API Server tab and the Threads dropdown. Be sure that this is set to 5 or something more than 1. Then press OK, and try both interfaces again.

Yes, you are correct in that you have to press the start button and assign variable in the dropdowns ... that's the way it is supposed to work. This allows you to assign your own names (that you can hopefully remember) to certain motor values, sensors etc. Then you need to use these same names in the API calls in order to get that information.

Hopefully increasing the number of threads does the trick. The C++ version should be more up to date than the Java version so ensure that you also have a most recent copy of RR AND of the API. There was an issue a couple weeks ago with the GetVariables routine in the API. Maybe that is your issue also.

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