57
57
% set_joint_target_velocities - Set the joint target velocities of a
58
58
% robot
59
59
% get_joint_velocities - Get the joint velocities of a robot
60
+ % get_joint_torques - Get the joint torques of a robot
61
+ % set_joint_torques - Set the joint torques of a robot
60
62
%
61
63
% DQ_VrepInterface Methods (For advanced users)
62
64
% get_handle - Get the handle of a V-REP object
96
98
% - Improved the documentation of the class
97
99
%
98
100
% 3. Frederico Fernandes Afonso Silva ([email protected] )
101
+ % - Added the following methods:
102
+ % - get_joint_torques() (see https://github.com/dqrobotics/matlab/pull/104)
103
+ % - set_joint_torques() (see https://github.com/dqrobotics/matlab/pull/104)
99
104
% - Altered the following properties from 'private' to 'protected'
100
105
% (see discussions in https://github.com/dqrobotics/matlab/pull/101
101
106
% to further details):
@@ -181,22 +186,19 @@ function connect(obj,ip,port)
181
186
error(' Failed to connect to remote API server' );
182
187
end
183
188
end
184
-
185
189
186
190
function disconnect(obj )
187
191
% This method ends the communication between the client and
188
192
% the CoppeliaSim scene. This should be the very last method called.
189
193
obj .vrep .simxFinish(obj .clientID );
190
194
end
191
195
192
-
193
196
function disconnect_all(obj )
194
197
% This method ends all running communication threads with the
195
198
% CoppeliaSim scene. This should be the very last method called.
196
199
obj .vrep .simxFinish(-1 );
197
200
end
198
201
199
-
200
202
function set_synchronous(obj ,flag )
201
203
% This method enables or disables the stepped (synchronous) mode
202
204
% for the remote API server service that the client is connected to.
@@ -209,33 +211,28 @@ function set_synchronous(obj,flag)
209
211
obj .vrep .simxSynchronous(obj .clientID ,flag );
210
212
end
211
213
212
-
213
214
function trigger_next_simulation_step(obj )
214
215
% This method sends a synchronization trigger signal to the CoppeliaSim scene,
215
216
% which performs a simulation step when the synchronous mode is used.
216
217
obj .vrep .simxSynchronousTrigger(obj .clientID );
217
218
end
218
219
219
-
220
220
function ping_time = wait_for_simulation_step_to_end(obj )
221
221
% This method returns the time needed for a command to be sent
222
222
% to the CoppeliaSim scene, executed, and sent back.
223
223
[~ , ping_time ] = obj .vrep .simxGetPingTime(obj .clientID );
224
224
end
225
225
226
-
227
226
function start_simulation(obj )
228
227
% This method starts the CoppeliaSim simulation.
229
228
obj .vrep .simxStartSimulation(obj .clientID ,obj .vrep .simx_opmode_oneshot );
230
229
end
231
230
232
-
233
231
function stop_simulation(obj )
234
232
% This method stops the CoppeliaSim simulation.
235
233
obj .vrep .simxStopSimulation(obj .clientID ,obj .vrep .simx_opmode_blocking );
236
234
end
237
235
238
-
239
236
function handles = get_handles(obj ,names )
240
237
% This method gets the handles for a cell array of
241
238
% object names in the the CoppeliaSim scene.
@@ -259,7 +256,6 @@ function stop_simulation(obj)
259
256
end
260
257
end
261
258
262
-
263
259
function handle = get_handle(obj ,name )
264
260
% This method gets the handle for a given object in the CoppeliaSim scene.
265
261
%
@@ -275,7 +271,6 @@ function stop_simulation(obj)
275
271
obj .vrep .simx_opmode_blocking );
276
272
end
277
273
278
-
279
274
function t = get_object_translation(obj ,objectname ,reference_frame ,opmode )
280
275
% This method gets the translation of an object in the CoppeliaSim scene.
281
276
%
@@ -353,7 +348,6 @@ function stop_simulation(obj)
353
348
t = DQ([0 ,double(object_position )]);
354
349
end
355
350
356
-
357
351
function set_object_translation(obj ,objectname ,translation ,reference_frame ,opmode )
358
352
% This method sets the translation of an object in the CoppeliaSim scene.
359
353
% Usage:
@@ -408,7 +402,6 @@ function set_object_translation(obj,objectname,translation,reference_frame,opmod
408
402
end
409
403
end
410
404
411
-
412
405
function r = get_object_rotation(obj , objectname , reference_frame , opmode )
413
406
% This method gets the rotation of an object in the CoppeliaSim scene.
414
407
%
@@ -493,7 +486,6 @@ function set_object_translation(obj,objectname,translation,reference_frame,opmod
493
486
object_rotation_double(3 )]));
494
487
end
495
488
496
-
497
489
function set_object_rotation(obj ,objectname ,rotation ,reference_frame ,opmode )
498
490
% This method sets the rotation of an object in the CoppeliaSim scene.
499
491
% Usage:
@@ -550,7 +542,6 @@ function set_object_rotation(obj,objectname,rotation,reference_frame,opmode)
550
542
end
551
543
end
552
544
553
-
554
545
function x = get_object_pose(obj ,objectname ,reference_frame ,opmode )
555
546
% This method gets the pose of an object in the CoppeliaSim scene.
556
547
%
@@ -606,7 +597,6 @@ function set_object_rotation(obj,objectname,rotation,reference_frame,opmode)
606
597
x = r + 0.5 * DQ .E * t * r ;
607
598
end
608
599
609
-
610
600
function set_object_pose(obj ,objectname ,pose ,reference_frame ,opmode )
611
601
% This method sets the pose of an object in the CoppeliaSim scene.
612
602
% Usage:
@@ -678,8 +668,7 @@ function set_object_pose(obj,objectname,pose,reference_frame,opmode)
678
668
obj .handle_from_string_or_handle(relative_to_handle ),...
679
669
opmode );
680
670
end
681
- end
682
-
671
+ end
683
672
684
673
function set_joint_positions(obj ,jointnames ,joint_positions ,opmode )
685
674
% This method sets the joint positions of a robot in the CoppeliaSim scene.
@@ -742,8 +731,7 @@ function set_joint_positions(obj,jointnames,joint_positions,opmode)
742
731
end
743
732
end
744
733
end
745
-
746
-
734
+
747
735
function set_joint_target_positions(obj ,jointnames ,joint_target_positions ,opmode )
748
736
% This method sets the joint target positions of a robot in the CoppeliaSim scene.
749
737
% It is required a dynamics enabled scene, and joints in dynamic mode
@@ -807,7 +795,6 @@ function set_joint_target_positions(obj,jointnames,joint_target_positions,opmode
807
795
end
808
796
end
809
797
810
-
811
798
function [joint_positions ,retval ]=get_joint_positions(obj ,jointnames ,opmode )
812
799
% This method gets the joint positions of a robot in the CoppeliaSim scene.
813
800
% Usage:
@@ -898,8 +885,7 @@ function set_joint_target_positions(obj,jointnames,joint_target_positions,opmode
898
885
joint_positions = thetas ;
899
886
end
900
887
901
-
902
- function joint_velocities = get_joint_velocities(obj ,jointnames ,opmode )
888
+ function joint_velocities = get_joint_velocities(obj ,jointnames ,opmode )
903
889
% This method gets the joint velocities of a robot in the CoppeliaSim scene.
904
890
% Usage:
905
891
% Recommended:
@@ -930,7 +916,7 @@ function set_joint_target_positions(obj,jointnames,joint_target_positions,opmode
930
916
%
931
917
% % Advanced usage:
932
918
% joint_velocities = get_joint_velocities(jointnames, OP_ONESHOT);
933
-
919
+
934
920
joint_velocities = zeros(length(jointnames ),1 );
935
921
for joint_index= 1 : length(jointnames )
936
922
% First approach to the auto-management using
@@ -1034,7 +1020,126 @@ function set_joint_target_velocities(obj,jointnames,joint_target_velocities,opmo
1034
1020
opmode );
1035
1021
end
1036
1022
end
1037
- end
1023
+ end
1024
+
1025
+ function joint_torques = get_joint_torques(obj ,jointnames ,opmode )
1026
+ % This method gets the joint torques of a robot in the CoppeliaSim scene.
1027
+ % Usage:
1028
+ % Recommended:
1029
+ % joint_torques = get_joint_torques(jointnames);
1030
+ %
1031
+ % Advanced:
1032
+ % joint_torques = get_joint_torques(jointnames, opmode)
1033
+ %
1034
+ % jointnames: The joint names.
1035
+ % (optional) opmode: The operation mode. If not
1036
+ % specified, the opmode will be set automatically.
1037
+ %
1038
+ % You can use the following modes:
1039
+ % OP_BLOCKING
1040
+ % OP_STREAMING
1041
+ % OP_ONESHOT
1042
+ % OP_BUFFER;
1043
+ %
1044
+ % Check this link for more details: https://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsMatlab.htm#simxGetJointForce
1045
+ %
1046
+ % Example:
1047
+ % jointnames={'LBR4p_joint1','LBR4p_joint2','LBR4p_joint3','LBR4p_joint4',...
1048
+ % 'LBR4p_joint5','LBR4p_joint6','LBR4p_joint7'};
1049
+ %
1050
+ % % Recommended:
1051
+ % joint_torques = get_joint_torques(jointnames);
1052
+ %
1053
+ % % Advanced usage:
1054
+ % joint_torques = get_joint_torques(jointnames, OP_STREAMING);
1055
+
1056
+ joint_torques = zeros(length(jointnames ),1 );
1057
+
1058
+ % If the user does not specify the opmode, it is chosen first
1059
+ % as STREAMING and then as BUFFER, as specified by the remote
1060
+ % API documentation.
1061
+ for joint_index= 1 : length(jointnames )
1062
+ % First approach to the auto-management using
1063
+ % DQ_VrepInterfaceMapElements. If the user does not specify the
1064
+ % opmode, it is chosen first as STREAMING and then as BUFFER,
1065
+ % as specified by the remote API documentation
1066
+ if nargin <= 2
1067
+ if isa(jointnames ,' cell' )
1068
+ element = obj .element_from_string(jointnames{joint_index });
1069
+ else
1070
+ element = obj .element_from_string(jointnames );
1071
+ end
1072
+ if (~element .state_from_function_signature(' get_joint_torques' ))
1073
+ [~ ,tmp ] = obj .vrep .simxGetJointForce(obj .clientID , element .handle , obj .OP_STREAMING );
1074
+ return_code = 1 ;
1075
+ while (return_code == 1 )
1076
+ [return_code ,tmp ] = obj .vrep .simxGetJointForce(obj .clientID , element .handle , obj .OP_BUFFER );
1077
+ end
1078
+ else
1079
+ [~ ,tmp ] = obj .vrep .simxGetJointForce(obj .clientID , element .handle , obj .OP_BUFFER );
1080
+ end
1081
+ else
1082
+ [~ ,tmp ] = obj .vrep .simxGetJointForce(obj .clientID , ...
1083
+ obj .handle_from_string_or_handle(jointnames{joint_index }), opmode );
1084
+ end
1085
+ joint_torques(joint_index ) = double(-tmp ); % V-REP returns joint torques with an inverse sign
1086
+ end
1087
+ end
1088
+
1089
+ function set_joint_torques(obj ,jointnames ,torques ,opmode )
1090
+ % This method sets the joint torques of a robot in the CoppeliaSim scene.
1091
+ % Usage:
1092
+ % Recommended:
1093
+ % set_joint_torques(jointnames, torques);
1094
+ %
1095
+ % Advanced:
1096
+ % set_joint_torques(jointnames, torques, opmode);
1097
+ %
1098
+ % jointnames: The joint names.
1099
+ % torques: The joint torques.
1100
+ % (optional) opmode: The operation mode. If not
1101
+ % specified, the opmode will be set automatically.
1102
+ %
1103
+ % You can use the following modes:
1104
+ % OP_BLOCKING
1105
+ % OP_STREAMING
1106
+ % OP_ONESHOT
1107
+ % OP_BUFFER;
1108
+ %
1109
+ % Check this link for more details: https://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsMatlab.htm#simxSetJointTargetVelocity
1110
+ %
1111
+ % Example:
1112
+ % jointnames={'LBR4p_joint1','LBR4p_joint2','LBR4p_joint3','LBR4p_joint4',...
1113
+ % 'LBR4p_joint5','LBR4p_joint6','LBR4p_joint7'};
1114
+ % u = [0.1 0.1 0.1 0.1 0.1 0.1 0.1];
1115
+ %
1116
+ % % Recommended:
1117
+ % set_joint_torques(jointnames, u);
1118
+ %
1119
+ % % Advanced usage:
1120
+ % set_joint_torques(jointnames, u, opmode);
1121
+
1122
+ % If the user does not specify the opmode, it is chosen first
1123
+ % as STREAMING and then as OP_ONESHOT, as specified by the
1124
+ % remote API documentation.
1125
+ if nargin == 3
1126
+ % The recommended mode is OP_ONESHOT
1127
+ for joint_index= 1 : length(jointnames )
1128
+ obj .vrep .simxSetJointTargetVelocity(obj .clientID , obj .handle_from_string_or_handle(jointnames{joint_index }), ...
1129
+ sign(torques(joint_index ))*10e10, obj .OP_ONESHOT );
1130
+ obj .vrep .simxSetJointForce(obj .clientID , obj .handle_from_string_or_handle(jointnames{joint_index }), ...
1131
+ abs(torques(joint_index )), obj .OP_ONESHOT );
1132
+ end
1133
+ else
1134
+ for joint_index= 1 : length(jointnames )
1135
+ obj .vrep .simxSetJointTargetVelocity(obj .clientID , obj .handle_from_string_or_handle(jointnames{joint_index }),...
1136
+ sign(torques(joint_index ))*10e10, opmode );
1137
+ obj .vrep .simxSetJointForce(obj .clientID ,obj .handle_from_string_or_handle(jointnames{joint_index }),abs(torques(joint_index )),...
1138
+ opmode );
1139
+ end
1140
+ end
1141
+ end
1142
+
1038
1143
end
1039
1144
1040
1145
end
0 commit comments