ZMQ API Issue

Typically: "How do I... ", "How can I... " questions
Post Reply
Adersh M
Posts: 23
Joined: 30 Nov 2022, 06:52

ZMQ API Issue

Post by Adersh M »

I am using ZMQ API via matlab to control a 6 wheeled, 4 steer rover. When I try to change the steering angles, coppeliasim only changes the first two in the order. I have verified the joint parameters, and have tried moving them independently. I also tried creating a custom function to pass all the joint angles together, but even then, the issue persist.

Code: Select all

% Simple Rover Motion Test using ZMQ Remote API
clearvars
clc

fprintf('Program started\n')
client = RemoteAPIClient();
sim = client.require('sim');

%% Setting Handles
% Wheel Motors
front_right_motor = sim.getObject('/RFW');
front_left_motor = sim.getObject('/LFW');
middle_right_motor = sim.getObject('/RMW');
middle_left_motor = sim.getObject('/LMW');
rear_right_motor = sim.getObject('/RRW');
rear_left_motor = sim.getObject('/LRW');

% Steering Motors
steer_front_right_motor = sim.getObject('/RFS');
steer_front_left_motor = sim.getObject('/LFS');
steer_rear_right_motor = sim.getObject('/RRS');
steer_rear_left_motor = sim.getObject('/LRS');

%% Motion Parameters
% % Set your desired values here
% turn_radius = 0; % in mm (use large values for straighter paths, + for right turn, - for left turn)
% linear_velocity = 0; % in m/s
% 
% % Calculate wheel velocities and steering angles
% [wheel_velocities, steer_angles] = velocitycalc(turn_radius, linear_velocity);

steer_angles = [0.5,0.5,0.5,0];
wheel_velocities = [0,0,0,0,0,0];

% Start simulation
sim.startSimulation();

while true

% Set initial steering angles
sim.setJointPosition(steer_rear_left_motor, steer_angles(4));
sim.setJointPosition(steer_rear_right_motor, steer_angles(2));
sim.setJointPosition(steer_front_left_motor, steer_angles(3));
sim.setJointPosition(steer_front_right_motor, steer_angles(1));


% Set wheel velocities
sim.setJointTargetVelocity(front_right_motor, wheel_velocities(1));
sim.setJointTargetVelocity(front_left_motor, -wheel_velocities(2));
sim.setJointTargetVelocity(middle_right_motor, wheel_velocities(3));
sim.setJointTargetVelocity(middle_left_motor, -wheel_velocities(4));
sim.setJointTargetVelocity(rear_right_motor, wheel_velocities(5));
sim.setJointTargetVelocity(rear_left_motor, -wheel_velocities(6));

% Stop all motors
sim.setJointTargetVelocity(front_right_motor, 0);
sim.setJointTargetVelocity(front_left_motor, 0);
sim.setJointTargetVelocity(middle_right_motor, 0);
sim.setJointTargetVelocity(middle_left_motor, 0);
sim.setJointTargetVelocity(rear_right_motor, 0);
sim.setJointTargetVelocity(rear_left_motor, 0);

end

% Stop simulation
sim.stopSimulation();
fprintf('Test completed\n');
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: ZMQ API Issue

Post by coppelia »

Hello,

what happens if you try to modify the steering angle of those joints that do not react from within CoppeliaSim? Do they react then?

Cheers
Adersh M
Posts: 23
Joined: 30 Nov 2022, 06:52

Re: ZMQ API Issue

Post by Adersh M »

No it doesnt. But it works with stepping mode. With this new code all joints are moving at once. % Simple Rover Motion Test using ZMQ Remote API

Code: Select all

clearvars
clc

fprintf('Program started\n')
client = RemoteAPIClient();
sim = client.require('sim');

%% Setting Handles
% Wheel Motors
front_right_motor = sim.getObject('/RFW');
front_left_motor = sim.getObject('/LFW');
middle_right_motor = sim.getObject('/RMW');
middle_left_motor = sim.getObject('/LMW');
rear_right_motor = sim.getObject('/RRW');
rear_left_motor = sim.getObject('/LRW');

% Steering Motors
steer_front_right_motor = sim.getObject('/RFS');
steer_front_left_motor = sim.getObject('/LFS');
steer_rear_right_motor = sim.getObject('/RRS');
steer_rear_left_motor = sim.getObject('/LRS');

%% Motion Parameters
% Test sequence of steering angles and velocities
steer_angles = [0.3;0.3;0.3;0.3];  % All steering joints same angle
wheel_velocities = [1;1;1;1;1;1]; % All wheels same speed

% Enable stepping for synchronous operation
sim.setStepping(true);
sim.startSimulation();

% Set steering angles first
sim.setJointPosition(steer_front_right_motor, steer_angles(1));
sim.setJointPosition(steer_front_left_motor, steer_angles(2));
sim.setJointPosition(steer_rear_right_motor, steer_angles(3));
sim.setJointPosition(steer_rear_left_motor, steer_angles(4));

% Let simulation settle steering angles
for i = 1:10
    sim.step();
end

% Now set wheel velocities
sim.setJointTargetVelocity(front_right_motor, wheel_velocities(1));
sim.setJointTargetVelocity(front_left_motor, -wheel_velocities(2)); % Note the negative for left side
sim.setJointTargetVelocity(middle_right_motor, wheel_velocities(3));
sim.setJointTargetVelocity(middle_left_motor, -wheel_velocities(4)); % Note the negative for left side
sim.setJointTargetVelocity(rear_right_motor, wheel_velocities(5));
sim.setJointTargetVelocity(rear_left_motor, -wheel_velocities(6)); % Note the negative for left side

% Let it run for some time
for i = 1:200
    sim.step();
end

% Stop all motors
sim.setJointTargetVelocity(front_right_motor, 0);
sim.setJointTargetVelocity(front_left_motor, 0);
sim.setJointTargetVelocity(middle_right_motor, 0);
sim.setJointTargetVelocity(middle_left_motor, 0);
sim.setJointTargetVelocity(rear_right_motor, 0);
sim.setJointTargetVelocity(rear_left_motor, 0);

% Stop simulation
sim.stopSimulation();
fprintf('Test completed\n');
Post Reply