139 Commits

Author SHA1 Message Date
3fddee73c7 Merge branch 'main' into 35-als-gebruiker-wil-ik-dat-mijn-data-word-opgeslagen-in-een-database-om-data-terug-te-zien 2025-01-13 10:26:29 +01:00
ishak jmilou.ishak
06dd2d9f48 fix: streamline Kobuki communication startup and reconnection logic 2025-01-09 15:52:22 +01:00
ishak jmilou.ishak
7d3a5fa9a3 fix: improve Kobuki communication startup and reconnection logging 2025-01-09 15:43:45 +01:00
ishak jmilou.ishak
3bca04053a fix: add reconnect attempt logging for Kobuki communication 2025-01-09 15:36:28 +01:00
ishak jmilou.ishak
82363d393c fix: add reconnection logic for Kobuki in main loop 2025-01-09 15:32:30 +01:00
ishak jmilou.ishak
1964589abc fix: update sensor_data function to process and store JSON message from kobuki 2025-01-09 14:57:56 +01:00
ishak jmilou.ishak
8d339851dd commented sensor data 2025-01-09 14:51:17 +01:00
ishak jmilou.ishak
79c2073d29 want to check data 2025-01-09 14:50:41 +01:00
ishak jmilou.ishak
ffbf3347f4 removed parameter 2025-01-09 14:37:26 +01:00
ishak jmilou.ishak
64452b78b4 fix: retrieve JSON data directly in sensor_data function 2025-01-09 14:36:57 +01:00
ishak jmilou.ishak
c87ebc565c fix: parse JSON message before saving sensor data 2025-01-09 14:34:26 +01:00
ishak jmilou.ishak
39659fffab fix: correct variable name in on_message function to use 'data' instead of 'kobuki_message' 2025-01-09 14:30:33 +01:00
ishak jmilou.ishak
a4ae0170a0 refactor: update sensor_data function to accept data directly instead of JSON string 2025-01-09 14:29:54 +01:00
ishak jmilou.ishak
ed475cd19f split the data 2025-01-09 14:28:04 +01:00
ishak jmilou.ishak
a9c37ec470 fix: ensure app context is set when saving sensor data 2025-01-09 14:21:06 +01:00
ishak jmilou.ishak
369120b16b feat: save sensor data to the database upon receiving message 2025-01-09 14:19:01 +01:00
ishak jmilou.ishak
ec71028270 wrote own functions for sending data 2025-01-09 14:16:16 +01:00
ishak jmilou.ishak
7560b0f67a changed to 2 functions 2025-01-09 14:09:33 +01:00
ishak jmilou.ishak
331de940cc fixed variable name 2025-01-09 14:06:13 +01:00
ishak jmilou.ishak
ec0b32a221 changed name 2025-01-09 14:04:40 +01:00
ishak jmilou.ishak
3aa77f5314 feat: insert sensor data into the database upon command execution 2025-01-09 14:03:24 +01:00
ishak jmilou.ishak
e59f235b91 changed db send data to other function 2025-01-09 13:58:34 +01:00
ishak jmilou.ishak
2e4f048ed9 feat: call save_sensor_data function upon receiving kobuki/data message 2025-01-09 13:56:45 +01:00
ishak jmilou.ishak
9a3829cdb2 feat: add save_sensor_data function to insert sensor data into the database 2025-01-09 13:54:15 +01:00
ishak jmilou.ishak
015b2db819 refactor: change startCommunication return type from bool to void 2025-01-09 13:48:01 +01:00
ishak jmilou.ishak
6ef739f794 removed thread 2025-01-09 13:40:47 +01:00
ishak jmilou.ishak
ec2a08c656 refactor: comment out connection check in sendKobukiData function 2025-01-09 13:38:18 +01:00
ishak jmilou.ishak
89421ccf34 replaced connect 2025-01-09 13:31:41 +01:00
ishak jmilou.ishak
1c081451aa made thread to wait 1 sec before reconnect 2025-01-09 13:29:25 +01:00
ishak jmilou.ishak
2396d61eae fix: update on_message function signature to include userdata parameter 2025-01-09 13:24:57 +01:00
ishak jmilou.ishak
fa17893b1b fix: update connection check method in sendKobukiData function 2025-01-09 13:21:14 +01:00
ishak jmilou.ishak
07d88eef7d fix: improve connection handling and logging in KobukiDriver 2025-01-09 13:19:00 +01:00
ishak jmilou.ishak
d066f68ad2 replaced /data endpoint 2025-01-09 12:56:25 +01:00
ishak jmilou.ishak
d90ac72591 test older version 2025-01-09 12:52:11 +01:00
ishak jmilou.ishak
a2aa80804e fix: move mqtt_client.on_message assignment under function definition 2025-01-09 12:47:39 +01:00
ishak jmilou.ishak
612af45f59 refactor control.html to update robot image source and improve structure 2025-01-09 12:39:45 +01:00
ishak jmilou.ishak
3ff1b22346 uncomment robot image in control.html 2025-01-09 12:35:17 +01:00
ishak jmilou.ishak
1a4056ff77 return raw kobuki_message instead of jsonify in data endpoint 2025-01-09 12:02:36 +01:00
ishak jmilou.ishak
8517a0d558 comment out image update interval in script.js 2025-01-09 12:00:02 +01:00
ishak jmilou.ishak
092e4f5aeb remove camera code 2025-01-09 11:59:34 +01:00
ishak jmilou.ishak
9eb9822cff remove unused event listeners and redundant data fetching logic from script.js 2025-01-09 11:58:48 +01:00
ishak jmilou.ishak
fe64267307 added js from main branch 2025-01-09 11:56:54 +01:00
ishak jmilou.ishak
72a0fadef8 add UML diagram for system architecture and clean up MQTT client initialization 2025-01-09 11:45:19 +01:00
ishak jmilou.ishak
d0bfef2296 add feedback document with coding suggestions and improvements 2025-01-08 16:40:34 +01:00
ishak jmilou.ishak
71091f57dd removed code that didnt work 2025-01-08 15:25:30 +01:00
ff7b148556 start readme 2025-01-08 14:20:38 +01:00
ishak jmilou.ishak
fa85be2df5 removed mqtt check 2025-01-08 14:18:46 +01:00
ishak jmilou.ishak
4bf3cd6d37 added mqtt connection safety 2025-01-08 14:15:06 +01:00
ishak jmilou.ishak
361c17fbdb comment everything again 2025-01-08 13:59:06 +01:00
ishak jmilou.ishak
fe3fe2b8cf restored all my code 2025-01-08 13:40:38 +01:00
ishak jmilou.ishak
bcac062cdf comment out monitorKobukiConnection thread for debugging 2025-01-08 13:31:57 +01:00
ishak jmilou.ishak
b12e4c7539 removed thread as well 2025-01-08 13:29:43 +01:00
ishak jmilou.ishak
a979d15a6e commented my new code to check if bug is still here 2025-01-08 13:27:34 +01:00
ishak jmilou.ishak
184e723379 added new thread 2025-01-08 13:05:19 +01:00
ishak jmilou.ishak
2bfd11276a importlist changed 2025-01-07 15:00:13 +01:00
ishak jmilou.ishak
bc0b878230 changed to bool 2025-01-07 14:40:55 +01:00
ishak jmilou.ishak
806bb16662 changed startcom function 2025-01-07 14:38:38 +01:00
ishak jmilou.ishak
56f085b73d added parameters 2025-01-07 14:33:12 +01:00
ishak jmilou.ishak
b111e49dff functions for auto reconnect with pi and kobuki 2025-01-07 14:28:06 +01:00
6fe28f997a edited kobuki speedvalue for safety 2025-01-07 12:51:24 +01:00
1bf9ebddab added mutex in python 2025-01-07 11:30:04 +01:00
585a0e9a52 fix thread crash 2025-01-07 11:19:47 +01:00
cb988a5260 store new image in processed_image 2025-01-07 11:09:33 +01:00
5e01e25d9c comment update 2025-01-06 16:40:40 +01:00
0d184261fd updated systemd kobukidriver service file 2025-01-06 16:40:00 +01:00
ccaa722973 edited startup file for kobukidriver
(everything works now)
2025-01-06 16:31:52 +01:00
7d1b878c30 fix yolo image boxes 2025-01-06 16:11:03 +01:00
228c508012 attempt to fix broken code 2025-01-06 16:02:17 +01:00
7845feb9f8 update yolo naming in image 2025-01-06 15:55:24 +01:00
20d6d8799d attempt to show name next to image box 2025-01-06 15:45:29 +01:00
9c7c774030 change boxing and text error of YOLO 2025-01-06 15:26:00 +01:00
0832da0d3b change mqtt port in python 2025-01-06 15:16:13 +01:00
a59b9c8714 requirements update 2025-01-06 15:11:27 +01:00
4a05ec5efc added dockerfile 2025-01-06 15:11:21 +01:00
c3d575ccf1 added yolo image object detection to /image 2025-01-06 13:00:00 +01:00
1b0b1e87ce change directories and added driver service config 2025-01-06 11:44:08 +01:00
9c41d64c69 remove mqtt debug print 2025-01-06 11:23:27 +01:00
b48eda9735 change image refresh time 2025-01-06 10:35:54 +01:00
629f9cba92 attempt to fix javascript 2025-01-06 10:34:00 +01:00
51aad34c78 added bracket 2025-01-06 10:08:05 +01:00
ishak jmilou.ishak
bb1904b125 commentaar naar engels 2025-01-06 09:53:01 +01:00
ishak jmilou.ishak
b29a615681 verslag def versie 2025-01-06 09:52:50 +01:00
1b3fead2b3 documentation 2025-01-06 09:49:56 +01:00
ishak jmilou.ishak
1fb7010773 enhance verslag.md with detailed analysis of IoT communication protocols and their reliability 2025-01-03 17:07:46 +01:00
ishak jmilou.ishak
ae03800c23 bijna klaar met deelvragen 2025-01-02 22:47:58 +01:00
ishak jmilou.ishak
490e0536ca took older version of the fetch 2024-12-20 14:31:25 +01:00
ishak jmilou.ishak
2f06927550 fix: correct interval for fetching sensor data to every 5 seconds 2024-12-20 14:10:14 +01:00
ishak jmilou.ishak
5dbbad5fff refactor data display to use table rows for sensor data 2024-12-20 14:08:45 +01:00
ishak jmilou.ishak
bc5f52922b removed image for now 2024-12-19 22:04:58 +01:00
ishak jmilou.ishak
52eff9ec39 return JSON response for /data endpoint 2024-12-19 22:02:36 +01:00
ishak jmilou.ishak
cf1350a3c0 zeker weten dat data word gestuurd 2024-12-19 21:55:51 +01:00
ishak jmilou.ishak
fa1aa6965d updated cmakelist 2024-12-19 20:31:50 +01:00
ishak jmilou.ishak
c5981f763b fixed error 2024-12-19 20:30:55 +01:00
ishak jmilou.ishak
45247b5574 added code from main branch 2024-12-19 20:22:43 +01:00
ishak jmilou.ishak
d8ce5de8f7 removed try catch 2024-12-19 20:05:48 +01:00
ishak jmilou.ishak
a6b1c04ea3 returned global variables 2024-12-19 20:03:36 +01:00
ishak jmilou.ishak
9cd6d3aa79 removed variable 2024-12-19 20:01:09 +01:00
ishak jmilou.ishak
810309c37d front to see if data is correct 2024-12-18 12:45:25 +01:00
ishak jmilou.ishak
ddeeb379cf fixed error from braces 2024-12-18 12:42:15 +01:00
ishak jmilou.ishak
29cfa86b5f returned try catch 2024-12-18 12:36:38 +01:00
ishak jmilou.ishak
f0b87de63d switched to older version 2024-12-18 12:30:41 +01:00
ishak jmilou.ishak
1ecd474ca1 switched to this branch 2024-12-18 12:28:59 +01:00
ishak jmilou.ishak
61651a9a02 try to see why sensor value doesnt show on website 2024-12-18 12:22:22 +01:00
ishak jmilou.ishak
e5881f1b37 making message print only once 2024-12-18 11:56:43 +01:00
50b6b83299 fix headerfile 2024-12-17 11:19:15 -04:00
10597ba37d avoid busy waiting 2024-12-17 11:17:25 -04:00
ishak jmilou.ishak
072b54af04 added kobuki_message 2024-12-17 15:49:32 +01:00
ishak jmilou.ishak
e0560d7162 changed mqtt port 2024-12-17 15:43:05 +01:00
ishak jmilou.ishak
b1d5e8548c got code from other branch 2024-12-17 15:26:19 +01:00
ishak jmilou.ishak
4da91f22ca changed 2024-12-17 15:03:21 +01:00
ishak jmilou.ishak
c4d2888fbf changed order 2024-12-17 14:58:31 +01:00
ishak jmilou.ishak
4307d0a8d5 test if i still get error 2024-12-17 14:57:01 +01:00
ishak jmilou.ishak
12c4e63022 test 2024-12-17 14:48:39 +01:00
ishak jmilou.ishak
9ea6ed5e2d removed in /move 2024-12-17 14:43:13 +01:00
ishak jmilou.ishak
92992288b5 returned function i removed by accident 2024-12-17 14:41:13 +01:00
ishak jmilou.ishak
ef572c6539 made function for db connection 2024-12-17 14:38:16 +01:00
ishak jmilou.ishak
10a7a2b98c add direction to db when pressed button 2024-12-17 14:08:42 +01:00
ishak jmilou.ishak
651dcbc6a5 see if connection is actually made 2024-12-17 14:01:15 +01:00
ishak jmilou.ishak
3c3f8b93db changed data i want to execute 2024-12-17 13:58:18 +01:00
ishak jmilou.ishak
d6c3383ef0 check to see if website is updated 2024-12-17 13:44:35 +01:00
ishak jmilou.ishak
df6a49bbaa test to get db info 2024-12-17 13:42:14 +01:00
ishak jmilou.ishak
c0186f935d start verslag 2024-12-17 13:37:16 +01:00
6ab5716797 Documentation kobuki, mqtt, opencv 2024-12-13 18:33:24 +01:00
50b90e461f gitignore update 2024-12-13 10:52:53 +01:00
2811036595 change port of mqtt flask 2024-12-12 14:01:39 +01:00
ishak jmilou.ishak
869f320446 fixed typo 2024-12-12 14:01:35 +01:00
ishak jmilou.ishak
820cb39781 changed mysql package 2024-12-12 14:00:26 +01:00
58f1a931a6 Merge branch 'OpenCV' into 'main'
Open cv

See merge request technische-informatica-sm3/ti-projectten/rooziinuubii79!3
2024-12-12 13:48:59 +01:00
ishak jmilou.ishak
5c4a0f1e9d busy with sending command to database 2024-12-11 18:45:22 +01:00
ishak jmilou.ishak
e77aa4b2dc try to get data from database 2024-12-11 14:54:33 +01:00
ishak jmilou.ishak
b2432ab9cd removed execute to test if page works 2024-12-11 14:39:47 +01:00
ishak jmilou.ishak
93167e67f6 changed table name 2024-12-09 15:01:29 +01:00
ishak jmilou.ishak
3bb40d5929 Replace MariaDB connection with Flask-MySQLdb integration 2024-12-09 14:59:42 +01:00
ishak jmilou.ishak
9689d70104 Uncommented mariadb conn 2024-12-09 13:12:51 +01:00
ishak jmilou.ishak
01535607fc removed mariadb 2024-12-09 10:14:10 +01:00
ishak jmilou.ishak
f0637f4ba8 final etische aspecten 2024-12-09 10:13:53 +01:00
ishak jmilou.ishak
14a62c022c start van visie op etische aspecten 2024-12-07 22:11:03 +01:00
ishak jmilou.ishak
cd374dab81 rename index route to database and update response message 2024-12-05 13:40:34 +01:00
ishak jmilou.ishak
f9cb54a1cf start db connection 2024-12-04 17:46:40 +01:00
35 changed files with 884 additions and 381 deletions

1
.gitignore vendored
View File

@@ -32,3 +32,4 @@ Makefile
CMakeCache.txt
cmake_install.cmake
src/C++/OpenCV/main
.vs

View File

@@ -1,93 +1,8 @@
# TI-project
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-project.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-project/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
# TI-project - Kobuki
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
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.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Photos
![Kobuki](/docs/assets/KobukiPhoto.jpg)
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

View File

@@ -0,0 +1,51 @@
# Systemd Services
# What is a service
A service is a program or script that runs in the background and is managed by the system. Services are started at boot time and run until the system is shut down. Services can be started, stopped, and restarted by the system administrator.
# How to manage services on systemD
## Starting a service
To start a service, use the `systemctl start` command followed by the service name. For example, to start the `apache2` service, use the following command:
```bash
sudo systemctl start apache2
```
## Stopping a service
To stop a service, use the `systemctl stop` command followed by the service name. For example, to stop the `apache2` service, use the following command:
```bash
sudo systemctl stop apache2
```
## Restarting a service
To restart a service, use the `systemctl restart` command followed by the service name. For example, to restart the `apache2` service, use the following command:
```bash
sudo systemctl restart apache2
```
## Enabling a service
To enable a service to start at boot time, use the `systemctl enable` command followed by the service name. For example, to enable the `apache2` service, use the following command:
```bash
sudo systemctl enable apache2
```
## Creating a new service
To create a new service, you need to create a new service file in the `/etc/systemd/system/` directory. The service file should have a `.service` extension and contain the following sections:
### Example service file:
```bash
[Unit]
Description=FlaskApp #description of the service
After=network.target #start the service after the network is up
[Service]
User=ishak #start the service as a specific user
WorkingDirectory=/home/ishak/rooziinuubii79/src/Python/flask/web/ #working directory of the service
ExecStart=/usr/bin/gunicorn -w 3 -b 127.0.0.1:5000 app:app #command to start the service
```

View File

@@ -0,0 +1,51 @@
```mermaid
classDiagram
class CKobuki {
+enableCommands(bool commands)
+loop(void *user_data, TKobukiData &Kobuki_data)
+startCommunication(char *portname, bool CommandsEnabled, void *userDataL)
+measure()
+setLed(int led1, int led2)
+setTranslationSpeed(int mmpersec)
+setRotationSpeed(double radpersec)
+setArcSpeed(int mmpersec, int radius)
+setSound(int noteinHz, int duration)
+setPower(int value)
+goStraight(long double distance)
+forward(int speedvalue)
+doRotation(long double th)
}
class FlaskApp {
+on_message(client, message)
+get_db()
+close_db(error)
+index()
+control()
+move()
}
class MQTTClient {
+connect()
+subscribe(topic)
+getLastMessage()
+isConnected()
}
FlaskApp --> MQTTClient : uses
FlaskApp --> CKobuki : controls
class RPI {
+KobukiCommunication()
+ESP32Communication()
+Camera()
}
class ESP32 {
+TVOC()
+DHT11()
}
RPI --> MQTTClient : communicates
MQTTClient --> CKobuki : communicates
RPI --> ESP32 : communicates

BIN
docs/assets/KobukiPhoto.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 KiB

50
docs/code/Mqtt.md Normal file
View 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);
}
```

View File

@@ -1,20 +1,69 @@
# OpenCV
## 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
* OpenCL not grabbing gpu
* Solution: https://github.com/Smorodov/Multitarget-tracker/issues/93
## Installation
### Dependencies
* glew
* opencv
* glew (for openGL)
* 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
* https://github.com/UnaNancyOwen/OpenCVDNNSample/tree/master

View 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

View File

@@ -0,0 +1 @@
# retro sprint 4

View File

@@ -68,58 +68,47 @@ int CKobuki::connect(char *comportT) {
HCom = open(comportT, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (HCom == -1) {
printf("Kobuki nepripojeny\n");
std::cerr <<"unable to connect. retry in 1 second" << std::endl;
return HCom;
} else {
set_interface_attribs2(HCom, B115200,
0); // set speed to 115,200 bps, 8n1 (no parity)
set_interface_attribs2(HCom, B115200,0); // set speed to 115,200 bps, 8n1 (no parity)
set_blocking2(HCom, 0); // set no blocking
/* struct termios settings;
tcgetattr(HCom, &settings);
cfsetospeed(&settings, B115200); // baud rate
settings.c_cflag &= ~PARENB; // no parity
settings.c_cflag &= ~CSTOPB; // 1 stop bit
settings.c_cflag &= ~CSIZE;
settings.c_cflag |= CS8 | CLOCAL; // 8 bits
settings.c_lflag &= ~ICANON; // canonical mode
settings.c_cc[VTIME]=1;
settings.c_oflag &= ~OPOST; // raw output
tcsetattr(HCom, TCSANOW, &settings); // apply the settings*/
tcflush(HCom, TCOFLUSH);
printf("Kobuki pripojeny\n");
std::cout<<"Kobuki connected" << std::endl;
return HCom;
}
}
bool CKobuki::isConnected() {
return (HCom != -1 && tcflush(HCom, TCOFLUSH) == 0);
}
unsigned char *CKobuki::readKobukiMessage() {
unsigned char buffer[1];
ssize_t Pocet;
buffer[0] = 0;
unsigned char *null_buffer(0);
// citame kym nezachytime zaciatok spravy
// Read until the start of the message is detected
do {
Pocet = read(HCom, buffer, 1);
} while (buffer[0] != 0xAA);
// mame zaciatok spravy (asi)
// We have the start of the message (possibly)
if (Pocet == 1 && buffer[0] == 0xAA) {
// citame dalsi byte
// Read the next byte
do {
Pocet = read(HCom, buffer, 1);
} while (Pocet != 1); // On Linux: -1, on Windows: 0
} while (Pocet != 1); // na linuxe -1 na windowse 0
// a ak je to druhy byte hlavicky
// If it is the second byte of the header
if (Pocet == 1 && buffer[0] == 0x55) {
// precitame dlzku
// Read the length
Pocet = read(HCom, buffer, 1);
// ReadFile(hCom, buffer, 1, &Pocet, NULL);
if (Pocet == 1) {
// mame dlzku.. nastavime vektor a precitame ho cely
// We have the length; initialize a buffer and read the entire message
int readLenght = buffer[0];
unsigned char *outputBuffer =
(unsigned char *)calloc(readLenght + 4, sizeof(char));
@@ -134,7 +123,7 @@ unsigned char *CKobuki::readKobukiMessage() {
pct = pct + (Pocet == -1 ? 0 : Pocet);
} while (pct != (readLenght + 1));
// tu si mozeme ceknut co chodi zo serial intefejsu Kobukiho
// Here we can check what data is received from the Kobuki's serial interface
// for(int i=0;i<outputBuffer[0]+2;i++)
// {
// printf("%x ",outputBuffer[i]);
@@ -162,8 +151,8 @@ void CKobuki::setLed(int led1, int led2) {
pocet = write(HCom, &message, 8);
}
// tato funkcia nema moc sama o sebe vyznam, payload o tom, ze maju byt externe
// napajania aktivne musi byt aj tak v kazdej sprave...
// this function doesn't have much meaning by itself, the payload about them being external
// power supplies must be active in every message anyway...
void CKobuki::setPower(int value) {
if (value == 1) {
unsigned char message[8] = {0xaa, 0x55, 0x04, 0x0C, 0x02, 0xf0, 0x00, 0xAF};
@@ -251,7 +240,7 @@ void CKobuki::setSound(int noteinHz, int duration) {
void CKobuki::startCommunication(char *portname, bool CommandsEnabled,
void *userDataL) {
connect(portname);
if(connect(portname) != -1){
enableCommands(CommandsEnabled);
userData = userDataL;
@@ -262,18 +251,19 @@ void CKobuki::startCommunication(char *portname, bool CommandsEnabled,
std::cerr << "Error creating thread: " << pthread_result << std::endl;
}
}
}
int CKobuki::measure() {
while (stopVlakno == 0) {
unsigned char *message = readKobukiMessage();
if (message == NULL) {
// printf("vratil null message\n");
continue;
// printf("returned null message\n");
continue;
}
int ok = parser.parseKobukiMessage(parser.data, message);
// maximalne moze trvat callback funkcia 20 ms, ak by trvala viac, nestihame
// citat
// the maximum callback function can take 20 ms, if it takes longer, we won't be able to do it
// read
if (ok == 0) {
loop(userData, parser.data);
}
@@ -353,7 +343,7 @@ long CKobuki::loop(void *user_data, TKobukiData &Kobuki_data) {
totalLeft += dLeft;
totalRight += dRight;
// ak je suma novej a predchadzajucej vacsia ako 65536 tak to pretieklo?
// if the sum of the new and previous is greater than 65536 then it overflowed?
directionL = (prevLeftEncoder < Kobuki_data.EncoderLeft ? 1 : -1);
directionR = (prevRightEncoder < Kobuki_data.EncoderRight ? 1 : -1);
dTimestamp = (Kobuki_data.timestamp < prevTimestamp
@@ -387,7 +377,7 @@ long CKobuki::loop(void *user_data, TKobukiData &Kobuki_data) {
// tells the kobuki to go a few meters forward or backward, the sign decides
// the function compensates for walking straight with the controller, internally
// it uses setArcSpeed and uses encoder data as feedback
// it uses setArcSpeed and uses encoder data as feedback
void CKobuki::goStraight(long double distance) {
long double u_translation =
0; // controlled magnitude, speed of the robot in motion
@@ -576,7 +566,7 @@ void CKobuki::robotSafety(std::string *pointerToMessage) {
parser.data.CliffCenter || parser.data.CliffRight) {
std::cout << "Safety condition triggered!" << std::endl; // Debug print
*pointerToMessage = "estop";
forward(-100); // reverse the robot
forward(-300); // reverse the robot
}
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(100)));
}
@@ -590,8 +580,10 @@ void CKobuki::robotSafety() {
parser.data.BumperRight || parser.data.CliffLeft ||
parser.data.CliffCenter || parser.data.CliffRight) {
std::cout << "Safety condition triggered!" << std::endl; // Debug print
forward(-100); // reverse the robot
forward(-300); // reverse the robot
}
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(100)));
}
}

View File

@@ -79,6 +79,7 @@ public:
void robotSafety(); //overload
void sendNullMessage();
bool safetyActive = false;
bool isConnected();
KobukiParser parser;

View File

@@ -2,6 +2,8 @@
#include <iostream>
//moet checkenvalue gebruiken of moet kijken naar de payloadlength welke dingen er extra zijn
int KobukiParser::parseKobukiMessage(TKobukiData &output, unsigned char *data) {
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(20))); //avoid busy waiting. The kobuki sends a message every 20ms
int rtrnvalue = checkChecksum(data);
if (rtrnvalue != 0) {
// std::cerr << "Invalid checksum" << std::endl;

View File

@@ -2,6 +2,8 @@
#define KOBUKIPARSER_H
#include <vector>
#include <thread>
struct TRawGyroData {
int x, y, z;

View File

@@ -37,7 +37,6 @@ void MqttClient::subscribe(const std::string& topic, int qos) {
void MqttClient::publishMessage(const std::string& topic, const std::string& payload) {
try {
std::cout << "Publishing message: " << payload << std::endl;
client_.publish(topic, payload)->wait();
} catch (const mqtt::exception& exc) {
std::cerr << "Error: " << exc.what() << std::endl;

View File

@@ -1,5 +1,4 @@
#include <iostream>
#include <cmath>
#include <thread>
#include "MQTT/MqttClient.h"
#include "KobukiDriver/CKobuki.h"
@@ -9,6 +8,7 @@
using namespace std;
using namespace cv;
CKobuki robot;
std::string readMQTT();
void parseMQTT(std::string message);
void CapnSend();
@@ -36,7 +36,11 @@ int main()
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
while(true){
parseMQTT(readMQTT());
std::string message = readMQTT();
if (!message.empty()){
parseMQTT(message);
}
}
sendMqtt.join();
@@ -46,233 +50,279 @@ int main()
std::string readMQTT()
{
message = client.getLastMessage();
if (!message.empty())
static std::string lastMessage;
std::string message = client.getLastMessage();
if (!message.empty() && message != lastMessage)
{
std::cout << "MQTT Message: " << message << std::endl;
lastMessage = message;
}
// Add a small delay to avoid busy-waiting
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return message;
// Add a small delay to avoid busy-waiting
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return lastMessage;
}
void parseMQTT(std::string message)
{
if (message == "up")
{
robot.forward(350);
}
else if (message == "left")
{
robot.setRotationSpeed(4);
}
else if (message == "right")
{
robot.setRotationSpeed(-4);
}
else if (message == "down")
{
robot.forward(-350);
}
else if (message == "stop")
{
robot.sendNullMessage();
robot.sendNullMessage();
}
else if (message == "estop")
{
robot.forward(-400);
}
else
{
std::cout << "Invalid command" << std::endl;
}
void parseMQTT(std::string message) {
if (message == "up") {
robot.forward(350);
} else if (message == "left") {
robot.setRotationSpeed(4);
} else if (message == "right") {
robot.setRotationSpeed(-4);
} else if (message == "down") {
robot.forward(-350);
} else if (message == "stop") {
robot.sendNullMessage();
robot.sendNullMessage();
} else if (message == "estop") {
robot.forward(-400);
} else {
std::cout << "Invalid command" << std::endl;
}
}
void logToFile()
{
while (true)
{
TKobukiData robotData = robot.parser.data;
std::ofstream outputFile("log", std::ios_base::app); // Open file in append mode to not overwrite own content
if (outputFile.is_open())
{ // check if the file was opened successfully
// Get current time
std::time_t now = std::time(nullptr);
outputFile << "Timestamp: " << std::ctime(&now);
// Write data to the file
outputFile << "analogInputCh0: " << robotData.analogInputCh0 << "\n";
outputFile << "analogInputCh1: " << robotData.analogInputCh1 << "\n";
outputFile << "analogInputCh2: " << robotData.analogInputCh2 << "\n";
outputFile << "analogInputCh3: " << robotData.analogInputCh3 << "\n";
outputFile << "digitalInput: " << robotData.digitalInput << "\n";
outputFile << "timestamp: " << robotData.timestamp << "\n";
outputFile << "BumperCenter: " << robotData.BumperCenter << "\n";
outputFile << "BumperLeft: " << robotData.BumperLeft << "\n";
outputFile << "BumperRight: " << robotData.BumperRight << "\n";
outputFile << "WheelDropLeft: " << robotData.WheelDropLeft << "\n";
outputFile << "WheelDropRight: " << robotData.WheelDropRight << "\n";
outputFile << "CliffCenter: " << robotData.CliffCenter << "\n";
outputFile << "CliffLeft: " << robotData.CliffLeft << "\n";
outputFile << "CliffRight: " << robotData.CliffRight << "\n";
outputFile << "EncoderLeft: " << robotData.EncoderLeft << "\n";
outputFile << "EncoderRight: " << robotData.EncoderRight << "\n";
outputFile << "PWMleft: " << robotData.PWMleft << "\n";
outputFile << "PWMright: " << robotData.PWMright << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress1 << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress2 << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress3 << "\n";
outputFile << "Charger: " << robotData.Charger << "\n";
outputFile << "Battery: " << robotData.Battery << "\n";
outputFile << "overCurrent: " << robotData.overCurrent << "\n";
outputFile << "IRSensorRight: " << robotData.IRSensorRight << "\n";
outputFile << "IRSensorCenter: " << robotData.IRSensorCenter << "\n";
outputFile << "IRSensorLeft: " << robotData.IRSensorLeft << "\n";
outputFile << "GyroAngle: " << robotData.GyroAngle << "\n";
outputFile << "GyroAngleRate: " << robotData.GyroAngleRate << "\n";
outputFile << "CliffSensorRight: " << robotData.CliffSensorRight << "\n";
outputFile << "CliffSensorCenter: " << robotData.CliffSensorCenter << "\n";
outputFile << "CliffSensorLeft: " << robotData.CliffSensorLeft << "\n";
outputFile << "wheelCurrentLeft: " << robotData.wheelCurrentLeft << "\n";
outputFile << "wheelCurrentRight: " << robotData.wheelCurrentRight << "\n";
outputFile << "frameId: " << robotData.frameId << "\n";
outputFile << "HardwareVersionPatch: " << robotData.extraInfo.HardwareVersionPatch << "\n";
outputFile << "HardwareVersionMinor: " << robotData.extraInfo.HardwareVersionMinor << "\n";
outputFile << "HardwareVersionMajor: " << robotData.extraInfo.HardwareVersionMajor << "\n";
outputFile << "FirmwareVersionPatch: " << robotData.extraInfo.FirmwareVersionPatch << "\n";
outputFile << "FirmwareVersionMinor: " << robotData.extraInfo.FirmwareVersionMinor << "\n";
outputFile << "FirmwareVersionMajor: " << robotData.extraInfo.FirmwareVersionMajor << "\n";
outputFile << "UDID0: " << robotData.extraInfo.UDID0 << "\n";
outputFile << "UDID1: " << robotData.extraInfo.UDID1 << "\n";
outputFile << "UDID2: " << robotData.extraInfo.UDID2 << "\n";
outputFile.close();
}
else
{
std::cerr << "Error opening file\n";
}
std::this_thread::sleep_for(std::chrono::seconds(2)); // Sleep for 2 seconds
void logToFile() {
while (true) {
TKobukiData robotData = robot.parser.data;
std::ofstream outputFile("log",
std::ios_base::app); // Open file in append mode to
// not overwrite own content
if (outputFile.is_open()) { // check if the file was opened successfully
// Get current time
std::time_t now = std::time(nullptr);
outputFile << "Timestamp: " << std::ctime(&now);
// Write data to the file
outputFile << "analogInputCh0: " << robotData.analogInputCh0 << "\n";
outputFile << "analogInputCh1: " << robotData.analogInputCh1 << "\n";
outputFile << "analogInputCh2: " << robotData.analogInputCh2 << "\n";
outputFile << "analogInputCh3: " << robotData.analogInputCh3 << "\n";
outputFile << "digitalInput: " << robotData.digitalInput << "\n";
outputFile << "timestamp: " << robotData.timestamp << "\n";
outputFile << "BumperCenter: " << robotData.BumperCenter << "\n";
outputFile << "BumperLeft: " << robotData.BumperLeft << "\n";
outputFile << "BumperRight: " << robotData.BumperRight << "\n";
outputFile << "WheelDropLeft: " << robotData.WheelDropLeft << "\n";
outputFile << "WheelDropRight: " << robotData.WheelDropRight << "\n";
outputFile << "CliffCenter: " << robotData.CliffCenter << "\n";
outputFile << "CliffLeft: " << robotData.CliffLeft << "\n";
outputFile << "CliffRight: " << robotData.CliffRight << "\n";
outputFile << "EncoderLeft: " << robotData.EncoderLeft << "\n";
outputFile << "EncoderRight: " << robotData.EncoderRight << "\n";
outputFile << "PWMleft: " << robotData.PWMleft << "\n";
outputFile << "PWMright: " << robotData.PWMright << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress1 << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress2 << "\n";
outputFile << "ButtonPress: " << robotData.ButtonPress3 << "\n";
outputFile << "Charger: " << robotData.Charger << "\n";
outputFile << "Battery: " << robotData.Battery << "\n";
outputFile << "overCurrent: " << robotData.overCurrent << "\n";
outputFile << "IRSensorRight: " << robotData.IRSensorRight << "\n";
outputFile << "IRSensorCenter: " << robotData.IRSensorCenter << "\n";
outputFile << "IRSensorLeft: " << robotData.IRSensorLeft << "\n";
outputFile << "GyroAngle: " << robotData.GyroAngle << "\n";
outputFile << "GyroAngleRate: " << robotData.GyroAngleRate << "\n";
outputFile << "CliffSensorRight: " << robotData.CliffSensorRight << "\n";
outputFile << "CliffSensorCenter: " << robotData.CliffSensorCenter
<< "\n";
outputFile << "CliffSensorLeft: " << robotData.CliffSensorLeft << "\n";
outputFile << "wheelCurrentLeft: " << robotData.wheelCurrentLeft << "\n";
outputFile << "wheelCurrentRight: " << robotData.wheelCurrentRight
<< "\n";
outputFile << "frameId: " << robotData.frameId << "\n";
outputFile << "HardwareVersionPatch: "
<< robotData.extraInfo.HardwareVersionPatch << "\n";
outputFile << "HardwareVersionMinor: "
<< robotData.extraInfo.HardwareVersionMinor << "\n";
outputFile << "HardwareVersionMajor: "
<< robotData.extraInfo.HardwareVersionMajor << "\n";
outputFile << "FirmwareVersionPatch: "
<< robotData.extraInfo.FirmwareVersionPatch << "\n";
outputFile << "FirmwareVersionMinor: "
<< robotData.extraInfo.FirmwareVersionMinor << "\n";
outputFile << "FirmwareVersionMajor: "
<< robotData.extraInfo.FirmwareVersionMajor << "\n";
outputFile << "UDID0: " << robotData.extraInfo.UDID0 << "\n";
outputFile << "UDID1: " << robotData.extraInfo.UDID1 << "\n";
outputFile << "UDID2: " << robotData.extraInfo.UDID2 << "\n";
outputFile.close();
} else {
std::cerr << "Error opening file\n";
}
std::this_thread::sleep_for(std::chrono::seconds(2)); // Sleep for 2 seconds
}
}
void sendIndividualKobukiData(const TKobukiData &data) {
while (true) {
client.publishMessage("kobuki/data/timestamp", std::to_string(data.timestamp));
client.publishMessage("kobuki/data/BumperCenter", std::to_string(data.BumperCenter));
client.publishMessage("kobuki/data/BumperLeft", std::to_string(data.BumperLeft));
client.publishMessage("kobuki/data/BumperRight", std::to_string(data.BumperRight));
client.publishMessage("kobuki/data/WheelDropLeft", std::to_string(data.WheelDropLeft));
client.publishMessage("kobuki/data/WheelDropRight", std::to_string(data.WheelDropRight));
client.publishMessage("kobuki/data/CliffCenter", std::to_string(data.CliffCenter));
client.publishMessage("kobuki/data/CliffLeft", std::to_string(data.CliffLeft));
client.publishMessage("kobuki/data/CliffRight", std::to_string(data.CliffRight));
client.publishMessage("kobuki/data/EncoderLeft", std::to_string(data.EncoderLeft));
client.publishMessage("kobuki/data/EncoderRight", std::to_string(data.EncoderRight));
client.publishMessage("kobuki/data/PWMleft", std::to_string(data.PWMleft));
client.publishMessage("kobuki/data/PWMright", std::to_string(data.PWMright));
client.publishMessage("kobuki/data/ButtonPress1", std::to_string(data.ButtonPress1));
client.publishMessage("kobuki/data/ButtonPress2", std::to_string(data.ButtonPress2));
client.publishMessage("kobuki/data/ButtonPress3", std::to_string(data.ButtonPress3));
client.publishMessage("kobuki/data/Charger", std::to_string(data.Charger));
client.publishMessage("kobuki/data/Battery", std::to_string(data.Battery));
client.publishMessage("kobuki/data/overCurrent", std::to_string(data.overCurrent));
client.publishMessage("kobuki/data/IRSensorRight", std::to_string(data.IRSensorRight));
client.publishMessage("kobuki/data/IRSensorCenter", std::to_string(data.IRSensorCenter));
client.publishMessage("kobuki/data/IRSensorLeft", std::to_string(data.IRSensorLeft));
client.publishMessage("kobuki/data/GyroAngle", std::to_string(data.GyroAngle));
client.publishMessage("kobuki/data/GyroAngleRate", std::to_string(data.GyroAngleRate));
client.publishMessage("kobuki/data/CliffSensorRight", std::to_string(data.CliffSensorRight));
client.publishMessage("kobuki/data/CliffSensorCenter", std::to_string(data.CliffSensorCenter));
client.publishMessage("kobuki/data/CliffSensorLeft", std::to_string(data.CliffSensorLeft));
client.publishMessage("kobuki/data/wheelCurrentLeft", std::to_string(data.wheelCurrentLeft));
client.publishMessage("kobuki/data/wheelCurrentRight", std::to_string(data.wheelCurrentRight));
client.publishMessage("kobuki/data/digitalInput", std::to_string(data.digitalInput));
client.publishMessage("kobuki/data/analogInputCh0", std::to_string(data.analogInputCh0));
client.publishMessage("kobuki/data/analogInputCh1", std::to_string(data.analogInputCh1));
client.publishMessage("kobuki/data/analogInputCh2", std::to_string(data.analogInputCh2));
client.publishMessage("kobuki/data/analogInputCh3", std::to_string(data.analogInputCh3));
client.publishMessage("kobuki/data/frameId", std::to_string(data.frameId));
client.publishMessage("kobuki/data/extraInfo/HardwareVersionPatch", std::to_string(data.extraInfo.HardwareVersionPatch));
client.publishMessage("kobuki/data/extraInfo/HardwareVersionMinor", std::to_string(data.extraInfo.HardwareVersionMinor));
client.publishMessage("kobuki/data/extraInfo/HardwareVersionMajor", std::to_string(data.extraInfo.HardwareVersionMajor));
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionPatch", std::to_string(data.extraInfo.FirmwareVersionPatch));
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionMinor", std::to_string(data.extraInfo.FirmwareVersionMinor));
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionMajor", std::to_string(data.extraInfo.FirmwareVersionMajor));
client.publishMessage("kobuki/data/extraInfo/UDID0", std::to_string(data.extraInfo.UDID0));
client.publishMessage("kobuki/data/extraInfo/UDID1", std::to_string(data.extraInfo.UDID1));
client.publishMessage("kobuki/data/extraInfo/UDID2", std::to_string(data.extraInfo.UDID2));
while (true) {
std::cout << "Kobuki Data wordt gepubliceerd naar kobuki/data/timestamp: "
<< data.timestamp << std::endl;
client.publishMessage("kobuki/data/timestamp",
std::to_string(data.timestamp));
client.publishMessage("kobuki/data/BumperCenter",
std::to_string(data.BumperCenter));
client.publishMessage("kobuki/data/BumperLeft",
std::to_string(data.BumperLeft));
client.publishMessage("kobuki/data/BumperRight",
std::to_string(data.BumperRight));
client.publishMessage("kobuki/data/WheelDropLeft",
std::to_string(data.WheelDropLeft));
client.publishMessage("kobuki/data/WheelDropRight",
std::to_string(data.WheelDropRight));
client.publishMessage("kobuki/data/CliffCenter",
std::to_string(data.CliffCenter));
client.publishMessage("kobuki/data/CliffLeft",
std::to_string(data.CliffLeft));
client.publishMessage("kobuki/data/CliffRight",
std::to_string(data.CliffRight));
client.publishMessage("kobuki/data/EncoderLeft",
std::to_string(data.EncoderLeft));
client.publishMessage("kobuki/data/EncoderRight",
std::to_string(data.EncoderRight));
client.publishMessage("kobuki/data/PWMleft", std::to_string(data.PWMleft));
client.publishMessage("kobuki/data/PWMright",
std::to_string(data.PWMright));
client.publishMessage("kobuki/data/ButtonPress1",
std::to_string(data.ButtonPress1));
client.publishMessage("kobuki/data/ButtonPress2",
std::to_string(data.ButtonPress2));
client.publishMessage("kobuki/data/ButtonPress3",
std::to_string(data.ButtonPress3));
client.publishMessage("kobuki/data/Charger", std::to_string(data.Charger));
client.publishMessage("kobuki/data/Battery", std::to_string(data.Battery));
client.publishMessage("kobuki/data/overCurrent",
std::to_string(data.overCurrent));
client.publishMessage("kobuki/data/IRSensorRight",
std::to_string(data.IRSensorRight));
client.publishMessage("kobuki/data/IRSensorCenter",
std::to_string(data.IRSensorCenter));
client.publishMessage("kobuki/data/IRSensorLeft",
std::to_string(data.IRSensorLeft));
client.publishMessage("kobuki/data/GyroAngle",
std::to_string(data.GyroAngle));
client.publishMessage("kobuki/data/GyroAngleRate",
std::to_string(data.GyroAngleRate));
client.publishMessage("kobuki/data/CliffSensorRight",
std::to_string(data.CliffSensorRight));
client.publishMessage("kobuki/data/CliffSensorCenter",
std::to_string(data.CliffSensorCenter));
client.publishMessage("kobuki/data/CliffSensorLeft",
std::to_string(data.CliffSensorLeft));
client.publishMessage("kobuki/data/wheelCurrentLeft",
std::to_string(data.wheelCurrentLeft));
client.publishMessage("kobuki/data/wheelCurrentRight",
std::to_string(data.wheelCurrentRight));
client.publishMessage("kobuki/data/digitalInput",
std::to_string(data.digitalInput));
client.publishMessage("kobuki/data/analogInputCh0",
std::to_string(data.analogInputCh0));
client.publishMessage("kobuki/data/analogInputCh1",
std::to_string(data.analogInputCh1));
client.publishMessage("kobuki/data/analogInputCh2",
std::to_string(data.analogInputCh2));
client.publishMessage("kobuki/data/analogInputCh3",
std::to_string(data.analogInputCh3));
client.publishMessage("kobuki/data/frameId", std::to_string(data.frameId));
client.publishMessage("kobuki/data/extraInfo/HardwareVersionPatch",
std::to_string(data.extraInfo.HardwareVersionPatch));
client.publishMessage("kobuki/data/extraInfo/HardwareVersionMinor",
std::to_string(data.extraInfo.HardwareVersionMinor));
client.publishMessage("kobuki/data/extraInfo/HardwareVersionMajor",
std::to_string(data.extraInfo.HardwareVersionMajor));
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionPatch",
std::to_string(data.extraInfo.FirmwareVersionPatch));
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionMinor",
std::to_string(data.extraInfo.FirmwareVersionMinor));
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionMajor",
std::to_string(data.extraInfo.FirmwareVersionMajor));
client.publishMessage("kobuki/data/extraInfo/UDID0",
std::to_string(data.extraInfo.UDID0));
client.publishMessage("kobuki/data/extraInfo/UDID1",
std::to_string(data.extraInfo.UDID1));
client.publishMessage("kobuki/data/extraInfo/UDID2",
std::to_string(data.extraInfo.UDID2));
if (!data.gyroData.empty()) {
const auto& latestGyro = data.gyroData.back();
client.publishMessage("kobuki/data/gyroData/x", std::to_string(latestGyro.x));
client.publishMessage("kobuki/data/gyroData/y", std::to_string(latestGyro.y));
client.publishMessage("kobuki/data/gyroData/z", std::to_string(latestGyro.z));
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
if (!data.gyroData.empty()) {
const auto &latestGyro = data.gyroData.back();
client.publishMessage("kobuki/data/gyroData/x",
std::to_string(latestGyro.x));
client.publishMessage("kobuki/data/gyroData/y",
std::to_string(latestGyro.y));
client.publishMessage("kobuki/data/gyroData/z",
std::to_string(latestGyro.z));
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
std::string serializeKobukiData(const TKobukiData &data) {
std::string json = "{\"timestamp\":" + std::to_string(data.timestamp) +
",\"BumperCenter\":" + std::to_string(data.BumperCenter) +
",\"BumperLeft\":" + std::to_string(data.BumperLeft) +
",\"BumperRight\":" + std::to_string(data.BumperRight) +
",\"WheelDropLeft\":" + std::to_string(data.WheelDropLeft) +
",\"WheelDropRight\":" + std::to_string(data.WheelDropRight) +
",\"CliffCenter\":" + std::to_string(data.CliffCenter) +
",\"CliffLeft\":" + std::to_string(data.CliffLeft) +
",\"CliffRight\":" + std::to_string(data.CliffRight) +
",\"EncoderLeft\":" + std::to_string(data.EncoderLeft) +
",\"EncoderRight\":" + std::to_string(data.EncoderRight) +
",\"PWMleft\":" + std::to_string(data.PWMleft) +
",\"PWMright\":" + std::to_string(data.PWMright) +
",\"ButtonPress1\":" + std::to_string(data.ButtonPress1) +
",\"ButtonPress2\":" + std::to_string(data.ButtonPress2) +
",\"ButtonPress3\":" + std::to_string(data.ButtonPress3) +
",\"Charger\":" + std::to_string(data.Charger) +
",\"Battery\":" + std::to_string(data.Battery) +
",\"overCurrent\":" + std::to_string(data.overCurrent) +
",\"IRSensorRight\":" + std::to_string(data.IRSensorRight) +
",\"IRSensorCenter\":" + std::to_string(data.IRSensorCenter) +
",\"IRSensorLeft\":" + std::to_string(data.IRSensorLeft) +
",\"GyroAngle\":" + std::to_string(data.GyroAngle) +
",\"GyroAngleRate\":" + std::to_string(data.GyroAngleRate) +
",\"CliffSensorRight\":" + std::to_string(data.CliffSensorRight) +
",\"CliffSensorCenter\":" + std::to_string(data.CliffSensorCenter) +
",\"CliffSensorLeft\":" + std::to_string(data.CliffSensorLeft) +
",\"wheelCurrentLeft\":" + std::to_string(data.wheelCurrentLeft) +
",\"wheelCurrentRight\":" + std::to_string(data.wheelCurrentRight) +
",\"digitalInput\":" + std::to_string(data.digitalInput) +
",\"analogInputCh0\":" + std::to_string(data.analogInputCh0) +
",\"analogInputCh1\":" + std::to_string(data.analogInputCh1) +
",\"analogInputCh2\":" + std::to_string(data.analogInputCh2) +
",\"analogInputCh3\":" + std::to_string(data.analogInputCh3) +
",\"frameId\":" + std::to_string(data.frameId) +
",\"extraInfo\":{\"HardwareVersionPatch\":" + std::to_string(data.extraInfo.HardwareVersionPatch) +
",\"HardwareVersionMinor\":" + std::to_string(data.extraInfo.HardwareVersionMinor) +
",\"HardwareVersionMajor\":" + std::to_string(data.extraInfo.HardwareVersionMajor) +
",\"FirmwareVersionPatch\":" + std::to_string(data.extraInfo.FirmwareVersionPatch) +
",\"FirmwareVersionMinor\":" + std::to_string(data.extraInfo.FirmwareVersionMinor) +
",\"FirmwareVersionMajor\":" + std::to_string(data.extraInfo.FirmwareVersionMajor) +
",\"UDID0\":" + std::to_string(data.extraInfo.UDID0) +
",\"UDID1\":" + std::to_string(data.extraInfo.UDID1) +
",\"UDID2\":" + std::to_string(data.extraInfo.UDID2) + "},\"gyroData\":[";
std::string json =
"{\"timestamp\":" + std::to_string(data.timestamp) +
",\"BumperCenter\":" + std::to_string(data.BumperCenter) +
",\"BumperLeft\":" + std::to_string(data.BumperLeft) +
",\"BumperRight\":" + std::to_string(data.BumperRight) +
",\"WheelDropLeft\":" + std::to_string(data.WheelDropLeft) +
",\"WheelDropRight\":" + std::to_string(data.WheelDropRight) +
",\"CliffCenter\":" + std::to_string(data.CliffCenter) +
",\"CliffLeft\":" + std::to_string(data.CliffLeft) +
",\"CliffRight\":" + std::to_string(data.CliffRight) +
",\"EncoderLeft\":" + std::to_string(data.EncoderLeft) +
",\"EncoderRight\":" + std::to_string(data.EncoderRight) +
",\"PWMleft\":" + std::to_string(data.PWMleft) +
",\"PWMright\":" + std::to_string(data.PWMright) +
",\"ButtonPress1\":" + std::to_string(data.ButtonPress1) +
",\"ButtonPress2\":" + std::to_string(data.ButtonPress2) +
",\"ButtonPress3\":" + std::to_string(data.ButtonPress3) +
",\"Charger\":" + std::to_string(data.Charger) +
",\"Battery\":" + std::to_string(data.Battery) +
",\"overCurrent\":" + std::to_string(data.overCurrent) +
",\"IRSensorRight\":" + std::to_string(data.IRSensorRight) +
",\"IRSensorCenter\":" + std::to_string(data.IRSensorCenter) +
",\"IRSensorLeft\":" + std::to_string(data.IRSensorLeft) +
",\"GyroAngle\":" + std::to_string(data.GyroAngle) +
",\"GyroAngleRate\":" + std::to_string(data.GyroAngleRate) +
",\"CliffSensorRight\":" + std::to_string(data.CliffSensorRight) +
",\"CliffSensorCenter\":" + std::to_string(data.CliffSensorCenter) +
",\"CliffSensorLeft\":" + std::to_string(data.CliffSensorLeft) +
",\"wheelCurrentLeft\":" + std::to_string(data.wheelCurrentLeft) +
",\"wheelCurrentRight\":" + std::to_string(data.wheelCurrentRight) +
",\"digitalInput\":" + std::to_string(data.digitalInput) +
",\"analogInputCh0\":" + std::to_string(data.analogInputCh0) +
",\"analogInputCh1\":" + std::to_string(data.analogInputCh1) +
",\"analogInputCh2\":" + std::to_string(data.analogInputCh2) +
",\"analogInputCh3\":" + std::to_string(data.analogInputCh3) +
",\"frameId\":" + std::to_string(data.frameId) +
",\"extraInfo\":{\"HardwareVersionPatch\":" +
std::to_string(data.extraInfo.HardwareVersionPatch) +
",\"HardwareVersionMinor\":" +
std::to_string(data.extraInfo.HardwareVersionMinor) +
",\"HardwareVersionMajor\":" +
std::to_string(data.extraInfo.HardwareVersionMajor) +
",\"FirmwareVersionPatch\":" +
std::to_string(data.extraInfo.FirmwareVersionPatch) +
",\"FirmwareVersionMinor\":" +
std::to_string(data.extraInfo.FirmwareVersionMinor) +
",\"FirmwareVersionMajor\":" +
std::to_string(data.extraInfo.FirmwareVersionMajor) +
",\"UDID0\":" + std::to_string(data.extraInfo.UDID0) +
",\"UDID1\":" + std::to_string(data.extraInfo.UDID1) +
",\"UDID2\":" + std::to_string(data.extraInfo.UDID2) + "},\"gyroData\":[";
if (!data.gyroData.empty()) {
const auto& latestGyro = data.gyroData.back();
json += "{\"x\":" + std::to_string(latestGyro.x) +
",\"y\":" + std::to_string(latestGyro.y) +
",\"z\":" + std::to_string(latestGyro.z) + "}";
}
if (!data.gyroData.empty()) {
const auto &latestGyro = data.gyroData.back();
json += "{\"x\":" + std::to_string(latestGyro.x) +
",\"y\":" + std::to_string(latestGyro.y) +
",\"z\":" + std::to_string(latestGyro.z) + "}";
}
json += "]}";
return json;
json += "]}";
return json;
}
//create extra function to send the message every 100ms
//needed it so it can be threaded
// create extra function to send the message every 100ms
// needed it so it can be threaded
void sendKobukiData(TKobukiData &data) {
while (true) {
client.publishMessage("kobuki/data", serializeKobukiData(data));
@@ -305,6 +355,6 @@ void CapnSend() {
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
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // Send image every 200ms
}
}

41
src/Python/YOLO/app.py Normal file
View File

@@ -0,0 +1,41 @@
from ultralytics import YOLO
import cv2
import numpy as np
import requests
import time
model = YOLO("yolo11n.pt")
#try to fetch the image from the given url
def fetch_image(url):
try:
response = requests.get(url)
response.raise_for_status()
image_array = np.frombuffer(response.content, np.uint8)
image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
return image
except requests.RequestException as e:
print(f"Error: Could not fetch image - {e}")
return None
# URL of the photostream
url = "http://145.92.224.21/image"
while True:
frame = fetch_image(url)
if frame is None:
print("Error: Could not fetch image, retrying...")
time.sleep(1) # Wait for 1 second before retrying
continue
# Predict on the frame
results = model(frame)
# Display the results
results[0].show()
# Exit if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()

View File

@@ -0,0 +1 @@
__pycache__

View File

@@ -0,0 +1,18 @@
FROM python:3.9
WORKDIR /app
COPY . .
RUN apt-get update && apt-get install -y libgl1
RUN pip install -r requirements.txt
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
# need to use network host to connect to the host's mqtt server

View File

@@ -0,0 +1,5 @@
Flask==3.1.0
paho-mqtt==1.6.1
ultralytics==8.3.58
opencv-python-headless==4.6.0.66
numpy==1.23.4

View File

@@ -1,32 +1,103 @@
from flask import Flask, Response, request, render_template, jsonify
import paho.mqtt.client as mqtt
from ultralytics import YOLO
import cv2
import numpy as np
import threading
import mysql.connector
import json
app = Flask(__name__)
kobuki_message = "empty"
# Load a model
model = YOLO("yolo11n.pt") # pretrained YOLO11n model
kobuki_message = ""
latest_image = None
processed_image = None
yolo_results = []
# Lock for thread-safe access to shared variables
lock = threading.Lock()
# List of class names (example for COCO dataset)
yolo_classes = list(model.names.values())
def on_message(client, userdata, message):
global kobuki_message, latest_image
global kobuki_message, latest_image, processed_image, yolo_results
if message.topic == "kobuki/data":
kobuki_message = str(message.payload.decode("utf-8"))
elif message.topic == "kobuki/cam":
with lock: # Lock the shared variables between threads so they can't be accessed at the same time and you cant have half processed images
latest_image = np.frombuffer(message.payload, np.uint8)
latest_image = cv2.imdecode(latest_image, cv2.IMREAD_COLOR)
# Process the image with YOLO
results = model(latest_image)
yolo_results = []
processed_image = latest_image.copy() # Create a copy for processing
for result in results:
for box in result.boxes:
class_id = int(box.cls.item())
class_name = yolo_classes[class_id]
yolo_results.append({
"class": class_name,
"confidence": box.conf.item(),
"bbox": box.xyxy.tolist()
})
# Draw bounding box on the processed image
x1, y1, x2, y2 = map(int, box.xyxy[0])
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")
mqtt_client.connect("localhost", 80, 60)
mqtt_client.connect("localhost", 1884, 60)
mqtt_client.loop_start()
mqtt_client.subscribe("kobuki/data")
mqtt_client.subscribe("kobuki/cam")
mqtt_client.on_message = on_message # this lines needs to be under the function definition otherwise it cant 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
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
g.db = mysql.connector.connect(
host="127.0.0.1",
port=3306,
user="admin",
password="kobuki",
database="kobuki"
)
return g.db
# Sluit de database na elke request
@app.teardown_appcontext
def close_db(error):
db = g.pop('db', None)
if db is not None:
db.close()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/control', methods=["GET","POST"])
@app.route('/control', methods=["GET", "POST"])
def control():
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
return render_template('control.html')
@@ -40,10 +111,60 @@ def move():
# Verstuur de richting via MQTT
if direction:
mqtt_client.publish("home/commands", direction) # Het topic kan aangepast worden
mqtt_client.publish("home/commands", direction)
db_connection = get_db()
cursor = db_connection.cursor()
sql_command = "INSERT INTO command (command) VALUES (%s)"
cursor.execute(sql_command, (direction,))
db_connection.commit()
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):
try:
# Parse de JSON-string naar een Python-dictionary
data = json.loads(kobuki_message)
# Maak een lijst van tuples met de naam en waarde van elk veld
sensor_data_tuples = [(name, float(value)) for name, value in data.items() if isinstance(value, (int, float))]
# Extra informatie of nested data (zoals "extraInfo" of "gyroData") kun je apart verwerken
if "extraInfo" in data:
for key, value in data["extraInfo"].items():
sensor_data_tuples.append((f"extraInfo_{key}", float(value)))
if "gyroData" in data:
for i, gyro in enumerate(data["gyroData"]):
for axis, value in gyro.items():
sensor_data_tuples.append((f"gyroData_{i}_{axis}", float(value)))
# Database-insert
db = get_db()
cursor = db.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()
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():
@@ -52,19 +173,20 @@ def data():
@app.route('/image')
def image():
global latest_image
if latest_image is not None:
return Response(latest_image, mimetype='image/jpeg')
else:
return "No image available", 404
@app.route('/phpmyadmin/<path:path>')
def phpmyadmin_passthrough(path):
# Laat Apache deze route direct afhandelen
return "", 404
global processed_image
with lock: # Lock the shared variables between threads so they can't be accessed at the same time and you cant have half processed images
if processed_image is not None:
_, buffer = cv2.imencode('.jpg', processed_image)
return Response(buffer.tobytes(), mimetype='image/jpeg')
else:
return "No image available", 404
@app.route('/yolo_results', methods=['GET'])
def yolo_results_endpoint():
global yolo_results
with lock:
return jsonify(yolo_results)
if __name__ == '__main__':

View File

@@ -14,7 +14,7 @@ document.addEventListener("DOMContentLoaded", function() {
body: JSON.stringify({ direction: direction })
})
.then(response => response.json())
.then(data => {script
.then(data => {
console.log("Success:", data);
})
.catch(error => {
@@ -25,13 +25,16 @@ document.addEventListener("DOMContentLoaded", function() {
// Fetch data from the server
async function fetchData() {
const response = await fetch("/data");
const data = await response.json();
return data;
try {
const response = await fetch("/data");
const data = await response.json();
return data;
} catch (error) {
console.error("Error:", error);
}
}
// Parse the data and show it on the website
async function parseData() {
// Parse the data and show it on the website
const data = await fetchData();
const sensorDataContainer = document.getElementById("sensor-data");
sensorDataContainer.innerHTML = ""; // Clear previous data
@@ -39,7 +42,7 @@ document.addEventListener("DOMContentLoaded", function() {
for (const [key, value] of Object.entries(data)) {
const dataElement = document.createElement("p");
dataElement.textContent = `${key}: ${value}`;
sensorDataContainer.appendChild(dataElement);
sensorDataContainer.appendChild(dataElement); // Voeg het element toe aan de container
}
}
@@ -49,9 +52,10 @@ document.addEventListener("DOMContentLoaded", function() {
img.src = "/image?" + new Date().getTime(); // Add timestamp to avoid caching
}
// Fetch and display sensor data every 5 seconds
// Fetch and display sensor data every 1 second
setInterval(parseData, 1000);
// Update the image every 5 seconds
setInterval(updateImage, 200);
// Update the image every 200 milliseconds
setInterval(updateImage, 100);
});

Binary file not shown.

View File

@@ -1,7 +0,0 @@
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "/home/ishak/rooziinuubii79/src/Python/flask/web")
from app import app as application

View File

@@ -0,0 +1,13 @@
[Unit]
Description=kobukiDriver
After=network.target
[Service]
User=user1
WorkingDirectory=/home/user1/rooziinuubii79/src/C++/Driver/
ExecStart=/home/user1/rooziinuubii79/src/C++/Driver/kobuki_control
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,25 @@
# Etische aspecten van het project
## Visie op de ethische aspecten van het Kobuki-project
Etische aspecten zijn heel belangrijk in het project, al ben ik wel van mening dat je niet alles kan voorkomen en ook kan waarborgen.
## Privacy
Als je bijvoorbeeld kijkt naar het gedeelte privacy, dan is het heel moeilijk om te kijken wat je gaat doen met die gegevens. Ik ga een camera gebruiken op de robot om zo te kijken
waar de robot is en wat hij allemaal ziet. Als de robot in een brandende huis komt en dan een persoon ziet, is het wel belangrijk om die persoon goed te kunnen zien. Je zou dan niet kunnen zeggen dat je die persoon bijvoorbeeld moet vervagen, want je moet wel kunnen zien wat de status is van die persoon.
Ook is het dan belangrijk om te kijken wat je met die gegevens gaat doen, ga je ze opslaan voor eventuele later gebruik of verwijder je ze direct. Het is heel lastig te bepalen wanneer je op zo een moment privacy schendt.
## Betrouwbaarheid
Ik vind dat je de betrouwbaarheid van de robot wel moet waarborgen,
want als ik de robot in een brandend huis stuur en hij valt uit, dan kan dat heel gevaarlijk zijn voor de persoon die in dat huis zit. Daar vind ik dat je meer rekening mee moet houden dan met de privacy van de persoon. Het is de bedoeling dat de robot hulpmedewerkers gaat helpen en niet hun werk moeilijker maakt.
## Impact op hulpverleners & maatschappij
Als meerdere hulpmedewerkers de robot gaan gebruiken en het word een soort van standaard, dan is het wel belangrijk dat de robot betrouwbaar is en dat je erop kan vertrouwen. Het gaat immers om mensenlevens en dat is wel het belangrijkste. Het is uiteindelijk de bedoeling dat de robot hulpverleners zal helpen en niet hun werk lastiger moet maken. Als de robot een standaard hulpmiddel wordt moet hij wel gebruiksvriendelijk zijn en goed kunnen helpen. De robot moet ook zo goed mogelijk werken om zo de vertrouwen te behouden van de mensen. Als de robot fouten blijft maken en niet betrouwbaar is zullen minder mensen het gebruiken. Ik vind dan ook dat de gebruik van de robot heel transparant moet zijn. Hoe word de robot aangestuurd, hoe vergelijkt hij situaties en hoe hij daarmee omgaat.
Als je daar al heel duidelijk in bent bouw je al wat sneller vertrouwen van de mensen op.
Ik vind dat in dit project de ethische aspecten heel belangrijk zijn en dat je daar ook rekening mee moet houden.
Bij betrouwbaarheid en de impact die de robot kan hebben op de maatschappij en de hulpverleners moet je wel goed over nadenken.
Je werkt immers met mensenlevens en dat is wel het belangrijkste. Privacy is ook heel belangrijk, maar ik vind dat je daar wel wat soepeler mee om kan gaan.

Binary file not shown.

View File

@@ -0,0 +1,7 @@
# feedback
- schrijf altijd in je code waarvan je de library importeert. Dit is handig voor jezelf en voor anderen die je code lezen.
- Meer comments in je code zouden handig zijn om te begrijpen wat je code doet.
- Database: timestamp voor wanneer je een record toevoegt in je command.
- Kobuki sensor data ook opslaan in de database.
-

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -0,0 +1,21 @@
Motivation Letter
16/12/2024
Cognizant Digital StudioAttn. Hayo Rubingh
Subject: Internship Application Cognizant Digital Studio
Dear Mr. Rubingh,
With great enthusiasm, I am applying for the internship position at Cognizant Digital Studio in Amsterdam. As a second-year bachelors student in Technische Informatica(Computer Science) at Hogeschool Van Amsterdam, I am seeking a challenging internship where I can combine my technical skills with my passion for innovation. Cognizants focus IoT, and technology prototypes fits perfectly with my interests .
Throughout my studies, I have gained experience in software development, including Python and JavaScript, and have worked with IoT devices such as Arduino/ESP. What drives me is the opportunity to create and develop new solutions that can make life easier and more efficient. I am particularly interested in the field of IoT and the possibilities it offers for creating smart solutions. I am eager to learn more about the latest technologies and how they can be applied in real-world projects.
I am available to start in February 2025 and look forward to contributing to innovative projects.
I would be delighted to discuss my motivation and experience further in a personal interview. You can find my contact details in my CV. Thank you for considering my application. I am looking forward to hearing from you.
Yours sincerely,
Ishak Jmilou

View File

@@ -0,0 +1,64 @@
![alt text](images/image.png)
# Welke communicatieprotocol geeft de mogelijkheid om veilig en betrouwbaar te communiceren tussen IoT apparaten?
Auteur: Ishak Jmilou
Datum: 17-12-2024
---
## Inleiding
In dit verslag wordt er gekeken naar de verschillende communicatieprotocollen die gebruikt kunnen worden om veilig en betrouwbaar te communiceren tussen IoT apparaten. Er wordt gekeken naar de verschillende protocollen en de voor- en nadelen van elk protocol.
---
# Samenvatting
In dit verslag worden de communicatieprotocollen MQTT, HTTP, WebSockets en CoAP vergeleken op het gebied van veilige en betrouwbare communicatie tussen IoT-apparaten. Veilige communicatie omvat gegevensversleuteling en authenticatie, terwijl betrouwbaarheid verwijst naar het verzenden en ontvangen van gegevens zonder verlies. Op basis van deze overwegingen wordt MQTT aanbevolen voor situaties waar zowel veiligheid als betrouwbaarheid cruciaal zijn in IoT-communicatie.
## 1. Wat houdt veilige en betrouwbare communicatie tussen apparaten in?
Als je werkt met IoT-apparaten, is het belangrijk dat de communicatie tussen deze apparaten veilig en betrouwbaar is. Iot-apparaten verzamelen gegevens over de omgeving en communiceert deze tussen apparaten over het internet. Als deze communicatie niet veilig is, kunnen hackers deze gegevens onderscheppen en gebruiken(Ministerie van Algemene Zaken, 2022). Je wilt voorkomen dat hackers toegang krijgen tot gevoelige informatie zoals persoonlijke gegevens of bedrijfsgeheimen. Daarom is het belangrijk dat de communicatie tussen apparaten veilig en betrouwbaar is. Een protocol is een set regels die bepalen hoe apparaten met elkaar communiceren. Er zijn verschillende protocollen die gebruikt kunnen worden om veilig en betrouwbaar te communiceren tussen IoT-apparaten.
## 2. Welke protocollen zijn er om veilig en betrouwbaar te communiceren tussen apparaten?
Een communicatieprotocol is een set regels die bepalen hoe apparaten met elkaar communiceren(Paul Christiano, 2023). Er is voor elk project een ander protocol dat het beste past. In dit geval is het belangrijk dat de communicatie veilig en betrouwbaar is. De protocollen die ik ga vergelijken zijn MQTT, HTTP, WebSockets en CoAP. Wat belangrijk is om te onderzoeken is hoe de protocollen omgaan met veiligheid en betrouwbaarheid. Veiligheid kan worden bereikt door gegevens te versleutelen en te authenticeren. Betrouwbaarheid kan worden bereikt door gegevens te verzenden en te ontvangen zonder verlies.(Paul Christiano, 2023).
## 3. Wat zijn de voor- en nadelen van de verschillende protocollen?
![alt text](image.png)
Zoals te zien is in de tabel is CoAP minder betrouwbaar dan de andere protocollen. Dit komt, omdat CoAP gebruik maakt van UDP wat ervoor zorgt dat het sneller is maar niet betrouwbaar met de berichten die hij stuurt(Darek Fanton, 2023). Websockets is een goede protocol alleen is het niet altijd geschikt voor lichtgewicht apparaten. HTTP maakt gebruik van TCP wat betrouwbaar is, maar het nadeel van HTTP is dat het elke keer een nieuwe verbinding moet maken. Dit kan een probleem zijn als je veel berichten moet versturen. MQTT is een lichtgewicht protocol dat betrouwbaar is en verschillende niveaus van kwaliteit van de berichten ondersteunt. Het is ook mogelijk om gegevens te versleutelen en te authenticeren met MQTT. Dit maakt het een goede keuze voor veilige en betrouwbare communicatie tussen IoT-apparaten.
## 4. Conclusie
Er zijn verschillende protocollen die goed gebruikt kunnen worden voor IoT apparaten. Aangezien voor mijn project veiligheid en betrouwbaarheid op één staat heb ik gekozen voor MQTT. Dit protocol is lichtgewicht, betrouwbaar en ondersteunt verschillende niveaus van kwaliteit van de berichten. Het is ook mogelijk om gegevens te versleutelen en te authenticeren met MQTT. Dit maakt het een goede keuze voor veilige en betrouwbare communicatie tussen IoT-apparaten.
## literatuurlijst
- Singh, S., & Jyoti. (2024, June 7). Secure Communications Protocols for IoT networks: a survey. https://journal.ijprse.com/index.php/ijprse/article/view/1082
- Nguyen, K. T., Laurent, M., Oualha, N., CEA, & Institut Mines-Telecom. (2015). Survey on secure communication protocols for the Internet of Things. In Ad Hoc Networks (Vol. 32, pp. 1731) [Journal-article]. http://dx.doi.org/10.1016/j.adhoc.2015.01.006
- Miorandi, D., Sicari, S., De Pellegrini, F., & Imrich Chlamtac. (2012). Internet of things: Vision, applications and research challenges. In Ad Hoc Networks (Vol. 10, pp. 14971516) [Journal-article]. Elsevier B.V. http://dx.doi.org/10.1016/j.adhoc.2012.02.016
- Christiano, P. (2023, November 5). Top 9 IoT communication protocols & their features in 2024: An In-Depth guide - ExpertBeacon. Expertbeacon. https://expertbeacon.com/iot-communication-protocol/
- Yugha, R., & Chithra, S. (2020). A survey on technologies and security protocols: Reference for future generation IoT. Journal of Network and Computer Applications, 169, 102763. https://doi.org/10.1016/j.jnca.2020.102763
- De Mendizábal, I. (2022, June 16). IoT Communication Protocols—IoT Data Protocols. Technical Articles. https://www.allaboutcircuits.com/technical-articles/internet-of-things-communication-protocols-iot-data-protocols/
- IoT-technologieën en -protocollen | Microsoft Azure. (n.d.). https://azure.microsoft.com/nl-nl/solutions/iot/iot-technology-protocols
- Darek Fanton(2024, Juli 11). Het IoT verbinden: wat is MQTT en waarin verschilt het van CoAP? (n.d.). https://www.onlogic.com/nl/blog/het-iot-verbinden-wat-is-mqtt-en-waarin-verschilt-het-van-coap/
- Nader, K. (2023, October 30). Wat zijn de voordelen van het gebruik van WebSocket voor IoT-communicatie? AppMaster - Ultimate All-in No-code Platform. https://appmaster.io/nl/blog/websocket-voor-iot-communicatie
- Sidna, J., Amine, B., Abdallah, N., & Alami, H. E. (2020). Analysis and evaluation of communication Protocols for IoT Applications. Karbala International Journal of Modern Science. https://doi.org/10.1145/3419604.3419754
- Ministerie van Algemene Zaken. (2022, February 8). Hoe kan ik slimme apparaten veilig gebruiken? Rijksoverheid.nl. https://www.rijksoverheid.nl/onderwerpen/bescherming-van-consumenten/vraag-en-antwoord/hoe-kan-ik-slimme-apparaten-veilig-gebruiken

Binary file not shown.