questions to java and a real robot

Typically: "How do I... ", "How can I... " questions
Stefan89
Posts: 11
Joined: 07 May 2013, 15:30

questions to java and a real robot

Post by Stefan89 » 08 May 2013, 08:21

Hello all together,

I am new to V-REP so there is still many stuff in the documentation that I have to read.

I want to use Java for programming the simulated robots. This is possible with the remote API, when I have understood that correctly.
I am currently trying to get the sample program running, but the following exception occures:
Exception in thread "main" java.lang.UnsatisfiedLinkError: remoteApi.simxStart(Ljava/lang/String;IZZI)I
at remoteApi.simxStart(Native Method)
at simpleTest.main(simpleTest.java:27)
This line is effected:

Code: Select all

if (vrep.simxStart("127.0.0.1",19999,true,true,5000)!=-1)
My removeAPIconnections.txt file:
//
// As an example:
//
portIndex1_port = 19999
portIndex1_debug = false
portIndex1_syncSimTrigger = true
I also have permitted that the port can be used by V-Rep in my firewall.

I am using

Code: Select all

System.loadLibrary("remoteApiJava");
to load the remoteApiJava.dll and the option
-Djava.library.path=D:\lib
to say where the library can be found.

Any ideas about this problem?

I think it should not be a problem to implement a Braitenberg Vehicle, a layer architecture, a subsumption architecture or a easy Bang Bang controller, right?

So a question came up to my mind. I have a real e-Puck and I am asking me now if it is possible to program it with Java via V-REP.

Can anybody give me answer on these questions?

Thanks a lot!

Stefan

coppelia
Site Admin
Posts: 7157
Joined: 14 Dec 2012, 00:25

Re: questions to java and a real robot

Post by coppelia » 08 May 2013, 20:59

Hello Stefan,

Did you trxy the example java application that came with the installation? It is located in programming/java/simpleTest.java. Also try to update to last version (V3.0.3), the remote API has improved and allows now multiple connections from a same client.

There is no problem imprementing the various algorithms you mention. I am not familiar with some of them, so some might need to be implemented in a plugin (as an example, it would be way to slow to implement a randomized path planning algorithm via the remote API (because of the communication lag). So carefully chose your control method from those available (in particular the table in that section).

And yes, you can program the epuck via the Java remote API.

Cheers

Stefan89
Posts: 11
Joined: 07 May 2013, 15:30

Re: questions to java and a real robot

Post by Stefan89 » 09 May 2013, 12:34

Hello!

Yes, that exception occurs with the sample implementation from the installation folder.

Well I will download the new version - I am currently using 3.0.2. Thanks for the hint.
I will give you a feedback as soon as I have tested it with the new version.

Is there any tutorial or some stuff where it documented how I can program the e-Puck or any other roboter via remote API, so that the real robot is doing the implemented tasks? :)

Thank you!

Stefan


EDIT:
I have now tested the sample implementation from the version 3.0.3 with the new version of the remove API for Java and it worked without any problems. :)
So I get no exceptions anymore.

coppelia
Site Admin
Posts: 7157
Joined: 14 Dec 2012, 00:25

Re: questions to java and a real robot

Post by coppelia » 09 May 2013, 21:39

Hello Stefan,

Glad it works ;)
You can have a look at the sample project programming/bubbleRobClient.vcproj (windows) or programming/bubbleRobClient_MakeFile (Mac and Linux). It shows a simple example where you control the BubbleRob robot from an external application. The corresponding scene is scenes/controlTypeExamples.ttt. The purple robot in that scene is controlled via the bubbleRobClient application mentionned above.

Cheers

Stefan89
Posts: 11
Joined: 07 May 2013, 15:30

Re: questions to java and a real robot

Post by Stefan89 » 12 May 2013, 10:12

Hello,

I had a look on the example you told me. That helped a lot - thanks. :)

I have still one big question:
Can I transfer my code on the real physical e-Puck and control it via V-Rep? I know that I can simulate the e-Puck, but can I also control the real physical e-Puck on my floor via a Bluetooth connection between V-Rep and the e-Puck? Is there any opportunity to connect V-Rep with the real physical e-Puck (like Bluetooth)?
Normally the real physically e-Puck can only be implemented by using C.

My question is, can I also use Java in connection with V-Rep to implement my real physical e-Puck? :)

Thanks a lot!

I with you a nice Sunday,

Stefan

coppelia
Site Admin
Posts: 7157
Joined: 14 Dec 2012, 00:25

Re: questions to java and a real robot

Post by coppelia » 13 May 2013, 12:27

Hi Stephan,

You have several possibilities:

You can control the real e-puck from V-REP using serial port commands. Refer to the example model models/robots/mobile/K-junior, and have a look how the serial port connection/communication is made (look into the child script attached to object KJunior_body).

You can also write a C/C++, Java, Python, Matlab or Urbi application that controls the e-puck, and that can optionally connect to V-REP via the remote API.

If your e-puck has a socket interface, then you can also directly use the remote API on the e-puck. This is actually a very elegant solution, since you would use the exact same code and location (i.e. on the real robot) to either control the real robot, or its simulation model.

And since the remote API also has a Java binding, java is also supported.

Cheers

Stefan89
Posts: 11
Joined: 07 May 2013, 15:30

Re: questions to java and a real robot

Post by Stefan89 » 13 May 2013, 13:41

Hello,

well the e-Puck has a Bluetooth interface and no serial port.

So there is no socket - it should be a little bit difficult then, isn't it?

I have another question about programming the V-Rep simulation with Java. This is currently my Java code:

Code: Select all

	
public static void main(String[] args) {
		// load remote API
		System.loadLibrary("remoteApiJava");
		remoteApi vrep = new remoteApi();
		// try to connect/start simulation
		int clientID = vrep.simxStart("127.0.0.1", 19998, true, true, 5000, 5);
		// check if connection could be established
		if (clientID != vrep.simx_error_noerror) {
			System.out.println("Failed connecting to remote API server");
			return; // stop here
		}

		// load scene
		int loadScene = vrep
				.simxLoadScene(
						clientID,
						"C:/V-Rep/Scene/Scene_with_real_walls_and_epuck.ttt",
						1, vrep.simx_opmode_oneshot_wait);
		if (loadScene != vrep.simx_error_noerror) {
			System.out.println("Failed loading scene " + loadScene);
			return;
		}

		// start simulation
		vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot_wait);

		while (vrep.simxGetConnectionId(clientID) != -1) {
			// if obstacle is in front of the robot
			// turn right otherwise drive forward
		}

		vrep.simxFinish(clientID);
	}
I had another look on the C++ example - its not clear to me how I can set the motor speed of a robot, because i have no robot object - how do i get it?
-Can I get a robot by using simxGetObjectHandle()?
-Can I read the distance values by using simxGetDistanceHandle()?

The user interface dialog of thee-Puck shows no sensor values during simulation - is that normal? Do I have to activate something?

Thank you.

Stefan

coppelia
Site Admin
Posts: 7157
Joined: 14 Dec 2012, 00:25

Re: questions to java and a real robot

Post by coppelia » 14 May 2013, 10:36

Stefan,

I am not a Bluetooth expert, but my guess is (and this is also how it works in the K-Junior robot) that you send serial port data that are send via a bluetooth signal and vice-versa.

About your other questions:
The e-puck model is just an example. You might have to adapt it. Make sure you look inside the attached child scripts for details.

Cheers

Stefan89
Posts: 11
Joined: 07 May 2013, 15:30

Re: questions to java and a real robot

Post by Stefan89 » 14 May 2013, 20:29

Hello,

okay - thanks for the hint with the K-Junior robot.

I had a look on the Child Script of the e-Puck. The distance sensors and the light sensors seem to be implemented for me.
I had also a look on the custom user interface of the e-Puck. It is associated with the e-Puck object.

So I do not understand why the sensor values are not displayed on the UI. :(

Sorry for the beginners questions.

Thank you for your help!

Stefan

coppelia
Site Admin
Posts: 7157
Joined: 14 Dec 2012, 00:25

Re: questions to java and a real robot

Post by coppelia » 14 May 2013, 20:51

Stefan,

The proximity sensor reading of the ePuck is displayed in the custom user interface! Make sure an obstacle is close enough, otherwise they will simply display a 0. The proximity sensor's range is around 4cm. Also make sure the obstacle is detectable!

Cheers

Post Reply