-
Notifications
You must be signed in to change notification settings - Fork 13
/
robotTest.m
54 lines (45 loc) · 2.3 KB
/
robotTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function robotTest()
pause on;
disp('Program started');
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);
if clientID == -1
disp('Failed connecting to remote API server');
end
[retVal,leftMotor] = vrep.simxGetObjectHandle(clientID,'remoteApiControlledBubbleRobLeftMotor',vrep.simx_opmode_oneshot_wait);
check(vrep,retVal, 'failed to get left motor', 'got left motor');
[retVal,rightMotor] = vrep.simxGetObjectHandle(clientID,'remoteApiControlledBubbleRobRightMotor',vrep.simx_opmode_oneshot_wait);
check(vrep,retVal, 'failed to get right motor', 'got right motor');
[retVal,noseSensor] = vrep.simxGetObjectHandle(clientID,'remoteApiControlledBubbleRobSensingNose',vrep.simx_opmode_oneshot_wait);
check(vrep,retVal, 'failed to get nose sensor', 'got nose sensor');
[retVal, vel] = vrep.simxGetObjectFloatParameter(clientID, leftMotor, 2012, vrep.simx_opmode_oneshot_wait);
vel
[retVal]=vrep.simxSetJointTargetVelocity(clientID,leftMotor,3*pi,vrep.simx_opmode_oneshot_wait);
check(vrep,retVal, 'velocity left failed', 'velocity left set');
[retVal]=vrep.simxSetJointTargetVelocity(clientID,rightMotor,pi,vrep.simx_opmode_oneshot_wait);
check(vrep,retVal, 'velocity right failed', 'velocity right set');
vrep.simxAddStatusbarMessage(clientID, 'this is a test', vrep.simx_opmode_oneshot_wait);
[retVal, vel] = vrep.simxGetObjectFloatParameter(clientID, leftMotor, 2012, vrep.simx_opmode_oneshot_wait);
vrep.simxAddStatusbarMessage(clientID, 'this is a test', vrep.simx_opmode_oneshot_wait);
try
while (vrep.simxGetConnectionId(clientID)>-1)
pause(.001)
%[retVal, nose] = vrep.simReadProximitySensor(noseSensor);
%nose
end
disp('exiting');
vrep.delete(); % call the destructor!
catch err
vrep.simxFinish(clientID); % close the line if still open
vrep.delete(); % call the destructor!
end;
disp('Program ended');
end
function check(vrep, retVal, textError, textNoError)
if (retVal==vrep.simx_error_noerror)
disp(textNoError);
else
disp(textError);
end
end