Hi @Cuong Huynh Nguyen
You mentioned, “3 Sine blocks and a constant block connected to the robots (I have made the robots connection and blocks a subsystem). From the robot subsystem, it's connected to a mux that takes 4 inputs. The mux is connected to the GetTransform block. The GetTransform block is connected to a Coordinate Transformation Conversion block which is then connected to a scope. All of my setup seems fine. However, I am getting an error that says the input is a vector of 4 whereas the outputs requires 11. I know this is due to the joints block where I have set up 4 of them to sense the postion and computed the torque automatically and I have 11 joints in total. When I add an additional Simulink to PS and PS to simulink to another joint, I get an error like this: "The input is a vector of 5 whereas the outputs requires 11". As mentioned, only 4 of the joints are actuating joints and joints that I need to find the forward kinematic for. How can I fix this issue without adding more joints to sense the position?”
Please see my response by addressing your first query.
The error message indicates that the GetTransform block expects an input vector of size 11, which corresponds to the total number of joints in your robot model. However, your current setup only provides a vector of size 4, which is likely derived from the four actuating joints. Since you have 11 joints in total, it is essential to make sure that the input to the GetTransform block includes all necessary joint states. The four actuating joints are not sufficient to represent the entire robot's configuration. The remaining joints must be accounted for, even if they are not actively controlled. So, to resolve the mismatch, you can modify the Mux input to include additional elements that represent the remaining joints. Here are a few strategies:
Option A: Zero Padding
If the non-actuating joints do not contribute to the transformation, you can pad the input vector with zeros. This way, you maintain the required size of 11 without adding additional sensing or control mechanisms.
% Assuming 'actuatingJoints' is a vector of size 4 actuatingJoints = [joint1_position; joint2_position; joint3_position; joint4_position]; % Create a zero vector for the remaining joints remainingJoints = zeros(7, 1); % 11 total - 4 actuating = 7 non-actuating % Combine both vectors inputVector = [actuatingJoints; remainingJoints]; % This will be of size 11
Option B: State Estimation
If the non-actuating joints have states that can be estimated or are known, you can create a mechanism to compute or retrieve their positions. This could involve using a Constant block or a MATLAB Function block to output the known positions of these joints.
function output = getJointStates() % Example of known positions for non-actuating joints joint5_position = 0.5; % Example value joint6_position = 0.3; % Example value % Add more as needed output = [joint5_position; joint6_position; ...]; % Continue for all non- actuating joints end
Once you have constructed the input vector of size 11, connect it to the GetTransform block. For more information on this block, please refer to
https://www.mathworks.com/help/robotics/ref/transformtree.gettransform.html?s_tid=doc_ta
Make sure that the Mux block is configured to accept the new input vector correctly. After making these adjustments, run your Simulink model again. Monitor the output in the Scope to ensure that the transformations are computed correctly and that the error regarding vector size is resolved. This will make sure that the input vector to the GetTransform block matches the expected size of 11, you can effectively resolve the error you are encountering. Whether through zero padding or state estimation, it is crucial to account for all joints in your robot model. This approach not only fixes the immediate issue but also enhances the robustness of your simulation by ensuring that all joint states are appropriately represented.
To address your second query regarding, “My second question is rather simple. I am using 3R1P configuration. I know I can get a constant block connected to a degrees to radians block to control the revolute arm of the robot. What is a similar setup I can use to move the prismatic joints?”
To control a prismatic joint in MATLAB, you can use a combination of blocks in Simulink or write a script in MATLAB. Since you are using Simulink, I will focus on it by providing step by step instructions. In Simulink, create a model that includes the following components:
Position Target: Use the State Targets parameters in the Prismatic Joint block to specify the desired position of the prismatic joint. The position can be controlled using a constant input or a time-varying signal, much like you would for angular positions in revolute joints.
Actuation Input: You can provide the actuation force through the input port f for controlling the joint. If you want to specify the position and velocity directly, enable the corresponding input ports in the block parameters.
By utilizing constant values, gain adjustments, and saturation limits, you can make sure that the prismatic joint operates within its physical constraints.
I would also recommend example documentation “Control PR2 Arm Movements Using ROS Actions and Inverse Kinematics” by clicking the link below
https://www.mathworks.com/help/robotics/ug/control-pr2-arm-movements-using-actions-and-ik.html
Here is an example code snippet for ROS if you feel like experimenting with it.
The code snippet below is a basic example to illustrate sending commands to a prismatic joint:
% Create action client for the prismatic joint prismaticActionClient = rosactionclient('/prismatic_joint_controller/. joint_trajectory_action'); waitForServer(prismaticActionClient);
% Set up the goal message goalMessage = rosmessage('trajectory_msgs/JointTrajectoryGoal'); goalMessage.Trajectory.JointNames = {'prismatic_joint_name'}; % Specify your joint name here
% Define trajectory points point1 = rosmessage('trajectory_msgs/JointTrajectoryPoint'); point1.Positions = [0]; % Initial position point1.Velocities = [0]; % Initial velocity point1.TimeFromStart = rosduration(1.0); % Time from start
point2 = rosmessage('trajectory_msgs/JointTrajectoryPoint'); point2.Positions = [1]; % Desired position point2.Velocities = [0]; % Desired velocity point2.TimeFromStart = rosduration(2.0); % Time from start
% Assign points to goal message goalMessage.Trajectory.Points = [point1, point2];
% Send goal to prismatic joint sendGoalAndWait(prismaticActionClient, goalMessage);
Additional Suggestions
Calibration:
Make that the prismatic joints are calibrated correctly within your simulation environment to avoid unexpected behavior during motion execution.
Limits and Constraints:
Always define the limits for the prismatic joints to prevent any out-of-bound movements, which could lead to simulation errors or physical damages in real robots.
Testing and Validation:
Before deploying commands to the physical robot, run simulations to validate the behavior of the prismatic joints in various scenarios, ensuring smooth transitions and adherence to trajectory commands.
Hope following these suggestions helps resolve your problem. Please let me know if you have any further questions.