Tracking another drone with Opencv and Pixhawk2 - c++

I am working in a UAV-Team and my task is following and locking another UAV autonomously. I coded my opencv part and I used background substitution method and several filters. I can get absolute result from my code (like to forward go left , go right). My question is how can I send this result to the UAV's motors. How can I communicate with my UAV with C++? I've read lots of documentation from ardupilot, ardurov, opencv and pixhawk. But still couldn't figure it out.

Connect your microprocessor(i.e rasberry Pi) with pixhawk ans use mavlink communication protocols to send command here is link
And you can use dronekit also to do that.

Related

orocos ros integration, createStream causes execution to stuck in a loop

I'm integrating orocos with ros, basically i created a component that read data from some input ports and write on output ports that create streams, because i want to public this values on ros topics and then read those values in plotjuggler.
So I created this component without any problem and work perfectly. After that i created used another ssd configured in the same way as the previos ssd in which i build this component that publish data on ROS but on this new ssd when i call the first createStream() it stuck without any error as if it is in an infinite loop. The only thing that i notice different from the other ssd is that i got the following message
[2022-05-06 12:33:28] [connect] WebSocket Connection 192.168.2.13:8081 v-2 "WebSocket++/0.7.0" /socket.io/?EIO=4&transport=websocket&t=1651833208 101
to create the stream I'm using, in the c++ code the following code
port.setName(<port_name>);
port.doc(<doc>);
port.createStream(rtt_roscomm::topic(<topic_name>));
i also tried to create the stream in the ops file, but i get exactly the same result, when it reach that point it stuck.
I repeat again that i have a working version of this component on a similar ssd, so this means that the code inside the component is should be correct
as well as the ops file.
I'm on ubuntu 18.04.06 LTS, I'm using ROS melodic.
Is 1 week that I'm working on this issue without success, so i tried a lot of different things but at the end when i create a stream it stuck.
Ros is working because if i create a topic and i publish something from terminal or a create a simple ros package i can send and receive data, also orocos is working because i have different component running without problem.
I know that with so few information is difficult to solve the problem but why when i create a topic, with createStream, i get stuck in this loop?
There is any known case in which it is possible to remain stacked in this way during the creation of a topic in ros?

Using gazebo with drake for quadrotor

My objective is to use finite horizon linear quadratic regulator(FHLQR) to follow a trajectory generated by a mathematical program and simulate it in Gazebo. As FHLQR needs a system as input, I'm using the QuadrotorPlant, but I'm not sure if this is ideal. My problems arise when I try to connect the state from Gazebo into Drake. In short, what would be the proper way of coupling state from Gazebo with a controller such as FHLQR?
I've thought about editing the context of QuadrotorPlant to mirror the state in Gazebo, but after this update I'm having trouble getting control output from the controller. I've also thought about coupling the Simulator between the output of the controller and input of the QuadrotorPlant, but haven't figured out how to modify the Simulator to mirror Gazebo.
And for your gazebo interface, and assuming you're all in c++, then I'd imagine it will look something like this:
// setup
auto regulator = MakeFiniteHorizonLinearQuadraticRegulator(...);
auto context = regulator.CreateDefaultContext();
// during execution
context->SetTime(time_from_gazebo);
context->FixInputPort(0, Eigen::VectorXd([state obtained from gazebo]));
Eigen::VectorXd u = regulator->get_output_port(0)->Eval(context);
// then apply u to your gazebo interface
I think we should be able to help, but probably need a few more details.
My mental model of your setup is that you use QuadrotorPlant to design the trajectory and the MakeFiniteHorizonLinearQuadraticRegulator methods in drake... the result of that is a drake System that has an input port expecting a vector of doubles representing the state of the quadrotor, and it outputs a vector of doubles that represent the thrust commands for the quadrotor.
Separately, you have a Gazebo simulator with a quadrotor, that is accepts commands and simulates the dynamics.
Are you trying to connect them via message passing (as opposed to a single executable)? Presumably with ROS1 messages? (If yes, then we have little systems in drake that can send/receive ROS messages, which we can point you to)
FWIW, I would definitely recommend trying the workflow with just running an LQR controller in drake before trying the trajectory version.

What is the correct way to read advertisement packets from a BLE sensor using bluez 5.43 and DBus

I am trying to implement a C++ code (using bluez 5.43 and dbus) to read advertisement packets from a BLE sensor. As per the bluez DBus docs, there is a StartDiscovery API that can be used to scan for nearby devices. However, I am unable to find any APIs to store/parse the advertisement packets from nearby BLE devices. The advertising-api.txt lists registeradvertisement API but as per my understanding, it can be used only for creating advertisement packets and not reading from an external device (or am I wrong?) Can someone please guide me on the correct way to get advertisement packets from nearby BLE devices using bluez and DBus?
Thanks for the suggestions everyone. I was finally able to get the manufacturer data by using Intel's tinyb library. It has an enable_manufacturer_data_notifications API which enables you to be notified whenever the manufacturer data changes.
The behavior you described in one your last comment is the right one (the advertising data is not beeing updated) : if I am correct a BLE device is not supposed to be up all the time, it can sleep or turn to low-power etc.
In this context, it is not weird that the data is in some way "cached". From my experience, when you perform a scan and discover a device (even if you don't Connect to it), the device information will be stored for some time.
In your case, that's problematic because you are passing data through the advertising. However there is a way to force bluez to remove all it's cached data about a device :
the adapter-api provides a RemoveDevice(object device) method. It takes the object path (eg "/org/bluez/hci0/dev_AA_BB_AA_BB_AA") as argument.
If you're looking for DBus bindings in C, I suggest GLib GDBus (you will find links at the bottom of this tutorial on freedesktop website : https://dbus.freedesktop.org/doc/dbus-tutorial.html).
If you are familiar with bluetoothctl (a tool to interact with bluez using commands), it was developped by the bluez guys using Glib GDbus and you can find the source code here (look at the bottom to find the command list) : https://git.kernel.org/cgit/bluetooth/bluez.git/tree/client/main.c
There are more straigthforward ways to use GDBus with bluez but bluetoothctl source code is a start and you'll find examples for pretty much anything that is possible to do with bluez =)

Recording, streaming and recieving audio over a LAN with python

I'm looking into coding a very simple LAN based home monitoring system using python 2.7 on Windows. I have a number of computers around the house each with a usb webcam attached. The cameras have built in microphones. I'm looking for the best way to capture and stream the audio and video over the network, then recieve and view/listen to it. I'm guessing I'd have to use PyAudio to get the audio from the microphone and CV2 to get the video, past that, I'm not sure how I'd stream that data to another computer, recieve it and then view/listen to it.
Not realy a question here, but still I guess I have a solution for you
(but there a millions of ways to solve this.)
My way is ROS (Robot Operating System), which is basically a TCP/IP Service Wrapper. Anyway you can simple broadcast and receive streams via your network.
ROS can be implemented in C++ or Python.
ROS usually applies OpenCV as CV-library, so it should suite your wishes.
Straight forward examples for video are (i.e.) here:
mjpeg_server
web_video_server
Audio streaming is introduced here:
audio_common (there might be solutions via PyAudio. Not sure if other solutions might come more easy and still suitable.)

creating realtime 2D maps of indoor environment

I am using ultrasonic sensors to get the data about the indoor environment i.e the distance of the from each wall . I want draw a realtime map of the surronding environment using that can u please guide that which software or which library is best suited for this purpose
Try OpenCV. It has everything you need for image processing. Could be an overkill tho, but I wouldn't mind it.
http://opencv.org/
If you want realtime map, I'd use Labview->embedded MATLAB code / C++. Labview has excellent hardware/peripheral support and operations, and you can embed custom code in the signal flow representation.
If you are using something like arduino or raspberry or any other such electronics kit to capture the ultrasound data, you can send the data to the serial port and then use Matlab to read from that serial port and use it to plot a live map. A good step by step example of how this can be done is available at Matlab Arduino org website