mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14:58 +00:00
Documentation kobuki, mqtt, opencv
This commit is contained in:
50
docs/code/Mqtt.md
Normal file
50
docs/code/Mqtt.md
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# MQTT
|
||||||
|
|
||||||
|
## What is MQTT?
|
||||||
|
MQTT is a lightweight messaging protocol made for IOT devices. It allows efficient communication between IoT devices, servers, and applications by allowing them to
|
||||||
|
publish and subscribe to messages.
|
||||||
|
|
||||||
|
|
||||||
|
## How to connect
|
||||||
|
To connect to a MQTT server you need to create a instance of the class.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```cpp
|
||||||
|
// server adress, Client ID, Client Username, Client Password
|
||||||
|
MqttClient client("ws://145.92.224.21/ws/", "KobukiRPI", "rpi", "rpiwachtwoordofzo"); // create a client object
|
||||||
|
```
|
||||||
|
Later in the setup function you need to call ```client.connect();``` to connect to the mqtt server.
|
||||||
|
```cpp
|
||||||
|
client.connect();
|
||||||
|
```
|
||||||
|
|
||||||
|
When you've connected and the instance is initiated you can subscribe to topics or send messages to topics.
|
||||||
|
|
||||||
|
|
||||||
|
## Subscribing and receiving messages
|
||||||
|
Example subscribing to a topic:
|
||||||
|
```cpp
|
||||||
|
void setup(){
|
||||||
|
client.subscribe("home/commands");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example receiving latest message from a topic:
|
||||||
|
```cpp
|
||||||
|
std::string foo(){
|
||||||
|
std::string latestMqttMessage = "";
|
||||||
|
latestMqttMessage = client.getLastMessage();
|
||||||
|
return latestMqttMessage;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to subscribe to mulitple topics you need to initiate multiple instances of the mqtt class.
|
||||||
|
|
||||||
|
## Publishing messages
|
||||||
|
Example publishing a message:
|
||||||
|
```cpp
|
||||||
|
void foo(std::string Message){
|
||||||
|
//channel, payload
|
||||||
|
client.publishMessage("kobuki/example", Message);
|
||||||
|
}
|
||||||
|
```
|
@@ -1,20 +1,69 @@
|
|||||||
# OpenCV
|
# OpenCV
|
||||||
## Requirements
|
## Requirements
|
||||||
For the camera we want it to detect what is happening on the video feed and identify it so it can identify dangers.
|
We want that the camera we want it to detect what is happening on the video feed and identify it so it can identify dangers.
|
||||||
|
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
|
|
||||||
* OpenCL not grabbing gpu
|
* OpenCL not grabbing gpu
|
||||||
* Solution: https://github.com/Smorodov/Multitarget-tracker/issues/93
|
* Solution: https://github.com/Smorodov/Multitarget-tracker/issues/93
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
### Dependencies
|
### Dependencies
|
||||||
* glew
|
* glew (for openGL)
|
||||||
* opencv
|
* opencv C++ lib
|
||||||
|
|
||||||
|
How to install OpenCV
|
||||||
|
```bash
|
||||||
|
sudo apt-get install libopencv-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Code explanation
|
||||||
|
|
||||||
|
### Opening the camera with OpenCV
|
||||||
|
```cpp
|
||||||
|
VideoCapture cap(0); //Open the default camera (0), points to /dev/video0. You could also change the number to the preferred camera
|
||||||
|
if (!cap.isOpened()) { //if camera is not opened throw a error message
|
||||||
|
cerr << "Error: Could not open camera" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Taking a picture and storing it in a variable
|
||||||
|
```cpp
|
||||||
|
Mat frame; //create a new Matrix variable called frame
|
||||||
|
while (true) {
|
||||||
|
cap >> frame; // Capture a new image frame.
|
||||||
|
if (frame.empty()) { //if the variable frame is not filled return a error
|
||||||
|
cerr << "Error: Could not capture image" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Encoding the image for sending it over MQTT
|
||||||
|
```cpp
|
||||||
|
vector<uchar> buf; //create a dyanmic buffer for the image
|
||||||
|
imencode(".jpg", frame, buf); //encode the image to the buffer
|
||||||
|
auto* enc_msg = reinterpret_cast<unsigned char*>(buf.data());
|
||||||
|
```
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
|
||||||
|
void CapnSend() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Convert the image to a byte array
|
||||||
|
|
||||||
|
|
||||||
|
// Publish the image data
|
||||||
|
client.publishMessage("kobuki/cam", string(enc_msg, enc_msg + buf.size()));
|
||||||
|
cout << "Sent image" << endl;
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(300)); // Send image every 1000ms
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Sources
|
## Sources
|
||||||
* https://github.com/UnaNancyOwen/OpenCVDNNSample/tree/master
|
* https://github.com/UnaNancyOwen/OpenCVDNNSample/tree/master
|
25
docs/code/kobuki-driver.md
Normal file
25
docs/code/kobuki-driver.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Kobuki driver
|
||||||
|
|
||||||
|
## How do i communicate with the kobuki
|
||||||
|
You can communicate with the kobuki by usb serial or the big serial port on the front. We chose the usb port paired with a raspberry Pi.
|
||||||
|
|
||||||
|
The Kobuki sends a message every 200ms with a baudrate of 115200. It sends all the sensordata and the message always starts with the same 2 bytes 0xAA and 0x55.
|
||||||
|
|
||||||
|
## Kobuki payloads
|
||||||
|
To communicate with the kobuki we need to send payloads to the kobuki. These are structured the same as the payloads that the kobuki sends.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
unsigned char KobukiPayload[11] = {
|
||||||
|
0xaa, // Start byte 1
|
||||||
|
0x55, // Start byte 2
|
||||||
|
0x08, // Payload length (the first 2 bytes dont count)
|
||||||
|
0x01, // payload type (0x01 = control command)
|
||||||
|
0x04, // Control byte or additional identifier
|
||||||
|
actual_speed % 256, // Lower byte of speed value (max actual_speed 1024)
|
||||||
|
actual_speed >> 8, // Upper byte of speed value
|
||||||
|
0x00, // Placeholder for radius
|
||||||
|
0x00, // Placeholder for radius
|
||||||
|
0x00 // Placeholder for checksum (will be applied later)
|
||||||
|
};
|
||||||
|
```
|
||||||
|
You can also find the documentation about the payloads on the kobuki website
|
Reference in New Issue
Block a user