Robotics StackExchange | Archived questions

Rotors control with matlab/simulink on Gazebo

Hi, I want to ask you a simple question: can I control rotors of a simulate drone on Gazebo, with matlab/simulink on ubuntu 14.04? I had installed all software components and they have a good communication (matlab-ros-gazebo). I can take some value of drone with matlab, but I don't understand how to control the velocity of drone's rotors. Thanks in advance.


Update

rosinit

$ rosinit

The value of the ROS_MASTER_URI environment variable, http://127.0.1.1:11311, will be used to connect to the ROS master.
The value of the ROS_HOSTNAME environment variable, 127.0.1.1, will be used to set the advertised address for the ROS node.
Warning: The IP address 127.0.1.1 in the "NodeHost" setting is not associated with any network
interface. It is possible that MATLAB cannot be reached by other ROS nodes. 
  In robotics.ros.internal.Net.generateNodeHost (line 368)
  In robotics.ros.Node.parseArguments (line 313)
  In rosinit (line 92) 
Initializing global node /matlab_global_node_54033 with NodeURI http://127.0.1.1:37780/

rostopic

$ rostopic list

/clock                                                                  
/command/motors                                                         
/command/rate                                                           
/diagnostics                                                            
/erlecopter/bottom/camera_info                                          
/erlecopter/bottom/image_raw                                            
/erlecopter/bottom/image_raw/compressed                                 
/erlecopter/bottom/image_raw/compressed/parameter_descriptions          
/erlecopter/bottom/image_raw/compressed/parameter_updates               
/erlecopter/bottom/image_raw/compressedDepth                            
/erlecopter/bottom/image_raw/compressedDepth/parameter_descriptions     
/erlecopter/bottom/image_raw/compressedDepth/parameter_updates          
/erlecopter/bottom/image_raw/theora                                     
/erlecopter/bottom/image_raw/theora/parameter_descriptions              
/erlecopter/bottom/image_raw/theora/parameter_updates                   
/erlecopter/bottom/parameter_descriptions                               
/erlecopter/bottom/parameter_updates                                    
/erlecopter/command/attitude                                            
/erlecopter/command/motor_speed                                         
/erlecopter/fix                                                         
/erlecopter/fix/position/parameter_descriptions                         
/erlecopter/fix/position/parameter_updates                              
/erlecopter/fix/status/parameter_descriptions                           
/erlecopter/fix/status/parameter_updates                                
/erlecopter/fix/velocity/parameter_descriptions                         
/erlecopter/fix/velocity/parameter_updates                              
/erlecopter/fix_velocity                                                
/erlecopter/front/camera_front_info                                     
/erlecopter/front/image_front_raw                                       
/erlecopter/front/image_front_raw/compressed                            
/erlecopter/front/image_front_raw/compressed/parameter_descriptions     
/erlecopter/front/image_front_raw/compressed/parameter_updates          
/erlecopter/front/image_front_raw/compressedDepth                       
/erlecopter/front/image_front_raw/compressedDepth/parameter_descriptions
/erlecopter/front/image_front_raw/compressedDepth/parameter_updates     
/erlecopter/front/image_front_raw/theora                                
/erlecopter/front/image_front_raw/theora/parameter_descriptions         
/erlecopter/front/image_front_raw/theora/parameter_updates              
/erlecopter/front/parameter_descriptions                                
/erlecopter/front/parameter_updates                                     
/erlecopter/gazebo/command/motor_speed                                  
/erlecopter/ground_truth/imu                                            
/erlecopter/ground_truth/odometry                                       
/erlecopter/ground_truth/pose                                           
/erlecopter/ground_truth/pose_with_covariance                           
/erlecopter/ground_truth/position                                       
/erlecopter/ground_truth/transform

Gio8, [6 gen 2019, 19:28:27]:
/erlecopter/imu                                                         
/erlecopter/motor_speed/0                                               
/erlecopter/motor_speed/1                                               
/erlecopter/motor_speed/2                                               
/erlecopter/motor_speed/3                                               
/erlecopter/motors                                                      
/erlecopter/waypoint                                                    
/erlecopter/wind                                                        
/gazebo/link_states                                                     
/gazebo/model_states                                                    
/gazebo/parameter_descriptions                                          
/gazebo/parameter_updates                                               
/gazebo/set_link_state                                                  
/gazebo/set_model_state                                                 
/imu                                                                    
/mavlink/from                                                           
/mavlink/to                                                             
/mavros/battery                                                         
/mavros/cam_imu_sync/cam_imu_stamp                                      
/mavros/extended_state                                                  
/mavros/global_position/compass_hdg                                     
/mavros/global_position/global                                          
/mavros/global_position/local                                           
/mavros/global_position/raw/fix                                         
/mavros/global_position/raw/gps_vel                                     
/mavros/global_position/rel_alt                                         
/mavros/imu/atm_pressure                                                
/mavros/imu/data                                                        
/mavros/imu/data_raw                                                    
/mavros/imu/mag                                                         
/mavros/imu/temperature                                                 
/mavros/local_position/odom                                             
/mavros/local_position/pose                                             
/mavros/local_position/velocity                                         
/mavros/manual_control/control                                          
/mavros/mission/waypoints                                               
/mavros/radio_status                                                    
/mavros/rc/in                                                           
/mavros/rc/out                                                          
/mavros/rc/override                                                     
/mavros/setpoint_accel/accel                                            
/mavros/setpoint_position/local                                         
/mavros/setpoint_raw/attitude                                           
/mavros/setpoint_raw/global                                             
/mavros/setpoint_raw/local                                              
/mavros/setpoint_raw/target_attitude                                    
/mavros/setpoint_raw/target_global                                      
/mavros/setpoint_raw/target_local                                       
/mavros/setpoint_velocity/cmd_vel                                       
/mavros/state                                                           
/mavros/time_reference                                                  
/mavros/vfr_hud                                                         
/mavros/wind_estimation                                                 
/rosout                                                                 
/rosout_agg                                                             
/scan                                                                   
/sonar_d                                                         
/sonar_front                                                            
/tf                                                                     
/tf_static

C++

motor_speeds = rospublisher('/erlecopter/gazebo/command/motor_speed','mav_msgs/Actuators');
The /erlecopter/gazebo/command/motor_speed topic with message type mav_msgs/CommandMotorSpeed is
already registered on the ROS master. Try creating it with type mav_msgs/CommandMotorSpeed, not
mav_msgs/Actuators.

motor_speeds = rospublisher('/erlecopter/gazebo/command/motor_speed','mav_msgs/CommandMotorSpeed');
Failed to create a publisher with topic name /erlecopter/gazebo/command/motor_speed and type
mav_msgs/CommandMotorSpeed.

motor_speeds = rospublisher('/erlecopter/motors','mav_msgs/CommandMotorSpeed');
The /erlecopter/motors topic with message type mav_msgs/MotorSpeed is already registered on the
ROS master. Try creating it with type mav_msgs/MotorSpeed, not mav_msgs/CommandMotorSpeed.

motor_speeds = rospublisher('/erlecopter/motors','mav_msgs/MotorSpeed');
Failed to create a publisher with topic name /erlecopter/motors and type mav_msgs/MotorSpeed.

Not run... It's possible that the problem is:

Warning: The IP address 127.0.1.1 in the "NodeHost" setting is not associated with any network
interface. It is possible that MATLAB cannot be reached by other ROS nodes''?

Should I have to modify any folder? Or should I write something different?

Asked by Gio888 on 2019-01-03 07:24:39 UTC

Comments

I copied the information from your answer into your question since it's actually an update to your question and not an answer. I did my best to format your question, but please feel free to edit it as you see fit making sure to use the format (101010) button for code/output.

Asked by jayess on 2019-01-06 14:15:00 UTC

The problem seems to be with re-creating the topic. Check my updated answer.

Asked by robowarrior on 2019-01-08 05:57:08 UTC

Answers

Usually, to control the speeds of a UAV in rotorS, you need to publish an array of speeds to a particular topic, right?

For Eg: To set all of the motor speeds of 'firefly' UAV to 100, we run the command

rostopic pub /firefly/command/motor_speed mav_msgs/Actuators '{angular_velocities: [100, 100, 100, 100, 100, 100]}'

Now, the equivalent to this command, using a MATLAB script and rospublisher, is as follows: (This publishes messages to the ROS network.)

rosinit
motor_speeds = rospublisher('/firefly/command/motor_speed','mav_msgs/Actuators');
msg = rosmessage(motor_speeds);
msg.Data = '{angular_velocities: [100, 100, 100, 100, 100, 100]}';
send(motor_speeds, msg);

PS: Try this. Let me know what happens. Coz, I haven't run this. I just followed that above link. So, let me know how it goes.


UPDATE:

In case the ROS topic already exists, follow this:

rosinit
motor_speeds_topic = '/firefly/command/motor_speed';
msg = rosmessage(motor_speeds);
msg.Data = '{angular_velocities: [100, 100, 100, 100, 100, 100]}';
send(motor_speeds_topic, msg);

Change the value of motor_speeds_topic to that existing topic you want.

Peace fellazz!!

Asked by robowarrior on 2019-01-04 14:02:54 UTC

Comments

Hi! Can you please send me the link to this repository? I would also install the same simulator for my project. Thanks

Asked by Wajeeh on 2019-04-09 14:27:57 UTC

https://github.com/ethz-asl/rotors_simulator

Asked by robowarrior on 2019-04-10 16:57:49 UTC