mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-05 12:54:57 +00:00
Compare commits
19 Commits
35-als-geb
...
8b66702605
Author | SHA1 | Date | |
---|---|---|---|
|
8b66702605 | ||
|
d8b3ec2938 | ||
|
97076dfe05 | ||
|
967bc8247c | ||
|
5d61579973 | ||
|
ebd88e43ab | ||
|
2fbe18be76 | ||
|
74d9687af5 | ||
|
48023773c6 | ||
56ac9cf687 | |||
|
3232ff121f | ||
5844387b19 | |||
|
b48243f831 | ||
317731ec87 | |||
441ca19578 | |||
7f807d0031 | |||
c0ec6901c4 | |||
2fa8fb2926 | |||
|
1fd88c7636 |
35
README.md
35
README.md
@@ -1,8 +1,39 @@
|
||||
# TI-project - Kobuki
|
||||
# TI-project - exploration robot Kobuki
|
||||
|
||||
## Description
|
||||
This project is a kobuki that drives around in dangerous areas and detects objects in its path. It uses a camera to detect objects. The kobuki is able to drive around in a room and detect objects.
|
||||
This project is a kobuki that drives around in dangerous areas and detects objects in its path. It uses a camera to detect objects. The purpose of this project is to explore dangerous areas without risking human lives. You are able to control the robot using controller on the website.
|
||||
|
||||
## Photos
|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
### Requirements
|
||||
|
||||
- Kobuki robot
|
||||
- Raspberry Pi (minimum 3B)
|
||||
- Camera
|
||||
- power supply for Raspberry Pi
|
||||
- laptop or computer
|
||||
|
||||
### Steps
|
||||
|
||||
1. **Install Python and Pip**
|
||||
- Ensure you have Python installed on your system. You can download it from [python.org](https://www.python.org/).
|
||||
- Pip is the package installer for Python. It usually comes with Python, but you can install it separately if needed.
|
||||
|
||||
2. **Clone Our Repository**
|
||||
- Clone our repository to your local machine doing the following :
|
||||
- Open your terminal
|
||||
- Change the current working directory to the location where you want the cloned directory.
|
||||
- Type `git clone https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
|
||||
|
||||
3. **Install the required packages**
|
||||
- Open the terminal and navigate to the project - scr - Python - flask.
|
||||
- Run the following command to install the required packages:
|
||||
- `pip install -r requirements.txt`
|
||||
- This will install all the python packages required to run the project.
|
||||
- for C++, you will need to install the following packages:
|
||||
- OpenCV
|
||||
- mqtt-client
|
||||
4.
|
@@ -8,6 +8,8 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
CKobuki robot;
|
||||
std::atomic<bool> kobuki_connected(false);
|
||||
|
||||
|
||||
std::string readMQTT();
|
||||
void parseMQTT(std::string message);
|
||||
@@ -28,12 +30,28 @@ void setup()
|
||||
client.subscribe("home/commands");
|
||||
}
|
||||
|
||||
void checkKobukiConnection() {
|
||||
while (true) {
|
||||
bool connected = robot.isConnected();
|
||||
if (!connected && kobuki_connected) {
|
||||
cout << "Kobuki is disconnected" << endl;
|
||||
kobuki_connected = false;
|
||||
} else if (connected && !kobuki_connected) {
|
||||
cout << "Kobuki is connecting..." << endl;
|
||||
// Start de Kobuki automatisch
|
||||
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5)); // Controleer elke 5 seconden
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
setup();
|
||||
std::thread image (CapnSend);
|
||||
std::thread safety([&]() { robot.robotSafety(&message); });
|
||||
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
|
||||
std::thread connectionThread(checkKobukiConnection);
|
||||
|
||||
while(true){
|
||||
std::string message = readMQTT();
|
||||
@@ -46,6 +64,7 @@ int main()
|
||||
sendMqtt.join();
|
||||
safety.join();
|
||||
image.join();
|
||||
connectionThread.join();
|
||||
}
|
||||
|
||||
std::string readMQTT()
|
||||
|
@@ -14,5 +14,5 @@ EXPOSE 5000
|
||||
CMD ["python", "web/app.py"]
|
||||
|
||||
#build instruction: sudo docker buildx build -t flaskapp:latest .
|
||||
#run instruction: sudo docker run --network="host" flaskapp:latest
|
||||
#run instruction: sudo docker run --network="host" --restart=always flaskapp:latest
|
||||
# need to use network host to connect to the host's mqtt server
|
@@ -3,3 +3,4 @@ paho-mqtt==1.6.1
|
||||
ultralytics==8.3.58
|
||||
opencv-python-headless==4.6.0.66
|
||||
numpy==1.23.4
|
||||
mysql-connector-python==9.1.0
|
@@ -1,4 +1,4 @@
|
||||
from flask import Flask, Response, request, render_template, jsonify
|
||||
from flask import Flask, Response, request, render_template, jsonify, g
|
||||
import paho.mqtt.client as mqtt
|
||||
from ultralytics import YOLO
|
||||
import cv2
|
||||
@@ -49,18 +49,6 @@ def on_message(client, userdata, message):
|
||||
cv2.rectangle(processed_image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
||||
cv2.putText(processed_image, f"{class_name} {box.conf.item():.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
|
||||
|
||||
|
||||
# Globale MQTT setup
|
||||
def on_message(client,userdata, message):
|
||||
global kobuki_message, latest_image
|
||||
if message.topic == "kobuki/data":
|
||||
kobuki_message = str(message.payload.decode("utf-8"))
|
||||
with app.app_context():
|
||||
sensor_data(kobuki_message) # Sla de data op in de database
|
||||
elif message.topic == "kobuki/cam":
|
||||
latest_image = message.payload
|
||||
|
||||
|
||||
# Create an MQTT client instance
|
||||
mqtt_client = mqtt.Client()
|
||||
mqtt_client.username_pw_set("server", "serverwachtwoordofzo")
|
||||
@@ -71,9 +59,6 @@ mqtt_client.subscribe("kobuki/cam")
|
||||
|
||||
mqtt_client.on_message = on_message # this line needs to be under the function definition otherwise it can't find which function it needs to use
|
||||
|
||||
mqtt_client.on_message = on_message # this line needs to be under the function definition otherwise it can't find which function it needs to use
|
||||
|
||||
|
||||
# Database connectie-functie
|
||||
def get_db():
|
||||
if 'db' not in g: # 'g' is specifiek voor een request en leeft zolang een request duurt
|
||||
@@ -122,17 +107,10 @@ def move():
|
||||
cursor.close()
|
||||
db_connection.close()
|
||||
return jsonify({"status": "success", "direction": direction})
|
||||
|
||||
|
||||
@app.route("/database")
|
||||
def database():
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
cursor.execute("SELECT * FROM kobuki_data")
|
||||
rows = cursor.fetchall()
|
||||
cursor.close()
|
||||
return str(rows)
|
||||
|
||||
def sensor_data(kobuki_message):
|
||||
@app.route('/data', methods=['GET'])
|
||||
def data():
|
||||
try:
|
||||
# Parse de JSON-string naar een Python-dictionary
|
||||
data = json.loads(kobuki_message)
|
||||
@@ -152,23 +130,21 @@ def sensor_data(kobuki_message):
|
||||
|
||||
# Database-insert
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
with db.cursor() as cursor:
|
||||
|
||||
# Zorg dat je tabel `kobuki_data` kolommen heeft: `name` en `value`
|
||||
sql_sensor = "INSERT INTO kobuki_data (name, value) VALUES (%s, %s)"
|
||||
cursor.executemany(sql_sensor, sensor_data_tuples)
|
||||
|
||||
# Commit en sluit de cursor
|
||||
db.commit()
|
||||
cursor.close()
|
||||
# Zorg dat je tabel `kobuki_data` kolommen heeft: `name` en `value`
|
||||
sql_sensor = "INSERT INTO kobuki_data (name, value) VALUES (%s, %s)"
|
||||
cursor.executemany(sql_sensor, sensor_data_tuples)
|
||||
|
||||
# Commit en sluit de cursor
|
||||
db.commit()
|
||||
cursor.close()
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"JSON decode error: {e}")
|
||||
except mysql.connector.Error as err:
|
||||
print(f"Database error: {err}")
|
||||
|
||||
@app.route('/data', methods=['GET'])
|
||||
def data():
|
||||
return kobuki_message
|
||||
|
||||
|
||||
|
||||
@app.route('/image')
|
||||
@@ -188,6 +164,16 @@ def yolo_results_endpoint():
|
||||
with lock:
|
||||
return jsonify(yolo_results)
|
||||
|
||||
def yolo_results_db():
|
||||
global yolo_results
|
||||
db = get_db()
|
||||
with db.cursor() as cursor:
|
||||
sql_yolo = "INSERT INTO yolo_results (object, confidence) VALUES (%s, %s)"
|
||||
yolo_tuples = [(result["class"], result["confidence"]) for result in yolo_results]
|
||||
cursor.executemany(sql_yolo, yolo_tuples)
|
||||
db.commit()
|
||||
cursor.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=5000)
|
@@ -34,7 +34,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the data and show it on the website
|
||||
// Parse the data and show it on the website
|
||||
async function parseData() {
|
||||
const data = await fetchData();
|
||||
const sensorDataContainer = document.getElementById("sensor-data");
|
||||
sensorDataContainer.innerHTML = ""; // Clear previous data
|
||||
@@ -57,5 +58,4 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
// Update the image every 200 milliseconds
|
||||
setInterval(updateImage, 100);
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user