## Which sensor should i use to get similar behaviour as an LDR

Typically: "How do I... ", "How can I... " questions
AmrabdDZ
Posts: 3
Joined: 01 Apr 2021, 02:01

### Which sensor should i use to get similar behaviour as an LDR

Hello everyone ;

So i'm working actually on a project with a 2 DoF robot arm carrying a solar panel to get the MPP (Maximum Power Point), i did a first solution using Matlab and Vrep based on a solar position algorithm and it was perfect.

Now i have to do a second solution to track the sun using 4 LDR sensors, i want to know how could i do that in Vrep, i read a little bit about vision sensor, i think its the best choice but how can i use its features to have similar behaviour as an LDR. and especially a sensor that i can read its data using Matlab API Functions.

Note: i used an omnidirectional light inside a yellew sphere to simulate sun, and they move together using real data position coming from Matlab.

Thanks for helping me.
Best regards ;
AMIRI.

AmrabdDZ
Posts: 3
Joined: 01 Apr 2021, 02:01

### Re: Which sensor should i use to get similar behaviour as an LDR

coppelia
Posts: 8531
Joined: 14 Dec 2012, 00:25

### Re: Which sensor should i use to get similar behaviour as an LDR

You cannot directly measure the light intensity by looking at a light: the light will not be shown, only its effect on surfaces is seen (illumination of the surface). So instead of having a vision sensor look towards the light source, have it look towards the illuminated surface (e.g. the solar panel). Or create a new type of sensor with a small rectangular, white shape, and a very low-res vision sensor looking at it from above.

Then you can measure the intensity of the vision sensor with sim.readVisionSensor:

Code: Select all

    local result,packet1=sim.readVisionSensor(visionSensorHandle)
if result>0 then
local averageIntensity=packet1[11]
end
Then there are different ways you can make that value available to Matlab. E.g. using the legacy remote API, if you place the data in a signal with sim.setFloatSignal, you can read it with simxGetFloatSignal. You could also directly pick the data up by calling simxCallScriptFunction, where on the CoppeliaSim side you'd have something like:

Code: Select all

function sysCall_init()
visionSensorHandle=sim.getObjectHandle(sim.handle_self)
averageIntensity=0
end

function sysCall_sensing()
if result>0 then
averageIntensity=packet1[11]
end
end

function getData(inInts,inFloats,inStrings,inBuffer)
return {},{averageIntensity},{},''
end
Above would be more convenient if you have to deal with several sensors and several values to fetch from CoppeliaSim.

Cheers

AmrabdDZ
Posts: 3
Joined: 01 Apr 2021, 02:01

### Re: Which sensor should i use to get similar behaviour as an LDR

Thank you @coppelia this is very helpful, i totaly understand your solution.

So yesterday i was testing by myself and i found an other solution, is making the light inside a yellow sphere shape and give them the same mouvement while the simulation, so the light will be always inside the yellow sphere while moving, and i ll place the vision sensors on the solar panel while they can't see anything just the sphere and then i will use sim.simxReadVisionSensor Matlab API function , for each of the four vision sensors that i have and i will use the average intensity auxPacket[11] the same way as a signal of the intensity of light detected by an LDR and develop my algorithm.