questions to java and a real robot

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

Re: questions to java and a real robot

Post by Stefan89 » 16 May 2013, 06:27

Hi,

okay that's fine. :)
Now it works. :)

I have a last question:
You say the sensor values are always zero when there is no obstacle or something other detectable. So there is no kind of sensor noise in V-Rep, right? :)

Thanks for your help and for your patience.

Stefan

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

Re: questions to java and a real robot

Post by coppelia » 16 May 2013, 09:24

Hi Stephan,

Proximity sensor readings are zero when not detecting anything in that particular example. The API function simReadProximitySensor will signal if nothing was detected, so you can handle that case as you wish.

Also, proximity sensors in V-REP are geometrically exact, but you are free to add noise on top of that in order to correctly model a real proximity sensor. You can do that using a child script.

Cheers

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

Re: questions to java and a real robot

Post by Stefan89 » 16 May 2013, 10:15

Hi,

okay - the child script comes up to my mind after I have written the post. :)

So thank you for your help. :)

Now I know everything I need to know - the rest I will find out by the documentation I think.

Thanks a lot!

Stefan


Edit:

Well I think I am not right.... I can't get everything from the documentation. :(

As you know I try to simulate a e-Puck.
I get the handle of one proximity sensor with this code - its the sensor on the left side of the robot:

Code: Select all

		IntW sensor = new IntW(1);
		vrep.simxGetObjectHandle(clientID, "ePuck_proxSensor1", sensor,
				vrep.simx_opmode_oneshot_wait);
I don't know how I get the value of the sensor??
I tried to following code:

Code: Select all

vrep.simxReadProximitySensor(clientID, s_left.getValue(),	detectionState, detectionPoint, null, null, vrep.simx_opmode_oneshot_wait)
Well - the method itself just returns the error code saying tell me if the operation was successful or not - always 0 is returned - so everything worked fine.
detectionState is always false and detectionPoint is an array - I don't get through what the values in the array mean?

In the documentation:
"detectedPoint: the detected point coordinates (relative to the sensor reference frame)"
The values are the x, y and z coordinated of the point. But what shall I do with these points? :(

I just want the value of the proximity sensor. :(

Another thing is, that I tried to stop the robot.
For this i used this code:

Code: Select all

IntW left_motor = new IntW(1);
IntW right_motor = new IntW(1);
vrep.simxGetObjectHandle(clientID, "ePuck_leftJoint", left_motor,vrep.simx_opmode_oneshot_wait);
vrep.simxGetObjectHandle(clientID, "ePuck_rightJoint", right_motor,	vrep.simx_opmode_oneshot_wait);

System.out.println("return value: "+ vrep.simxSetJointTargetVelocity(clientID,left_motor.getValue(), 0,vrep.simx_opmode_oneshot));

System.out.println("return value: "+ vrep.simxSetJointTargetVelocity(clientID,right_motor .getValue(), 0,vrep.simx_opmode_oneshot));
The result returned by each method is also 0 - so no error occurred. But the robot is still driving.
Then I found the child script of the robot in the simulator. It is a sample implementation that I don't need - so I cleared it.

-When I have understood it correctly the robot should not move now, because there is no child script for it - but my robot is still moving when I start the simulation.
-When I start the simulation by using the remote API, the simulation starts fine. But the robot is moving forward and tell him this to do. The child script is empty.
-Clearing the child script has as result, that the user interface displays no sensor values anymore. Copied the existing LUA code that manages this. So this works fine now.

The user interface in V-Rep displays the sensor values correctly, when the robot is driving into the wall.

Can you please help me again? :(

Thank you

Stefan

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

Re: questions to java and a real robot

Post by Stefan89 » 20 May 2013, 18:16

Hello,

I have solved the problem of setting the engine speed now. It was a problem in my scene.

But I have still problems with reading the proximity sensor values.

From the documentation:
detectedPoint: coordinates of the closest detected point (x, y and z: detectedPoint[0]-detectedPoint[2]) relative to the sensor reference frame, and distance to the detected point (1 value: detectedPoint[3]). Can be NULL
Normally the value on index 3 would be the distance. But the remote API returns only an array of size 3 where index 0 is the x coordinate, index 1 the y coordinate and index 2 the z coordinate.

Where is the distance? :(

With detectionState I get true or false depending on if something was detected or not.

I need the distance value, not just a true or false value - is that also possible?

Thanks!

Stefan

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

Re: questions to java and a real robot

Post by coppelia » 20 May 2013, 18:27

Hello Stefan,

I am a little bit confused... What API function are you referring to?
In any case, you can obtain the distance to the detected point also from the detected point coordinates:

distance=sqrt(x*x+y*y+z*z)

Cheers

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

Re: questions to java and a real robot

Post by Stefan89 » 20 May 2013, 19:23

Hello,

ahhh! That was what I have searched!

Now I can calculate the distance and everything is fine. :)

Thanks a lot! :)

It works fine now =)

Post Reply