Recommendations on getting started with VREP/Arduino

Typically: "How do I... ", "How can I... " questions
coppelia
Site Admin
Posts: 7199
Joined: 14 Dec 2012, 00:25

Re: Recommendations on getting started with VREP/Arduino

Post by coppelia » 08 Mar 2016, 10:06

Sometimes there is a buffer that is being sent only when there is enough data in it. Try to send continuously data from your Arduino, and see if you can read something.

Cheers

dnahar
Posts: 30
Joined: 07 Jan 2016, 03:03

Re: Recommendations on getting started with VREP/Arduino

Post by dnahar » 11 Mar 2016, 19:59

This is not at all helping. I come to the forum, only when i have tried myself many things and couldn't figure out a solution. Could you please help me with the code just to receive simple numbers from arduino and display it on custom user interface? I am able to send code to arduino, but cant receive anything.

(note: receiving of arduino data can be seen on serial monitor of arduino, that means arduino is sending data)

Thanks,
Dixit

Eric
Posts: 186
Joined: 11 Feb 2013, 16:39

Re: Recommendations on getting started with VREP/Arduino

Post by Eric » 13 Mar 2016, 01:13

Please refer to my post on the first page of this thread to find your answer!

Cheers

Eric

dnahar
Posts: 30
Joined: 07 Jan 2016, 03:03

Re: Recommendations on getting started with VREP/Arduino

Post by dnahar » 13 Mar 2016, 02:40

Hello Eric,

Your posts and video is very helpful. I developed the code based on the arduino esplora mode and seeing the video only. I have posted my code in my previous posts here. The problem is i cant receive any information from arduino to vrep, i am able to send it to arduino. This doesnt make sense to me, i have tried many ways. Could you look into my code and suggest me the solution.

Or could you give me a simple code in arduino and vrep, that gets some simple information from arduino and i can display it in vrep.

This is quite an emergency now.

Thanks,
Dixit

Eric
Posts: 186
Joined: 11 Feb 2013, 16:39

Re: Recommendations on getting started with VREP/Arduino

Post by Eric » 13 Mar 2016, 14:49

The serial monitor of the arduino is not running when you are sending the data to V-REP right? You know that if you do so the port of com would already be used and V-REP could never connect and receive data ....

dnahar
Posts: 30
Joined: 07 Jan 2016, 03:03

Re: Recommendations on getting started with VREP/Arduino

Post by dnahar » 13 Mar 2016, 15:17

No Sir. I just quoted about the serial monitor to tell that Arduino does send data which I can see on serial monitor.

Again, the problem is that I can send data using serial communication from vrep to arduino but I cant receive any data sent from arduino to vrep using serial communication.

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

Re: Recommendations on getting started with VREP/Arduino

Post by coppelia » 14 Mar 2016, 09:55

Dixit, please be aware that you probably use the free version of V-REP, you also get free support. Then, we are not from the Arduino company, we don't even have an Arduino here, so our possibilities are limited. Your questions are vague and we don't have all the code you are using to do the writing and reading (e.g. Arduino-side code).

Cheers

dnahar
Posts: 30
Joined: 07 Jan 2016, 03:03

Re: Recommendations on getting started with VREP/Arduino

Post by dnahar » 15 Mar 2016, 00:27

I understand. I admire VREP and propagate it to be an excellent package with a responsive forum. I only wish it to grow.

I have posted vrep and arduino code in my previous posts here, i just ask if my code on vrep side is correct and sufficient to receive any data from arduino or do i have to add anything to it?
The problem may be similar to this : http://forum.arduino.cc/index.php?topic=50266.0

and alongwith, i am facing this problem that as i set the label in a non-threaded script within "while (simGetSimulationState()~=sim_simulation_advancing_abouttostop) do" using "simSetUIButtonLabel(uiHandle,27,"100","")", the label 27 just blinks with value 100 once after i stop the simulation. During the simulation it doesnt become 100 which it should be. Could you suggest something here?

Thanks,
Dixit

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

Re: Recommendations on getting started with VREP/Arduino

Post by coppelia » 15 Mar 2016, 09:36

About the label problem: if you stop the simulation, a threaded child script will break out its various routines, and might still execute some other code in the sequence. That's what is probably happening. Also, try to use print statements in your child script to see if a command is really executed (you can check the console window to see if your prints appear). You can of course also use simAddStatusbarMessage or simAuxiliaryConsoleOpen or similar. Always check the status bar for error messages!

Cheers

dnahar
Posts: 30
Joined: 07 Jan 2016, 03:03

Re: Recommendations on getting started with VREP/Arduino

Post by dnahar » 21 Mar 2016, 20:22

while in this loop : "while (simGetSimulationState()~=sim_simulation_advancing_abouttostop) do" in the threaded child script, i want to read the values from arduino using serial comm, and print it on console.

1. I am able to print it just once, and i can see it in the console window only when i stop the simulation. This tells me that it is not running in a loop and executing just once. This might be the reason i am not receiving anything from arduino. It is supposed to run many times in a loop, right? I cross-checked it creating a non-threaded child scripts and i could see lot of values on the console window which asssures me the non-threaded child script is running in loop.

Why is my threaded child script not looping??

2. I am not able to access variables initialized in the initialization phase, in non-threaded child script.

Code: Select all

-- DO NOT WRITE CODE OUTSIDE OF THE if-then-end SECTIONS BELOW!! (unless the code is a function definition)

if (sim_call_type==sim_childscriptcall_initialization) then
portNumber="\\\\.\\COM4"
-- for serial port
baudrate=9600

serial=simSerialOpen(portNumber,baudrate)
		print(serial)

end


if (sim_call_type==sim_childscriptcall_actuation) then

-- for UI

--if (simGetScriptExecutionCount()==0) then
   uiHandle=simGetUIHandle('UI')
--end

button,auxData=simGetUIEventButton(uiHandle)

-- update sensor weights
--for i = 1,9,1 do
	str0 = simSerialRead(serial,100,false,'\n',100)
	simSetUIButtonLabel(uiHandle,25,str0,"")
	simSetUIButtonLabel(uiHandle,29,"100","")
--end

	if str0 ~= nil then
		print(str0)
		simSetUIButtonLabel(uiHandle,27,str0,"")
	end
		--simSetUIButtonLabel(uiHandle,27,"100","")
serial=simSerialOpen(portNumber,baudrate)

if (button==3) then
	signal='9'
	simSerialSend(serial,signal) 
elseif (button==47) then
--	serial=simSerialOpen(portNumber,baudrate)
	signal="R"
	simSerialSend(serial,signal)
	
	str0 = simSerialRead(serial,100,false,'\n',1000)
	print(str0)
	simSetUIButtonLabel(uiHandle,25,str0,"")
	print('10')

end
--thats it for UI

	-- Put your main ACTUATION code here

	-- For example:
	--
	-- local position=simGetObjectPosition(handle,-1)
	-- position[1]=position[1]+0.001
	-- simSetObjectPosition(handle,-1,position)

end


if (sim_call_type==sim_childscriptcall_sensing) then

	-- Put your main SENSING code here

end


if (sim_call_type==sim_childscriptcall_cleanup) then
	-- Put some restoration code here

end
Throws error on accessing "serial" in the actuation phase.

Thanks,
Dixit

Post Reply