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');