Change color of a primitive shape from remote Api (Matlab)

Typically: "How do I... ", "How can I... " questions
Post Reply
DavideIng
Posts: 34
Joined: 21 Sep 2017, 17:27

Change color of a primitive shape from remote Api (Matlab)

Post by DavideIng » 11 Oct 2017, 17:11

Hello,
the following it's the code that I have wrote on matlab to get the absolute position of the epuck on the scenes and to try to change the color of a plane (primitive shape) from a remote Api (Matlab), this second instruction doesn't works.

Code: Select all

disp('Program started');
vrep=remApi('remoteApi'); % oggetto remoto chiamato vrep
vrep.simxFinish(-1); % chiusura di ogni precedente connessine
clientID=vrep.simxStart('127.0.0.1',20001,true,true,5000,5); % crea una connessione con vrep
if (clientID>-1) % se la connessione è stata stabilita correttamente
    disp('Connected to remote Api server');
    
    %Handle
    [returnCode,e_Puck]=vrep.simxGetObjectHandle(clientID,'ePuck',vrep.simx_opmode_blocking);
    [returnCode,e_Puck1]=vrep.simxGetObjectHandle(clientID,'ePuck1',vrep.simx_opmode_blocking);
    [reurnCode,Plane_color]=vrep.simxGetObjectHandle(clientID,'Plane',vrep.simx_opmode_blocking);
   
    % Get signal (RgbPlane)
     [returnCode,PlaneColor]=vrep.simxGetStringSignal(clientID,'color',vrep.simx_opmode_streaming);
    
    %Position
    [returnCode,ePuck_position]=vrep.simxGetObjectPosition(clientID,e_Puck,-1,vrep.simx_opmode_streaming); 
    [returnCode,ePuck1_position]=vrep.simxGetObjectPosition(clientID,e_Puck1,-1,vrep.simx_opmode_streaming);
    
    %Color
    [returnCode]=vrep.simxSetStringSignal(clientID,'color',{1,0,0},vrep.simx_opmode_oneshot); % set red
   
    for i=1:inf
    [returnCode,ePuck_position]=vrep.simxGetObjectPosition(clientID,e_Puck,-1,vrep.simx_opmode_streaming); %-1 return the absolute position   
    [returnCode,ePuck1_position]=vrep.simxGetObjectPosition(clientID,e_Puck1,-1,vrep.simx_opmode_streaming);
    
    
    disp(ePuck_position);
    disp(ePuck1_position);
    
    pause(0.1);
    
    end
   vrep.simxFinish(-1);
end
The following is the non Threaded child script of the plane:

Code: Select all


if (sim_call_type==sim_childscriptcall_initialization) then
handleWall = simGetObjectHandle('Plane')

number result,tablergb=simGetShapeColor(handleWall,'Color',sim_colorcomponent_ambient_diffuse)
end

if (sim_call_type==sim_childscriptcall_actuation) then

simSetShapeColor(handleWall,nil,0,tablergb)

if (sim_call_type==sim_childscriptcall_sensing) then
end
Someone could help me to figure out why It doesn't change a color of the plane from Matlab?

Many thanks

Davide

DavideIng
Posts: 34
Joined: 21 Sep 2017, 17:27

Re: Change color of a primitive shape from remote Api (Matlab)

Post by DavideIng » 12 Oct 2017, 15:43

One of the main issue with these scripts is that the Array InitColor (Initial color of the shape on the scene) has not been got in matlab ( not defined in matlab). How can I fix it? Just define a matlab Array with the same name?

Many thanks

Davide

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

Re: Change color of a primitive shape from remote Api (Matlab)

Post by coppelia » 13 Oct 2017, 08:27

Hello,

use simxCallScriptFunction to change the color of an object. More details are here. Also, make sure to test the demo script programming/remoteApiBindings/matlab/matlab/complexCommandTest.m

Cheers

Post Reply