mavros icon indicating copy to clipboard operation
mavros copied to clipboard

How can I edit the set_point.cpp file such that I can change velocity along with the global position?

Open mariofaragalla opened this issue 3 years ago • 4 comments

This is only bug and feature tracker, please use it to report bugs or request features.


Issue details

I am working on a drone project I’m connecting ros to gazebo and using the mavros node of course. I would like to publish position messages to /mavros/setpoint_position/global topic and at the same time I’m trying to adjust the velocity with which the drone goes to the intended position using the /mavros/setpoint_velocity/cmd_vel, but it doesn’t work together. I think the problem is in the setpoint_position.cpp in this method:

void setpointg_cb(const geographic_msgs::GeoPoseStamped::ConstPtr &req) { using mavlink::common::POSITION_TARGET_TYPEMASK;

	uint16_t type_mask = uint16_t(POSITION_TARGET_TYPEMASK::VX_IGNORE)
				| uint16_t(POSITION_TARGET_TYPEMASK::VY_IGNORE)
				| uint16_t(POSITION_TARGET_TYPEMASK::VZ_IGNORE)
				| uint16_t(POSITION_TARGET_TYPEMASK::AX_IGNORE)
				| uint16_t(POSITION_TARGET_TYPEMASK::AY_IGNORE)
				| uint16_t(POSITION_TARGET_TYPEMASK::AZ_IGNORE);

	Eigen::Quaterniond attitude;
	tf::quaternionMsgToEigen(req->pose.orientation, attitude);
	Eigen::Quaterniond q = ftf::transform_orientation_enu_ned(
					ftf::transform_orientation_baselink_aircraft(attitude));

	set_position_target_global_int(
				req->header.stamp.toNSec() / 1000000,
				uint8_t(MAV_FRAME::GLOBAL_INT),
				type_mask,
				req->pose.position.latitude * 1e7,
				req->pose.position.longitude * 1e7,
				req->pose.position.altitude,
				Eigen::Vector3d::Zero(),
				Eigen::Vector3d::Zero(),
				ftf::quaternion_get_yaw(q),
				0);

}

As I believe that this bit masking ignores the velocity change effects.

Thank you in advance.

MAVROS version and platform

Mavros: ?1.0.0? ROS: ?noetic? Ubuntu: ?20.04?

Autopilot type and version

[ ] ArduPilot [ ] PX4

Version: ?3.7.1?

mariofaragalla avatar May 24 '21 13:05 mariofaragalla

As i remember you cannot control at the same time position and velocity (or attitude?), in any case i suppose easier to use setpoint_raw for prototyping. Then check your autopilot code to see which type masks it supports.

vooon avatar May 29 '21 07:05 vooon

What do you mean by prototyping? I tried to publish the desired position and velocity to the mavros/setpoint_raw/global topic once from my ros node and another time using rostopic pub -r 50 but I didn't see any change with the drone's position or velocity in the gazebo simulation.

mariofaragalla avatar May 29 '21 17:05 mariofaragalla

Did you update header.stamp? Update stream also should be frequent, else OFFBOARD would disable (or don't enable).

By prototyping i mean that it's easier to use existing plugin than do new one gust to try different type masks.

vooon avatar May 31 '21 09:05 vooon

use the /mavros/setpoint_velocity/cmd_vel_unstamped in offboard mode and publish this topic of type Twist to control it with some teleop command node like teleop_twist_keyboard. You can use the PointTarget message of topic /mavros/setpoint_raw/local to takeoff to a certain height and start publishing velocity commands instead of position. you don't have to edit .cpp files. you can reffer to my code if you didn't understand https://github.com/thitapi/Drone-sim/blob/main/exp1/src/px4/offboard.py I have used this code as a base code and modified it to take teleop commands https://akshayk07.weebly.com/offboard-control-of-pixhawk.html

thitapi avatar Jun 24 '21 14:06 thitapi