Quantcast
Channel: ArduPilot Discourse - Latest topics
Viewing all articles
Browse latest Browse all 46999

Sending MAVLink command via UDP to MAVProxy

$
0
0

@SalahuddinAsh wrote:

I'm trying to send MAVLink commands from my application to SITL "Sim_Vehicly.py" to test my code. As a start I'm trying to send a "Takeoff to height 20" command. My code can send UDP packets to "127.0.0.1:14551". There is something wrong with my code as MAVProxy doesn't receive the message. I hope if anyone can tell me where the problem is. When I run
sudo tcpdump -i lo -n udp port 14551
the output is
18:42:46.734776 IP 127.0.0.1.39634 > 127.0.0.1.14551: UDP, length 41
Here is the code:

using boost::asio::ip::udp;

uint16_t targetSysId = 1;
uint16_t targetCompId = 214;

class UDPClient
{
public:
	UDPClient(
		boost::asio::io_service& io_service, 
		const std::string& host, 
		const std::string& port
	) : io_service_(io_service), socket_(io_service, udp::endpoint(udp::v4(), 0)) {
		udp::resolver resolver(io_service_);
		udp::resolver::query query(udp::v4(), host, port);
		udp::resolver::iterator iter = resolver.resolve(query);
		endpoint_ = *iter;
	}

	void send(const uint8_t *msg, const uint16_t size) {
		socket_.send_to(boost::asio::buffer(msg, size), endpoint_);
	}
	
private:
	boost::asio::io_service& io_service_;
	udp::socket socket_;
	udp::endpoint endpoint_;
};

int main(void)
{
	mavlink_system.sysid = SYS_ID;
	mavlink_system.compid = MAV_COMP_ID_IMU;

	boost::asio::io_service io_service;
	UDPClient client(io_service, "localhost", "14551");

mavlink_msg_command_long_pack(mavlink_system.sysid, mavlink_system.compid, &msg, targetSysId, 	
    			targetCompId, MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, 20);
    	len = mavlink_msg_to_send_buffer(buf, &msg);

	while(1)
	{
		client.send(pbuf, len);
	}
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 46999

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>