-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controlling actuator velocities using simulink blocks #487
Comments
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 |
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 mav_msgs/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'); where Omega_1, Omega_2, and so on, are the propellers angular velocities you would publish. I hope I have made it clear. |
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. |
You cannot use this kind of Matlab function in Simulink. I mean, you cannot publish a ROS message via Simulink by using it. 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. |
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. 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. 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). |
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, it should work. |
You have to save the variables in the Workspace as 2D Array. See my Simulink scheme. |
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. |
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? |
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 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.
The text was updated successfully, but these errors were encountered: