-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Matlab and Python remote control code
- Loading branch information
Showing
36 changed files
with
6,878 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
57 changes: 57 additions & 0 deletions
57
6_Demo_MatlabAndPythonControl/matlab/VREP_RemoteAPIs/complexCommandTest.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
% This example illustrates how to execute complex commands from | ||
% a remote API client. You can also use a similar construct for | ||
% commands that are not directly supported by the remote API. | ||
% | ||
% Load the demo scene 'remoteApiCommandServerExample.ttt' in CoppeliaSim, then | ||
% start the simulation and run this program. | ||
% | ||
% IMPORTANT: for each successful call to simxStart, there | ||
% should be a corresponding call to simxFinish at the end! | ||
|
||
function complexCommandTest() | ||
|
||
disp('Program started'); | ||
% sim=remApi('remoteApi','extApi.h'); % using the header (requires a compiler) | ||
sim=remApi('remoteApi'); % using the prototype file (remoteApiProto.m) | ||
sim.simxFinish(-1); % just in case, close all opened connections | ||
clientID=sim.simxStart('127.0.0.1',19999,true,true,5000,5); | ||
|
||
if (clientID>-1) | ||
disp('Connected to remote API server'); | ||
|
||
% 1. First send a command to display a specific message in a dialog box: | ||
[res retInts retFloats retStrings retBuffer]=sim.simxCallScriptFunction(clientID,'remoteApiCommandServer',sim.sim_scripttype_childscript,'displayText_function',[],[],'Hello world!',[],sim.simx_opmode_blocking); | ||
if (res==sim.simx_return_ok) | ||
fprintf('Returned message: %s\n',retStrings); | ||
else | ||
fprintf('Remote function call failed\n'); | ||
end | ||
|
||
% 2. Now create a dummy object at coordinate 0.1,0.2,0.3 with name 'MyDummyName': | ||
[res retInts retFloats retStrings retBuffer]=sim.simxCallScriptFunction(clientID,'remoteApiCommandServer',sim.sim_scripttype_childscript,'createDummy_function',[],[0.1 0.2 0.3],'MyDummyName',[],sim.simx_opmode_blocking); | ||
if (res==sim.simx_return_ok) | ||
fprintf('Dummy handle: %d\n',retInts(1)); | ||
else | ||
fprintf('Remote function call failed\n'); | ||
end | ||
|
||
% 3. Now send a code string to execute some random functions: | ||
code=['local octreeHandle=simCreateOctree(0.5,0,1)', char(10), ... | ||
'simInsertVoxelsIntoOctree(octreeHandle,0,{0.1,0.1,0.1},{255,0,255})', char(10), ... | ||
'return ''done''']; | ||
[res retInts retFloats retStrings retBuffer]=sim.simxCallScriptFunction(clientID,'remoteApiCommandServer',sim.sim_scripttype_childscript,'executeCode_function',[],[],code,[],sim.simx_opmode_blocking); | ||
if (res==sim.simx_return_ok) | ||
fprintf('Code execution returned: %s\n',retStrings); | ||
else | ||
fprintf('Remote function call failed\n'); | ||
end | ||
|
||
% Now close the connection to CoppeliaSim: | ||
sim.simxFinish(clientID); | ||
else | ||
disp('Failed connecting to remote API server'); | ||
end | ||
sim.delete(); % call the destructor! | ||
|
||
disp('Program ended'); | ||
end |
18 changes: 18 additions & 0 deletions
18
6_Demo_MatlabAndPythonControl/matlab/VREP_RemoteAPIs/readMe.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Make sure you have following files in your directory, in order to run the various examples: | ||
|
||
1. remApi.m | ||
2. remoteApiProto.m | ||
3. the appropriate remote API library: "remoteApi.dll" (Windows), "remoteApi.dylib" (Mac) or "remoteApi.so" (Linux) | ||
4. simpleTest.m (or any other example program) | ||
|
||
------------------------------------------------------------------- | ||
|
||
If you choose not to use the prototype file ("remoteApiProto.m"), then you will have to make sure you have a compiler | ||
set-up for Matlab (mex -setup). You will also need "extApi.h" in this folder, and you will have to instanciate the | ||
remote API with "sim=remApi('remoteApi','extApi.h');" instead of "sim=remApi('remoteApi');" | ||
|
||
Finally, if you wish to rebuild the prototype file, you will have to comply with above conditions, then type: | ||
|
||
loadlibrary('remoteApi','extApi.h','mfilename','remoteApiProto') | ||
|
||
For more examples, have a look at the python folder: language is different but principles are the same |
Oops, something went wrong.