Open HusseinHazem opened 6 years ago
I suggest you to read something about the MathWorks Robotics System Toolbox
![screenshot from 2018-05-02 15 58 33](https://user-images.githubusercontent.com/36478570/39527571-0b638eb2-4e22-11e8-88fd-4ec5c4b672b5.png that was my attempt. but i also followed https://it.mathworks.com/help/robotics/examples/work-with-ros-messages-in-simulink.html but i couldn't get it to work.
I suggest you to read these tutorials: Connect to a ROS-enabled Robot from Simulink, Install robotics system toolbox support packages and Create custom messagges from ROS package.
You have to take in mind that _mavmsgs/Actuators is not a standard ROS message. It is not present in the default MATLAB installation (with the Robotics System Toolbox) and you have to import it by using the tutorials I linked you.
thanks but i already went through all of these and installed ROS custom message interface. and as you can see from the screenshot the message type mav_msgs/Actuators in available for use. My problem is how to publish the message to the motor speeds.
You right!! It is not allowed to publish a message via Simulink, at least I did not succeed. You should use MATLAB, in particular the commands as reported below:
[pub, msg] = rospublisher('/command/motor_speed','mav_msgs/Actuators'); msg.AngularVelocities = [Omega_1_SIMULINK.signals.values(end), Omega_2_SIMULINK.signals.values(end), Omega_3_SIMULINK.signals.values(end), Omega_4_SIMULINK.signals.values(end)]; send(pub,msg);
where Omega_1, Omega_2, and so on, are the propellers angular velocities you would publish.
I hope I have made it clear.
Thanks a lot , i changed it a bit to the above and it worked. My goal is to use my controller from simulink to control the motor velocities, any idea how i could do that?
Great!! You have to combine SIMULINK with MATLAB. The MATLAB script handles the communication, receiving data from ROS and passing such data to Simulink. The control scheme in Simulink computes the control actions and saves such actions in a toWorkspace block. Later MATLAB, thanks to the command I showed (and you corrected a little bit), sends the motor command to GAZEBO.
To do that you have to synchronize the enviroment by using the GAZEBO services pause and unpase physics.
Do you know how i can remove this error? the u here is a vector of length 4 coming from a mux and for some reason the function can't recognize the ros function.
You cannot use this kind of Matlab function in Simulink. I mean, you cannot publish a ROS message via Simulink by using it. In attached two files: a MATLAB script that handles the communication between MATLAB and GAZEBO, and a Simulink that allows you to implement your control law. I mean, the Simulink scheme is able to use the Gazebo data (MATLAB makes them available) and to compute the propellers angular velocities. Such velocities every simulation step (Ts seconds) are sent to MATLAB (a simple toWorkspace block) that has the aim to publish them. Furthermore, the MATLAB script makes the two environments synchronized: when MATLAB is running, Gazebo is in pause and vice-versa.
I don't know if I got it across. I hope so.
The 2018a version of MATLAB you need to run these files
thanks i will try it out and get back to you, but will 2017a version not work?
I made the Simulink scheme by using 2018a version of MATLAB. I don't know if you can open it with a previous version of the software. You should try.
it is possible but you have to change the file from a simulink 2018a as shown in the pic
Can you export to version 2017a and send it again?
Yes, of course. You find it in attach.
Thanks a lot, but i am having a bit of trouble understanding how i am supposed to run it using my control method from simulink. Am i supposed to send my omegas generated from my control to the omega blocks instead of the constants and run the simulink model first then the matlab script?
As I told you before, the MATLAB script has the aim of handling the communication. It is enough to run the MATLAB script to execute the entire simulation. Thus, you have to think in your mind an event triggered system. Such system brings data from the environment, computes the next action to do (the propeller angular velocities) and acts it in order to reach the goal. Every step, each Ts seconds (1e-3 in my example) the cycle is run. How many time? The number of the simulation steps.
In other words, the code works like an automata. In each state, some actions are done and later the results used by the next node, and so on.
so that being said, i won't be able to use my MPC (model predictive control) i did on simulink where i publish the speed of the motors depending on the feedback i get from gazebo (i.e position of the hummingbird)
i hadn't noticed that you run the simulink simulation in the matlab script, so it should work?
Yes, you are able to do that..but you have to redesign the controller. I mean, the idea behind. I already used the Robotics System Toolbox in my research activity. In particular, I employed such toolbox to develop an extension of the RotorS platform named CrazyS.
In this video is showed as the Robotics System Toolbox (on a Windows machine) is able to send commands (the propellers angular velocities) to and receive data from the Gazebo 3D virtual environment (on a Ubuntu 14.04 machine).
So if this is my controller with the system, i should just change the feedback to be of x y z roll pitch and yaw to be from the workspace of matlab which come from gazebo?
First of all, when you are using the Robotics System Toolbox with Gazebo you have to take in mind that your model is in Gazebo, and not in MATLAB. Later, the feedback loop data come from Gazebo. Thus, you have to read the odometry messages from the environment, to compute from the propellers angular velocities for a single step, and finally to send them by using the properly MATLAB function.
Yes i know, i will totally neglect the system in matlab
should that work?
Yes, it should work.
The "from workspace " blocks give me that error
You have to save the variables in the Workspace as 2D Array. See my Simulink scheme.
It worked, flies for like 3 seconds then it disappears into the ground hahahahahah but i think it is an error from my control.
Maybe, could be. I am glad to listen that all is ok now. Thus, I think you can close the issue now.
Say something more in the title. Such discussion could help others that are interested to use the toolbox but don't know how to do.
i don't think it is the control though, are there any parameters that i can change which would effect the simulation somehow?
The simulation steps, maybe. It has to be equal to the simulation step that you used in the simulation scheme. Search on google how to modify a world in GAZEBO, the real time factor.
okay i will, but i think something is wrong with the controllers output because i tried your simulink scheme and it worked, or at least didn't flip over. Thanks a lot for your help, and i'll try to get it to work and get back to you.
Hey @HusseinHazem and @gsilano I think it would be awesome if you could add a Wiki page for this.
I started one here: https://github.com/ethz-asl/rotors_simulator/wiki/Interfacing-RotorS-through-Matlab
Feel free to edit also the sample titles.
@ffurrer, why not. It is the minimum for the help you gave me some months ago: the issues I had with the build when I opened the pull request #465.
Could I insert such guide in CrazyS? If you remember, it is an extension of the RotorS capabilities in which I modeled, developed and integrated the Crazyflie 2.0 nano-quadcopter.
This is up to you of course, but I guess it would make a bit more sense if it would be in this repo. As this is unspecific to CrazyS.
Yes, of course. I will write it for RotorS sharing such contents also in CrazyS. In this way, the same procedure may be used not only by RotorS developers but also the CrazyS ones. I remember well that CrazyS is nothing else than a branch, an extension of RotorS.
Giuseppe, is there a way to run the simulink for one step? because when i put my controller scheme it generates the input till the quadrotor settles so for example it can reach z=1 then fall and in the next simulation step it will do the same and so on.
I don't know how your controller works, but you have to take into account that now the simulation is in discrete time and not continuous.
what kinda worked for me was to do the whole thing on matlab, i tried out a simple PID for Z. it goes to the desired Z position and keeps hovering for about 40 seconds perfectly then it drifts slowly and eventually falls. Can you give me your email so i can send you?
My e-mail address is giuseppe.silano[at]unisannio.it :-)
@ffurrer, I just updated the wiki section of RotorS related issue above. Here the link
https://github.com/ethz-asl/rotors_simulator/wiki/Interfacing-RotorS-through-Matlab
In the coming days, I will release a new version of CrazyS with all the files I mentioned in the wiki. I hope it will be useful for all RotorS users.
@gsilano Hello, I was wondering if you would inform me of the documentation or reference for the hovering example controller model at https://github.com/ethz-asl/rotors_simulator/wiki/Interfacing-RotorS-through-Matlab#examples-controller.
Hi @mahdinobar! I don't know if I understand correctly, but all the information regarding the use of the MathWorks Robotics System Toolbox with RotorS are reported in the Wiki section of CrazyS and RotorS. Are you looking for other stuff?
So if this is my controller with the system, i should just change the feedback to be of x y z roll pitch and yaw to be from the workspace of matlab which come from gazebo?
Hello, please can u send me your model ?
Here it is the link to the Wiki page: https://github.com/ethz-asl/rotors_simulator/wiki/Interfacing-RotorS-through-Matlab
Hi Everyone,
I have been working on a similar problem which HusseinHazem was working on and that is how to publish motor speed commands using Simulink. I believe I have figured out a method to do so. I am attaching a simulink file as well and hope it helps.
The solution requires the use of "Use of Matlab function to assign nested arrays" documentation in Matlab, I have done this for the mav_msgs/Actuators message.
In the function make sure that the message length is defined using the command
msg.AngularVelocities_SL_Info.CurrentLength=uint32(4);
After that assign values to the motor using the command msg.AngularVelocities=u;
Where u is the input to the function. I am using Matlab 2021b so if you need an older version do let me know. I have been trying to figure this problem out for quite a few months and I hope this helps other people.
I launched the mav_hovering_example.launch file and commented out lines 32 till line 36 (the part where the lee_position_controller node launches) to be able to control the speeds of the motors using the message publisher in rqt. Is it possible to control each motor speed from the simulink ros blocks? and if so how can i do it? My attempt leads to gazebo freezing and even then i don't how to access each motor speed separately.