Modify simulation time step while simulation is paused (remote api matlab)

Typically: "How do I... ", "How can I... " questions
R2D2
Posts: 6
Joined: 08 Jul 2017, 16:22

Modify simulation time step while simulation is paused (remote api matlab)

Postby R2D2 » 12 Jul 2017, 17:17

I am trying to carry out a simulation in v-rep 3. Specifically, there are 3 Manta vehicles. I have a matrix in Matlab which specifies their velocities and steering angles for each time instant t. The difference between two successive time instants (t(i)-t(i-1)) is not always the same. My approach is to pause the simulation at time instant t(i-1). Then set the desired velocities and steering angles of the vehicles, set the simulation time step equal to t(i)-t(i-1) and start the simulation. Pause the simulation at time instant t(i) and do the same... However it seems that the simulation time step does not change. Can someone help me please? This is my first project in v-rep, so i am not sure if this implementation is even legitimate. Thus, if you have any other ideas to implement this simulation, they would be really welcomed and appreciated. The code is given below:

Code: Select all

disp('Program started');
    clc
    close all
    clear all
    load('data.mat');
    vrep=remApi('remoteApi'); % using the prototype file (remoteApiProto.m)
    vrep.simxFinish(-1); % just in case, close all opened connections
    clientID=vrep.simxStart('127.0.0.1',19999,true,true,5000,5);
    vrep.simxPauseSimulation(clientID, vrep.simx_opmode_oneshot);
    if (clientID>-1)
       
        disp('Connected to remote API server');

        [returnCode,steer_handle(1)]=vrep.simxGetObjectHandle(clientID,'steer_joint', vrep.simx_opmode_blocking);
        [returnCode,motor_handle(1)]=vrep.simxGetObjectHandle(clientID,'motor_joint', vrep.simx_opmode_blocking);
        [returnCode,steer_handle(2)]=vrep.simxGetObjectHandle(clientID,'steer_joint#0', vrep.simx_opmode_blocking);
        [returnCode,motor_handle(2)]=vrep.simxGetObjectHandle(clientID,'motor_joint#0', vrep.simx_opmode_blocking);
        [returnCode,steer_handle(3)]=vrep.simxGetObjectHandle(clientID,'steer_joint#1', vrep.simx_opmode_blocking);
        [returnCode,motor_handle(3)]=vrep.simxGetObjectHandle(clientID,'motor_joint#1', vrep.simx_opmode_blocking);
       
        %set initial velocities and steering angles to zero
        [returnCode]=vrep.simxSetJointTargetVelocity(clientID, motor_handle(1), 0, vrep.simx_opmode_streaming);
        [returnCode]=vrep.simxSetJointPosition(clientID,steer_handle(1), 0, vrep.simx_opmode_streaming);
        [returnCode]=vrep.simxSetJointTargetVelocity(clientID, motor_handle(2), 0, vrep.simx_opmode_streaming);
        [returnCode]=vrep.simxSetJointPosition(clientID,steer_handle(2), 0, vrep.simx_opmode_streaming);
        [returnCode]=vrep.simxSetJointTargetVelocity(clientID, motor_handle(3), 0, vrep.simx_opmode_streaming);
        [returnCode]=vrep.simxSetJointPosition(clientID,steer_handle(3), 0, vrep.simx_opmode_streaming);
        vrep.simxStartSimulation(clientID,vrep.simx_opmode_blocking);
        for i=1:size(t)
       
            vrep.simxPauseSimulation(clientID, vrep.simx_opmode_oneshot);
      %set desired velocities and steering angles
            [returnCode]=vrep.simxSetJointTargetVelocity(clientID, motor_handle(1), ul(i,1), vrep.simx_opmode_streaming);
            [returnCode]=vrep.simxSetJointPosition(clientID,steer_handle(1), g(i,1), vrep.simx_opmode_streaming);
            [returnCode]=vrep.simxSetJointTargetVelocity(clientID, motor_handle(2), ul(i,2), vrep.simx_opmode_streaming);
            [returnCode]=vrep.simxSetJointPosition(clientID,steer_handle(2), g(i,2), vrep.simx_opmode_streaming);
            [returnCode]=vrep.simxSetJointTargetVelocity(clientID, motor_handle(3), u(i,3), vrep.simx_opmode_streaming);
            [returnCode]=vrep.simxSetJointPosition(clientID,steer_handle(3), g(i,3), vrep.simx_opmode_streaming);
            if (i==1)
                %pause(t(i));
                vrep.simxSetFloatingParameter(clientID, vrep.sim_floatparam_simulation_time_step, t(i), vrep.simx_opmode_oneshot_wait)
            else
                %pause(t(i)-t(i-1));
                vrep.simxSetFloatingParameter(clientID,vrep.sim_floatparam_simulation_time_step, t(i)-t(i-1), vrep.simx_opmode_oneshot_wait)
            end
           
            vrep.simxStartSimulation(clientID,vrep.simx_opmode_blocking);
        end       
        vrep.simxFinish(-1);
    end
    vrep.delete();
    disp('Program Ended');

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

Re: Modify simulation time step while simulation is paused (remote api matlab)

Postby coppelia » 13 Jul 2017, 12:56

Hello,

you cannot modify the simulation time step programmatically during simulation. Only when simulation is stopped can you do it.
But, are you using the V-REP remote API synchronous operation? If you do that, you are in perfect control from your Matlab client when the next simulation step should run.

Cheers

R2D2
Posts: 6
Joined: 08 Jul 2017, 16:22

Re: Modify simulation time step while simulation is paused (remote api matlab)

Postby R2D2 » 14 Jul 2017, 18:55

But it's not about when I want to run my next simulation step. It's about how long do i want it to last. I pre-select 50.0ms (Custom), in order to be able to change it (i read that on another post), but it does not change. If i toggle synchronous mode on, will I be able to change the duration of the time step while the simulation is paused and not stopped?

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

Re: Modify simulation time step while simulation is paused (remote api matlab)

Postby coppelia » 16 Jul 2017, 20:08

Basically you can't do anything else that what you can do via the GUI: when simulation is stopped, you can change the simulation time step. But when simulation is running (or paused), the simulation time step is greyed out in the toolbar button. Via the API you cannot change it either, while simulation is not stopped. But while simulation is running, you can always use the turtle and rabit toolbar buttons to kind of increase speed or reduce speed (read more here). Via API you can also do this by using sim_intparam_speedmodifier and simSetInt32Parameter.

Cheers


Return to “General questions”

Who is online

Users browsing this forum: Bing [Bot] and 18 guests