Error in port widths or dimensions

19 views (last 30 days)
oualid doukhi
oualid doukhi on 23 Jan 2018
Answered: Andrew Tayler on 1 Nov 2021
I am using Robotics System toolbox to publish direct motor commands (Angular velocities=[v1,v2,v3,v4]) for a quadrotor (rotors simulator) as following
I got the following error
Error in port widths or dimensions. Output port 1 of 'pelican/Command Velocity Publisher/Mux' is a one-dimensional vector with 4 elements. Component: Simulink | Category: Model error Error in port widths or dimensions. Input port 2 of 'pelican/Command Velocity Publisher/Bus Assignment1' is a one-dimensional vector with 128 elements.
when I publish through the terminal using rospub it works fine
rostopic pub /pelican/command/motor_speed mav_msgs/Actuators '{angular_velocities: [100, 100, 100, 100]}'
I tried to manage the array sizes for ROS msgs in Simulink from 128 to 4 :
in this case, Simulink running without error, but I got a new error and gazebo simulator shutdown,
Thanks in advance
  2 Comments
krishneel kumar
krishneel kumar on 13 Feb 2018
Hey I had the same issues as you did. Have you managed to solve the latter? I have been stuck at this for a while now.
Thanks in advance
Mahdi Nobar
Mahdi Nobar on 21 Mar 2019
Hi, could you manage to solve the error? Is there any way to send the AngularVelocity from topic type mav_msgs/Actuators directly from Simulink to Gazebo?

Sign in to comment.

Answers (5)

Tohru Kikawada
Tohru Kikawada on 21 Feb 2018
If you want to assign the data to the variable-length array, you will need to follow the "Task 1 - Access Data in a Variable-length Array" section in this link.
Hope this helps.
  1 Comment
Mahdi Nobar
Mahdi Nobar on 21 Mar 2019
Edited: Mahdi Nobar on 21 Mar 2019
Hi, I looked at the link but it could not solve the error. According to the claim of this website Interfacing RotorS through Matlab, the error is because of the fact that MathWorks Robotics System Toolbox only supports the forwarding of custom messages only via Matlab scripts, and the Simulink schemes have to be adapted and integrated with Matlab scripts for exchanging data and commands with ROS and Gazebo. So, I was wondering this claim would be correct? Isn't there any way to send the AngularVelocity from topic type mav_msgs/Actuators directly from Simulink to Gazebo?

Sign in to comment.


Calogero Forte
Calogero Forte on 4 Oct 2018
Ehi, How did you work with "mav_msgs/xxx" message type? In my enviroment, this type of message does not exist and Matlab does't create the custome messages with rosgenmsg function.
  2 Comments
Mahdi Nobar
Mahdi Nobar on 5 Jun 2019
You need to inistall Robotics System toolbox and ROS custom message for MATLAB. Follow the instructions on links below:
Ami
Ami on 6 Oct 2020
Hi. If you don't mind, can you please share how you used rosgenmsg and were you using windows? I'm having a bit of trouble with that function.

Sign in to comment.


Li Jack
Li Jack on 5 Jun 2019
Hello, have you solved this problem? I was stuck in this problem too, also using ros message.

Aaron Angert
Aaron Angert on 24 Jan 2020
All variables in the ROS bus start off empty, so just make a matlab function that loops through and assigns each vector element to the ones coming in, i.e.:
function y = fcn(Bus, Ct, Points, Current_len, ReceivedLen)
Bus.Ct = Ct;
disp(size(Points,1))
for c = 1:size(Points,1)
Bus.Points(c) = Points(c);
end
Bus.Points_SL_Info.CurrentLength = Current_len;
Bus.Points_SL_Info.ReceivedLength = ReceivedLen;
y = Bus;
  2 Comments
Ami
Ami on 23 Oct 2020
Hello. Where do I get the Ct, Points, Current_len, ReceivedLen so that I can supply the function with those values? Can you please show a screenshot of how you implemented this method in Simulink?
Aaron Angert
Aaron Angert on 26 Oct 2020
Hi, Ct is specific for the bus in this example you can leave that out. Points is the array of data values, Current_len and recieved_len are also specific to the bus, and are the amount of points in the array. you can use a matlab function in simulink to implement the above code.

Sign in to comment.


Andrew Tayler
Andrew Tayler on 1 Nov 2021
I encountered this same issue and managed to solve it by changing the dimensions of the mav_msgs_Actuators bus in the Model Explorer to 4 and then updating the bus with a matlab function like Aaron suggested. See below:
Hope this helps.
function msg = fcn(Bus,angVel) % Input modified mav_msgs_Actuators bus and motor speeds
Bus.AngularVelocities = angVel'; % [motor1, motor2, motor3, motor4]'
Bus.AngularVelocities_SL_Info.CurrentLength = uint32(4); % Update the length of the velocities vector
msg = Bus;

Categories

Find more on Publishers and Subscribers in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!