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
212 Commits
Develop_te
...
2c630bf89b
Author | SHA1 | Date | |
---|---|---|---|
|
2c630bf89b | ||
|
ef3407b742 | ||
|
3d9a68ff7f | ||
|
aedff1c2cc | ||
|
c31689ac70 | ||
|
1ab718a472 | ||
bbade2384c | |||
e04cff3d65 | |||
|
36aaee9bad | ||
7b51330675 | |||
3bb44ad4ab | |||
|
fb12b20a0b | ||
|
1b3ccd1e72 | ||
|
a16abe068c | ||
|
9f7d7e7ac9 | ||
|
6f34a0f554 | ||
|
364f6e5259 | ||
7c30d838f7 | |||
|
50bf777f78 | ||
|
95e2d292c9 | ||
|
3367f1dbd2 | ||
e273e175cb | |||
06e08a2cfb | |||
|
4e78caa577 | ||
|
5b0e843654 | ||
|
8b66702605 | ||
|
d8b3ec2938 | ||
|
97076dfe05 | ||
|
967bc8247c | ||
|
5d61579973 | ||
|
ebd88e43ab | ||
|
2fbe18be76 | ||
|
74d9687af5 | ||
|
48023773c6 | ||
56ac9cf687 | |||
|
3232ff121f | ||
5844387b19 | |||
|
b48243f831 | ||
317731ec87 | |||
441ca19578 | |||
7f807d0031 | |||
c0ec6901c4 | |||
2fa8fb2926 | |||
3fddee73c7 | |||
|
06dd2d9f48 | ||
|
7d3a5fa9a3 | ||
|
3bca04053a | ||
|
82363d393c | ||
|
1964589abc | ||
|
8d339851dd | ||
|
79c2073d29 | ||
|
ffbf3347f4 | ||
|
64452b78b4 | ||
|
c87ebc565c | ||
|
39659fffab | ||
|
a4ae0170a0 | ||
|
ed475cd19f | ||
|
a9c37ec470 | ||
|
369120b16b | ||
|
ec71028270 | ||
|
7560b0f67a | ||
|
331de940cc | ||
|
ec0b32a221 | ||
|
3aa77f5314 | ||
|
e59f235b91 | ||
|
2e4f048ed9 | ||
|
9a3829cdb2 | ||
|
015b2db819 | ||
|
6ef739f794 | ||
|
ec2a08c656 | ||
|
89421ccf34 | ||
|
1c081451aa | ||
|
2396d61eae | ||
|
fa17893b1b | ||
|
07d88eef7d | ||
|
d066f68ad2 | ||
|
d90ac72591 | ||
|
a2aa80804e | ||
|
612af45f59 | ||
|
3ff1b22346 | ||
|
1a4056ff77 | ||
|
8517a0d558 | ||
|
092e4f5aeb | ||
|
9eb9822cff | ||
|
fe64267307 | ||
|
72a0fadef8 | ||
|
d0bfef2296 | ||
|
71091f57dd | ||
|
1fd88c7636 | ||
ff7b148556 | |||
|
fa85be2df5 | ||
|
4bf3cd6d37 | ||
|
361c17fbdb | ||
|
fe3fe2b8cf | ||
|
bcac062cdf | ||
|
b12e4c7539 | ||
|
a979d15a6e | ||
|
184e723379 | ||
|
2bfd11276a | ||
|
bc0b878230 | ||
|
806bb16662 | ||
|
56f085b73d | ||
|
b111e49dff | ||
6fe28f997a | |||
1bf9ebddab | |||
585a0e9a52 | |||
cb988a5260 | |||
5e01e25d9c | |||
0d184261fd | |||
ccaa722973 | |||
7d1b878c30 | |||
228c508012 | |||
7845feb9f8 | |||
20d6d8799d | |||
9c7c774030 | |||
0832da0d3b | |||
a59b9c8714 | |||
4a05ec5efc | |||
c3d575ccf1 | |||
1b0b1e87ce | |||
9c41d64c69 | |||
b48eda9735 | |||
629f9cba92 | |||
51aad34c78 | |||
|
bb1904b125 | ||
|
b29a615681 | ||
1b3fead2b3 | |||
|
1fb7010773 | ||
|
ae03800c23 | ||
|
490e0536ca | ||
|
2f06927550 | ||
|
5dbbad5fff | ||
|
bc5f52922b | ||
|
52eff9ec39 | ||
|
cf1350a3c0 | ||
|
fa1aa6965d | ||
|
c5981f763b | ||
|
45247b5574 | ||
|
d8ce5de8f7 | ||
|
a6b1c04ea3 | ||
|
9cd6d3aa79 | ||
|
810309c37d | ||
|
ddeeb379cf | ||
|
29cfa86b5f | ||
|
f0b87de63d | ||
|
1ecd474ca1 | ||
|
61651a9a02 | ||
|
e5881f1b37 | ||
50b6b83299 | |||
10597ba37d | |||
|
072b54af04 | ||
|
e0560d7162 | ||
|
b1d5e8548c | ||
|
4da91f22ca | ||
|
c4d2888fbf | ||
|
4307d0a8d5 | ||
|
12c4e63022 | ||
|
9ea6ed5e2d | ||
|
92992288b5 | ||
|
ef572c6539 | ||
|
10a7a2b98c | ||
|
651dcbc6a5 | ||
|
3c3f8b93db | ||
|
d6c3383ef0 | ||
|
df6a49bbaa | ||
|
c0186f935d | ||
6ab5716797 | |||
50b90e461f | |||
2811036595 | |||
|
869f320446 | ||
|
820cb39781 | ||
58f1a931a6 | |||
c9d3b0f795 | |||
85af15d7a3 | |||
a1b50a3780 | |||
|
5c4a0f1e9d | ||
b86528595e | |||
eef4f9c79c | |||
3c23d37be1 | |||
c2886d32c9 | |||
8158c85d6e | |||
e682969ec8 | |||
0dfc3b5c13 | |||
7f786d5197 | |||
60ba177dc2 | |||
e9f998b3e7 | |||
|
e77aa4b2dc | ||
7eeaba482e | |||
e8db00120f | |||
c65f310e81 | |||
|
b2432ab9cd | ||
ec3e83ef7f | |||
480d36393a | |||
fea0f19857 | |||
e1135dac0f | |||
|
93167e67f6 | ||
|
3bb40d5929 | ||
|
9689d70104 | ||
2f4e5ae096 | |||
|
01535607fc | ||
|
f0637f4ba8 | ||
|
14a62c022c | ||
|
cd374dab81 | ||
|
f9cb54a1cf | ||
9e07a243ea | |||
b93a5f2dca | |||
911b870786 | |||
dd39bd3021 | |||
8aa54805ac | |||
d26d277c3c | |||
508d2ed4e2 | |||
3e202acc8d |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -13,7 +13,7 @@ src/Socket/a.out
|
|||||||
src/C++/Driver/cmake_install.cmake
|
src/C++/Driver/cmake_install.cmake
|
||||||
src/C++/Socket/a.out
|
src/C++/Socket/a.out
|
||||||
src/C++/Driver/Makefile
|
src/C++/Driver/Makefile
|
||||||
src/C++/Driver/vgcore*
|
vgcore*
|
||||||
src/C++/Driver/cmake_install.cmake
|
src/C++/Driver/cmake_install.cmake
|
||||||
src/C++/Driver/Makefile
|
src/C++/Driver/Makefile
|
||||||
src/C++/Driver/log
|
src/C++/Driver/log
|
||||||
@@ -31,3 +31,5 @@ CMakeFiles/
|
|||||||
Makefile
|
Makefile
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
|
src/C++/OpenCV/main
|
||||||
|
.vs
|
135
README.md
135
README.md
@@ -1,93 +1,70 @@
|
|||||||
# TI-project
|
# TI-project - exploration robot Kobuki
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 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.
|
|
||||||
|
|
||||||
## Description
|
## 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 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.
|
||||||
|
|
||||||
## Badges
|
## Photos
|
||||||
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.
|

|
||||||
|
|
||||||
## 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
|
## 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
|
### Requirements
|
||||||
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
|
- Kobuki robot
|
||||||
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.
|
- Raspberry Pi (minimum 3B)
|
||||||
|
- Camera
|
||||||
|
- power supply for Raspberry Pi
|
||||||
|
- laptop or computer
|
||||||
|
|
||||||
## Roadmap
|
### Steps
|
||||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
||||||
|
|
||||||
## Contributing
|
1. **Install Python and Pip**
|
||||||
State if you are open to contributions and what your requirements are for accepting them.
|
- 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.
|
||||||
|
|
||||||
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.
|
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**
|
||||||
|
- Install the following packages on the server: "docker docker-buildx mosquitto nginx"
|
||||||
|
- Install the following packages on the Raspberry Pi: "g++ make cmake", https://github.com/eclipse-paho/paho.mqtt.c, https://github.com/eclipse-paho/paho.mqtt.cpp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
4. **Run the project**
|
||||||
|
|
||||||
|
#### Server side
|
||||||
|
- Run the following commands in the terminal to start the website:
|
||||||
|
- `cd src/Python/flask`
|
||||||
|
- `sudo docker buildx build -t flaskapp:latest .`
|
||||||
|
- `sudo docker run --network="host" --restart=always flaskapp:latest`
|
||||||
|
- Run the following commands in the terminal to start the MQTT broker:
|
||||||
|
- `cd src/config/server/`
|
||||||
|
- `mosquitto -c mosquitto.conf`
|
||||||
|
- Run the following commands in the terminal to start the Nginx server:
|
||||||
|
- `cd src/config/server/`
|
||||||
|
- `cp nginx.conf /etc/nginx/nginx.conf`
|
||||||
|
- `cp nginx-sites.conf /etc/nginx/sites-enable/nginx-sites.conf`
|
||||||
|
|
||||||
|
|
||||||
|
#### Raspberry Pi side
|
||||||
|
- Run the following commands to build and start the driver:
|
||||||
|
- `cd src/C++/Driver`
|
||||||
|
- `cmake ..`
|
||||||
|
- `make`
|
||||||
|
- `./kobuki_driver`
|
||||||
|
- Run the following commands to autostart the driver on startup of the Raspberry Pi:
|
||||||
|
- `cd src/config/rpi/`
|
||||||
|
- `cp kobukiDriver.service /etc/systemd/system/kobukiDriver.service`
|
||||||
|
- `systemctl enable kobukiDriver.service`
|
||||||
|
- `systemctl start kobukiDriver.service`
|
||||||
|
|
||||||
|
## Extra notes
|
||||||
|
Dont forget to change the IP address in the `src/C++/Driver/src/main.cpp` file to the IP address of the server.
|
||||||
|
|
||||||
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.
|
|
||||||
|
51
docs/Infrastructure/system-services.md
Normal file
51
docs/Infrastructure/system-services.md
Normal 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
|
||||||
|
```
|
||||||
|
|
51
docs/Infrastructure/uml.md
Normal file
51
docs/Infrastructure/uml.md
Normal 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
BIN
docs/assets/KobukiPhoto.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 491 KiB |
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);
|
||||||
|
}
|
||||||
|
```
|
69
docs/code/OpenCV.md
Normal file
69
docs/code/OpenCV.md
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# OpenCV
|
||||||
|
## Requirements
|
||||||
|
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 (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
|
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
|
1
docs/scrum/retrospective/retro_sprint_4.md
Normal file
1
docs/scrum/retrospective/retro_sprint_4.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# retro sprint 4
|
@@ -6,7 +6,10 @@ set(CMAKE_CXX_STANDARD 23)
|
|||||||
find_library(PAHO_MQTTPP_LIBRARY paho-mqttpp3 PATHS /usr/local/lib)
|
find_library(PAHO_MQTTPP_LIBRARY paho-mqttpp3 PATHS /usr/local/lib)
|
||||||
find_library(PAHO_MQTT_LIBRARY paho-mqtt3a PATHS /usr/local/lib)
|
find_library(PAHO_MQTT_LIBRARY paho-mqtt3a PATHS /usr/local/lib)
|
||||||
|
|
||||||
include_directories(/usr/local/include)
|
# Find OpenCV package
|
||||||
|
find_package(OpenCV REQUIRED)
|
||||||
|
find_package(OpenEXR REQUIRED)
|
||||||
|
include_directories(${OpenCV_INCLUDE_DIRS})
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
src/KobukiDriver/KobukiParser.cpp
|
src/KobukiDriver/KobukiParser.cpp
|
||||||
@@ -20,4 +23,4 @@ set(SOURCE_FILES
|
|||||||
add_executable(kobuki_control ${SOURCE_FILES})
|
add_executable(kobuki_control ${SOURCE_FILES})
|
||||||
|
|
||||||
# Link the static libraries
|
# Link the static libraries
|
||||||
target_link_libraries(kobuki_control ${PAHO_MQTTPP_LIBRARY} ${PAHO_MQTT_LIBRARY} pthread)
|
target_link_libraries(kobuki_control ${PAHO_MQTTPP_LIBRARY} ${PAHO_MQTT_LIBRARY} ${OpenCV_LIBS} pthread OpenEXR::OpenEXR)
|
||||||
|
@@ -68,58 +68,47 @@ int CKobuki::connect(char *comportT) {
|
|||||||
HCom = open(comportT, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
HCom = open(comportT, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||||
|
|
||||||
if (HCom == -1) {
|
if (HCom == -1) {
|
||||||
printf("Kobuki nepripojeny\n");
|
std::cerr <<"unable to connect. retry in 1 second" << std::endl;
|
||||||
return HCom;
|
return HCom;
|
||||||
} else {
|
} else {
|
||||||
set_interface_attribs2(HCom, B115200,
|
set_interface_attribs2(HCom, B115200,0); // set speed to 115,200 bps, 8n1 (no parity)
|
||||||
0); // set speed to 115,200 bps, 8n1 (no parity)
|
|
||||||
set_blocking2(HCom, 0); // set no blocking
|
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);
|
tcflush(HCom, TCOFLUSH);
|
||||||
|
|
||||||
printf("Kobuki pripojeny\n");
|
std::cout<<"Kobuki connected" << std::endl;
|
||||||
return HCom;
|
return HCom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CKobuki::isConnected() {
|
||||||
|
return (HCom != -1 && tcflush(HCom, TCOFLUSH) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char *CKobuki::readKobukiMessage() {
|
unsigned char *CKobuki::readKobukiMessage() {
|
||||||
unsigned char buffer[1];
|
unsigned char buffer[1];
|
||||||
ssize_t Pocet;
|
ssize_t Pocet;
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
unsigned char *null_buffer(0);
|
unsigned char *null_buffer(0);
|
||||||
// citame kym nezachytime zaciatok spravy
|
|
||||||
|
// Read until the start of the message is detected
|
||||||
do {
|
do {
|
||||||
Pocet = read(HCom, buffer, 1);
|
Pocet = read(HCom, buffer, 1);
|
||||||
} while (buffer[0] != 0xAA);
|
} while (buffer[0] != 0xAA);
|
||||||
// mame zaciatok spravy (asi)
|
|
||||||
|
// We have the start of the message (possibly)
|
||||||
if (Pocet == 1 && buffer[0] == 0xAA) {
|
if (Pocet == 1 && buffer[0] == 0xAA) {
|
||||||
// citame dalsi byte
|
// Read the next byte
|
||||||
do {
|
do {
|
||||||
|
|
||||||
Pocet = read(HCom, buffer, 1);
|
Pocet = read(HCom, buffer, 1);
|
||||||
|
} while (Pocet != 1); // On Linux: -1, on Windows: 0
|
||||||
|
|
||||||
} while (Pocet != 1); // na linuxe -1 na windowse 0
|
// If it is the second byte of the header
|
||||||
|
|
||||||
// a ak je to druhy byte hlavicky
|
|
||||||
if (Pocet == 1 && buffer[0] == 0x55) {
|
if (Pocet == 1 && buffer[0] == 0x55) {
|
||||||
// precitame dlzku
|
// Read the length
|
||||||
Pocet = read(HCom, buffer, 1);
|
Pocet = read(HCom, buffer, 1);
|
||||||
|
|
||||||
// ReadFile(hCom, buffer, 1, &Pocet, NULL);
|
|
||||||
if (Pocet == 1) {
|
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];
|
int readLenght = buffer[0];
|
||||||
unsigned char *outputBuffer =
|
unsigned char *outputBuffer =
|
||||||
(unsigned char *)calloc(readLenght + 4, sizeof(char));
|
(unsigned char *)calloc(readLenght + 4, sizeof(char));
|
||||||
@@ -134,7 +123,7 @@ unsigned char *CKobuki::readKobukiMessage() {
|
|||||||
pct = pct + (Pocet == -1 ? 0 : Pocet);
|
pct = pct + (Pocet == -1 ? 0 : Pocet);
|
||||||
} while (pct != (readLenght + 1));
|
} 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++)
|
// for(int i=0;i<outputBuffer[0]+2;i++)
|
||||||
// {
|
// {
|
||||||
// printf("%x ",outputBuffer[i]);
|
// printf("%x ",outputBuffer[i]);
|
||||||
@@ -162,8 +151,8 @@ void CKobuki::setLed(int led1, int led2) {
|
|||||||
pocet = write(HCom, &message, 8);
|
pocet = write(HCom, &message, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// tato funkcia nema moc sama o sebe vyznam, payload o tom, ze maju byt externe
|
// this function doesn't have much meaning by itself, the payload about them being external
|
||||||
// napajania aktivne musi byt aj tak v kazdej sprave...
|
// power supplies must be active in every message anyway...
|
||||||
void CKobuki::setPower(int value) {
|
void CKobuki::setPower(int value) {
|
||||||
if (value == 1) {
|
if (value == 1) {
|
||||||
unsigned char message[8] = {0xaa, 0x55, 0x04, 0x0C, 0x02, 0xf0, 0x00, 0xAF};
|
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 CKobuki::startCommunication(char *portname, bool CommandsEnabled,
|
||||||
void *userDataL) {
|
void *userDataL) {
|
||||||
connect(portname);
|
if(connect(portname) != -1){
|
||||||
enableCommands(CommandsEnabled);
|
enableCommands(CommandsEnabled);
|
||||||
userData = userDataL;
|
userData = userDataL;
|
||||||
|
|
||||||
@@ -262,18 +251,19 @@ void CKobuki::startCommunication(char *portname, bool CommandsEnabled,
|
|||||||
std::cerr << "Error creating thread: " << pthread_result << std::endl;
|
std::cerr << "Error creating thread: " << pthread_result << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int CKobuki::measure() {
|
int CKobuki::measure() {
|
||||||
while (stopVlakno == 0) {
|
while (stopVlakno == 0) {
|
||||||
unsigned char *message = readKobukiMessage();
|
unsigned char *message = readKobukiMessage();
|
||||||
if (message == NULL) {
|
if (message == NULL) {
|
||||||
// printf("vratil null message\n");
|
// printf("returned null message\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int ok = parser.parseKobukiMessage(parser.data, message);
|
int ok = parser.parseKobukiMessage(parser.data, message);
|
||||||
|
|
||||||
// maximalne moze trvat callback funkcia 20 ms, ak by trvala viac, nestihame
|
// the maximum callback function can take 20 ms, if it takes longer, we won't be able to do it
|
||||||
// citat
|
// read
|
||||||
if (ok == 0) {
|
if (ok == 0) {
|
||||||
loop(userData, parser.data);
|
loop(userData, parser.data);
|
||||||
}
|
}
|
||||||
@@ -353,7 +343,7 @@ long CKobuki::loop(void *user_data, TKobukiData &Kobuki_data) {
|
|||||||
totalLeft += dLeft;
|
totalLeft += dLeft;
|
||||||
totalRight += dRight;
|
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);
|
directionL = (prevLeftEncoder < Kobuki_data.EncoderLeft ? 1 : -1);
|
||||||
directionR = (prevRightEncoder < Kobuki_data.EncoderRight ? 1 : -1);
|
directionR = (prevRightEncoder < Kobuki_data.EncoderRight ? 1 : -1);
|
||||||
dTimestamp = (Kobuki_data.timestamp < prevTimestamp
|
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
|
// tells the kobuki to go a few meters forward or backward, the sign decides
|
||||||
// the function compensates for walking straight with the controller, internally
|
// 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) {
|
void CKobuki::goStraight(long double distance) {
|
||||||
long double u_translation =
|
long double u_translation =
|
||||||
0; // controlled magnitude, speed of the robot in motion
|
0; // controlled magnitude, speed of the robot in motion
|
||||||
@@ -509,32 +499,6 @@ void CKobuki::doRotation(long double th) {
|
|||||||
usleep(25 * 1000);
|
usleep(25 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// combines navigation to a coordinate and rotation by an angle, performs
|
|
||||||
// movement to the selected coordinate in the robot's coordinate system
|
|
||||||
void CKobuki::goToXy(long double xx, long double yy) {
|
|
||||||
long double th;
|
|
||||||
|
|
||||||
yy = yy * -1;
|
|
||||||
|
|
||||||
th = atan2(yy, xx);
|
|
||||||
doRotation(th);
|
|
||||||
|
|
||||||
long double s = sqrt(pow(xx, 2) + pow(yy, 2));
|
|
||||||
|
|
||||||
// resetnem suradnicovu sustavu robota
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
iterationCount = 0;
|
|
||||||
theta = 0;
|
|
||||||
|
|
||||||
// std::cout << "mam prejst: " << s << "[m]" << std::endl;
|
|
||||||
|
|
||||||
goStraight(s);
|
|
||||||
|
|
||||||
usleep(25 * 1000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Makes the robot move forward for 3 seconds
|
/// @brief Makes the robot move forward for 3 seconds
|
||||||
/// @param speedvalue How fast it will drive forward from 0 - 1024
|
/// @param speedvalue How fast it will drive forward from 0 - 1024
|
||||||
void CKobuki::forward(int speedvalue) {
|
void CKobuki::forward(int speedvalue) {
|
||||||
@@ -602,7 +566,7 @@ void CKobuki::robotSafety(std::string *pointerToMessage) {
|
|||||||
parser.data.CliffCenter || parser.data.CliffRight) {
|
parser.data.CliffCenter || parser.data.CliffRight) {
|
||||||
std::cout << "Safety condition triggered!" << std::endl; // Debug print
|
std::cout << "Safety condition triggered!" << std::endl; // Debug print
|
||||||
*pointerToMessage = "estop";
|
*pointerToMessage = "estop";
|
||||||
forward(-100); // reverse the robot
|
forward(-300); // reverse the robot
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(100)));
|
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(100)));
|
||||||
}
|
}
|
||||||
@@ -616,8 +580,10 @@ void CKobuki::robotSafety() {
|
|||||||
parser.data.BumperRight || parser.data.CliffLeft ||
|
parser.data.BumperRight || parser.data.CliffLeft ||
|
||||||
parser.data.CliffCenter || parser.data.CliffRight) {
|
parser.data.CliffCenter || parser.data.CliffRight) {
|
||||||
std::cout << "Safety condition triggered!" << std::endl; // Debug print
|
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)));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,7 +31,6 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "KobukiParser.h"
|
#include "KobukiParser.h"
|
||||||
#include "graph.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -80,6 +79,7 @@ public:
|
|||||||
void robotSafety(); //overload
|
void robotSafety(); //overload
|
||||||
void sendNullMessage();
|
void sendNullMessage();
|
||||||
bool safetyActive = false;
|
bool safetyActive = false;
|
||||||
|
bool isConnected();
|
||||||
KobukiParser parser;
|
KobukiParser parser;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
//moet checkenvalue gebruiken of moet kijken naar de payloadlength welke dingen er extra zijn
|
//moet checkenvalue gebruiken of moet kijken naar de payloadlength welke dingen er extra zijn
|
||||||
int KobukiParser::parseKobukiMessage(TKobukiData &output, unsigned char *data) {
|
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);
|
int rtrnvalue = checkChecksum(data);
|
||||||
if (rtrnvalue != 0) {
|
if (rtrnvalue != 0) {
|
||||||
// std::cerr << "Invalid checksum" << std::endl;
|
// std::cerr << "Invalid checksum" << std::endl;
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
#define KOBUKIPARSER_H
|
#define KOBUKIPARSER_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
struct TRawGyroData {
|
struct TRawGyroData {
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
@@ -1,71 +0,0 @@
|
|||||||
#ifndef GRAPH1010
|
|
||||||
#define GRAPH1010
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
#define GRAPH_ENABLED true
|
|
||||||
|
|
||||||
class plot {
|
|
||||||
public:
|
|
||||||
FILE *gp;
|
|
||||||
bool enabled,persist;
|
|
||||||
plot(bool _persist=false,bool _enabled=GRAPH_ENABLED) {
|
|
||||||
enabled=_enabled;
|
|
||||||
persist=_persist;
|
|
||||||
if (enabled) {
|
|
||||||
if(persist)
|
|
||||||
gp=popen("gnuplot -persist","w");
|
|
||||||
else
|
|
||||||
gp=popen("gnuplot","w");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void plot_data(vector<float> x,const char* style="points",const char* title="Data") {
|
|
||||||
if(!enabled)
|
|
||||||
return;
|
|
||||||
fprintf(gp,"set title '%s' \n",title);
|
|
||||||
fprintf(gp,"plot '-' w %s \n",style);
|
|
||||||
for(int k=0;k<x.size();k++) {
|
|
||||||
fprintf(gp,"%f\n",x[k]);
|
|
||||||
}
|
|
||||||
fprintf(gp,"e\n");
|
|
||||||
fflush(gp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void plot_data(vector<float> x,vector<float> y,const char* style="points",const char* title="Data") {
|
|
||||||
if(!enabled)
|
|
||||||
return;
|
|
||||||
fprintf(gp,"set title '%s' \n",title);
|
|
||||||
fprintf(gp,"plot '-' w %s \n",style);
|
|
||||||
for(int k=0;k<x.size();k++) {
|
|
||||||
fprintf(gp,"%f %f \n",x[k],y[k]);
|
|
||||||
}
|
|
||||||
fprintf(gp,"e\n");
|
|
||||||
fflush(gp);
|
|
||||||
}
|
|
||||||
|
|
||||||
~plot() {
|
|
||||||
if(enabled)
|
|
||||||
pclose(gp);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
int main(int argc,char **argv) {
|
|
||||||
plot p;
|
|
||||||
for(int a=0;a<100;a++) {
|
|
||||||
vector<float> x,y;
|
|
||||||
for(int k=a;k<a+200;k++) {
|
|
||||||
x.push_back(k);
|
|
||||||
y.push_back(k*k);
|
|
||||||
}
|
|
||||||
p.plot_data(x,y);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif
|
|
@@ -5,6 +5,7 @@ MqttClient::MqttClient(const std::string& address, const std::string& clientId,
|
|||||||
//here all the @PARAMS are getting set for the connection
|
//here all the @PARAMS are getting set for the connection
|
||||||
: client_(address, clientId), username_(username), password_(password), callback_(*this) {
|
: client_(address, clientId), username_(username), password_(password), callback_(*this) {
|
||||||
client_.set_callback(callback_);
|
client_.set_callback(callback_);
|
||||||
|
|
||||||
options.set_clean_session(true);
|
options.set_clean_session(true);
|
||||||
options.set_mqtt_version(MQTTVERSION_3_1_1); // For MQTT 3.1.1
|
options.set_mqtt_version(MQTTVERSION_3_1_1); // For MQTT 3.1.1
|
||||||
if (!username_.empty() && !password_.empty()) {
|
if (!username_.empty() && !password_.empty()) {
|
||||||
@@ -36,7 +37,6 @@ void MqttClient::subscribe(const std::string& topic, int qos) {
|
|||||||
|
|
||||||
void MqttClient::publishMessage(const std::string& topic, const std::string& payload) {
|
void MqttClient::publishMessage(const std::string& topic, const std::string& payload) {
|
||||||
try {
|
try {
|
||||||
std::cout << "Publishing message: " << payload << std::endl;
|
|
||||||
client_.publish(topic, payload)->wait();
|
client_.publish(topic, payload)->wait();
|
||||||
} catch (const mqtt::exception& exc) {
|
} catch (const mqtt::exception& exc) {
|
||||||
std::cerr << "Error: " << exc.what() << std::endl;
|
std::cerr << "Error: " << exc.what() << std::endl;
|
||||||
|
@@ -1,16 +1,22 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "KobukiDriver/graph.h"
|
#include <fstream>
|
||||||
#include "MQTT/MqttClient.h"
|
#include "MQTT/MqttClient.h"
|
||||||
#include "KobukiDriver/CKobuki.h"
|
#include "KobukiDriver/CKobuki.h"
|
||||||
|
#include <opencv4/opencv2/opencv.hpp>
|
||||||
|
#include <opencv4/opencv2/core.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
CKobuki robot;
|
CKobuki robot;
|
||||||
|
std::atomic<bool> kobuki_connected(false);
|
||||||
|
|
||||||
std::string readMQTT();
|
std::string readMQTT();
|
||||||
void parseMQTT(std::string message);
|
void parseMQTT(std::string message);
|
||||||
//ip, clientID, username, password
|
void CapnSend();
|
||||||
MqttClient client("mqtt://145.92.224.21:1884", "KobukiRPI", "rpi", "rpiwachtwoordofzo"); // create a client object
|
void checkKobukiConnection();
|
||||||
|
// ip, clientID, username, password
|
||||||
|
MqttClient client("ws://145.92.224.21/ws/", "KobukiRPI", "rpi", "rpiwachtwoordofzo"); // create a client object
|
||||||
std::string message = "stop";
|
std::string message = "stop";
|
||||||
std::string serializeKobukiData(const TKobukiData &data);
|
std::string serializeKobukiData(const TKobukiData &data);
|
||||||
void sendKobukiData(TKobukiData &data);
|
void sendKobukiData(TKobukiData &data);
|
||||||
@@ -19,7 +25,7 @@ void setup()
|
|||||||
{
|
{
|
||||||
unsigned char *null_ptr(0);
|
unsigned char *null_ptr(0);
|
||||||
robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
|
robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
|
||||||
//connect mqtt server and sub to commands
|
// connect mqtt server and sub to commands
|
||||||
client.connect();
|
client.connect();
|
||||||
client.subscribe("home/commands");
|
client.subscribe("home/commands");
|
||||||
}
|
}
|
||||||
@@ -27,35 +33,94 @@ void setup()
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
std::thread safety([&]() { robot.robotSafety(&message); });
|
std::thread image(CapnSend);
|
||||||
std::thread sendMqtt([&]() { sendKobukiData(robot.parser.data); });
|
std::thread safety([&](){ robot.robotSafety(&message); });
|
||||||
|
std::thread sendMqtt([&](){ sendKobukiData(robot.parser.data); });
|
||||||
|
std::thread connectionChecker(checkKobukiConnection);
|
||||||
|
connectionChecker.detach(); // Laat deze thread onafhankelijk draaien
|
||||||
|
|
||||||
while(true){
|
|
||||||
parseMQTT(readMQTT());
|
while (true)
|
||||||
|
{
|
||||||
|
std::string message = readMQTT();
|
||||||
|
if (!message.empty())
|
||||||
|
{
|
||||||
|
parseMQTT(message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sendMqtt.join();
|
sendMqtt.join();
|
||||||
safety.join();
|
safety.join();
|
||||||
return 0;
|
image.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::mutex connectionMutex;
|
||||||
|
|
||||||
|
void checkKobukiConnection()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(connectionMutex);
|
||||||
|
|
||||||
|
// Controleer of het apparaat beschikbaar is
|
||||||
|
if (!std::ifstream("/dev/ttyUSB0")){
|
||||||
|
if (kobuki_connected){
|
||||||
|
cout << "Kobuki disconnected: USB device not found." << endl;
|
||||||
|
kobuki_connected = false;
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
|
continue; // Probeer later opnieuw
|
||||||
|
}
|
||||||
|
|
||||||
|
// Controleer of de Kobuki verbonden is
|
||||||
|
if (!robot.isConnected()){
|
||||||
|
if (kobuki_connected){
|
||||||
|
cout << "Kobuki disconnected." << endl;
|
||||||
|
kobuki_connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Attempting to reconnect Kobuki..." << endl;
|
||||||
|
robot.startCommunication("/dev/ttyUSB0", true, nullptr);
|
||||||
|
|
||||||
|
if (robot.isConnected()){
|
||||||
|
cout << "Kobuki reconnected successfully!" << endl;
|
||||||
|
kobuki_connected = true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
cout << "Failed to reconnect Kobuki, retrying in 5 seconds..." << endl;
|
||||||
|
}
|
||||||
|
}else if (!kobuki_connected){
|
||||||
|
// Update status als de verbinding hersteld is
|
||||||
|
cout << "Kobuki is connected." << endl;
|
||||||
|
kobuki_connected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wacht voordat je opnieuw controleert
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string readMQTT()
|
std::string readMQTT()
|
||||||
{
|
{
|
||||||
message = client.getLastMessage();
|
static std::string lastMessage;
|
||||||
if (!message.empty())
|
|
||||||
|
std::string message = client.getLastMessage();
|
||||||
|
if (!message.empty() && message != lastMessage)
|
||||||
{
|
{
|
||||||
std::cout << "MQTT Message: " << message << std::endl;
|
std::cout << "MQTT Message: " << message << std::endl;
|
||||||
|
lastMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a small delay to avoid busy-waiting
|
// Add a small delay to avoid busy-waiting
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
return message;
|
return lastMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseMQTT(std::string message)
|
void parseMQTT(std::string message)
|
||||||
{
|
{
|
||||||
if (message == "up")
|
if (message == "up")
|
||||||
{
|
{
|
||||||
robot.forward(1024);
|
robot.forward(350);
|
||||||
}
|
}
|
||||||
else if (message == "left")
|
else if (message == "left")
|
||||||
{
|
{
|
||||||
@@ -67,7 +132,7 @@ void parseMQTT(std::string message)
|
|||||||
}
|
}
|
||||||
else if (message == "down")
|
else if (message == "down")
|
||||||
{
|
{
|
||||||
robot.forward(-800);
|
robot.forward(-350);
|
||||||
}
|
}
|
||||||
else if (message == "stop")
|
else if (message == "stop")
|
||||||
{
|
{
|
||||||
@@ -89,7 +154,9 @@ void logToFile()
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
TKobukiData robotData = robot.parser.data;
|
TKobukiData robotData = robot.parser.data;
|
||||||
std::ofstream outputFile("log", std::ios_base::app); // Open file in append mode to not overwrite own content
|
std::ofstream outputFile("log",
|
||||||
|
std::ios_base::app); // Open file in append mode to
|
||||||
|
// not overwrite own content
|
||||||
if (outputFile.is_open())
|
if (outputFile.is_open())
|
||||||
{ // check if the file was opened successfully
|
{ // check if the file was opened successfully
|
||||||
// Get current time
|
// Get current time
|
||||||
@@ -126,17 +193,25 @@ void logToFile()
|
|||||||
outputFile << "GyroAngle: " << robotData.GyroAngle << "\n";
|
outputFile << "GyroAngle: " << robotData.GyroAngle << "\n";
|
||||||
outputFile << "GyroAngleRate: " << robotData.GyroAngleRate << "\n";
|
outputFile << "GyroAngleRate: " << robotData.GyroAngleRate << "\n";
|
||||||
outputFile << "CliffSensorRight: " << robotData.CliffSensorRight << "\n";
|
outputFile << "CliffSensorRight: " << robotData.CliffSensorRight << "\n";
|
||||||
outputFile << "CliffSensorCenter: " << robotData.CliffSensorCenter << "\n";
|
outputFile << "CliffSensorCenter: " << robotData.CliffSensorCenter
|
||||||
|
<< "\n";
|
||||||
outputFile << "CliffSensorLeft: " << robotData.CliffSensorLeft << "\n";
|
outputFile << "CliffSensorLeft: " << robotData.CliffSensorLeft << "\n";
|
||||||
outputFile << "wheelCurrentLeft: " << robotData.wheelCurrentLeft << "\n";
|
outputFile << "wheelCurrentLeft: " << robotData.wheelCurrentLeft << "\n";
|
||||||
outputFile << "wheelCurrentRight: " << robotData.wheelCurrentRight << "\n";
|
outputFile << "wheelCurrentRight: " << robotData.wheelCurrentRight
|
||||||
|
<< "\n";
|
||||||
outputFile << "frameId: " << robotData.frameId << "\n";
|
outputFile << "frameId: " << robotData.frameId << "\n";
|
||||||
outputFile << "HardwareVersionPatch: " << robotData.extraInfo.HardwareVersionPatch << "\n";
|
outputFile << "HardwareVersionPatch: "
|
||||||
outputFile << "HardwareVersionMinor: " << robotData.extraInfo.HardwareVersionMinor << "\n";
|
<< robotData.extraInfo.HardwareVersionPatch << "\n";
|
||||||
outputFile << "HardwareVersionMajor: " << robotData.extraInfo.HardwareVersionMajor << "\n";
|
outputFile << "HardwareVersionMinor: "
|
||||||
outputFile << "FirmwareVersionPatch: " << robotData.extraInfo.FirmwareVersionPatch << "\n";
|
<< robotData.extraInfo.HardwareVersionMinor << "\n";
|
||||||
outputFile << "FirmwareVersionMinor: " << robotData.extraInfo.FirmwareVersionMinor << "\n";
|
outputFile << "HardwareVersionMajor: "
|
||||||
outputFile << "FirmwareVersionMajor: " << robotData.extraInfo.FirmwareVersionMajor << "\n";
|
<< 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 << "UDID0: " << robotData.extraInfo.UDID0 << "\n";
|
||||||
outputFile << "UDID1: " << robotData.extraInfo.UDID1 << "\n";
|
outputFile << "UDID1: " << robotData.extraInfo.UDID1 << "\n";
|
||||||
outputFile << "UDID2: " << robotData.extraInfo.UDID2 << "\n";
|
outputFile << "UDID2: " << robotData.extraInfo.UDID2 << "\n";
|
||||||
@@ -151,66 +226,116 @@ void logToFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendIndividualKobukiData(const TKobukiData &data) {
|
void sendIndividualKobukiData(const TKobukiData &data)
|
||||||
while (true) {
|
{
|
||||||
client.publishMessage("kobuki/data/timestamp", std::to_string(data.timestamp));
|
while (true)
|
||||||
client.publishMessage("kobuki/data/BumperCenter", std::to_string(data.BumperCenter));
|
{
|
||||||
client.publishMessage("kobuki/data/BumperLeft", std::to_string(data.BumperLeft));
|
std::cout << "Kobuki Data wordt gepubliceerd naar kobuki/data/timestamp: "
|
||||||
client.publishMessage("kobuki/data/BumperRight", std::to_string(data.BumperRight));
|
<< data.timestamp << std::endl;
|
||||||
client.publishMessage("kobuki/data/WheelDropLeft", std::to_string(data.WheelDropLeft));
|
client.publishMessage("kobuki/data/timestamp",
|
||||||
client.publishMessage("kobuki/data/WheelDropRight", std::to_string(data.WheelDropRight));
|
std::to_string(data.timestamp));
|
||||||
client.publishMessage("kobuki/data/CliffCenter", std::to_string(data.CliffCenter));
|
client.publishMessage("kobuki/data/BumperCenter",
|
||||||
client.publishMessage("kobuki/data/CliffLeft", std::to_string(data.CliffLeft));
|
std::to_string(data.BumperCenter));
|
||||||
client.publishMessage("kobuki/data/CliffRight", std::to_string(data.CliffRight));
|
client.publishMessage("kobuki/data/BumperLeft",
|
||||||
client.publishMessage("kobuki/data/EncoderLeft", std::to_string(data.EncoderLeft));
|
std::to_string(data.BumperLeft));
|
||||||
client.publishMessage("kobuki/data/EncoderRight", std::to_string(data.EncoderRight));
|
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/PWMleft", std::to_string(data.PWMleft));
|
||||||
client.publishMessage("kobuki/data/PWMright", std::to_string(data.PWMright));
|
client.publishMessage("kobuki/data/PWMright",
|
||||||
client.publishMessage("kobuki/data/ButtonPress1", std::to_string(data.ButtonPress1));
|
std::to_string(data.PWMright));
|
||||||
client.publishMessage("kobuki/data/ButtonPress2", std::to_string(data.ButtonPress2));
|
client.publishMessage("kobuki/data/ButtonPress1",
|
||||||
client.publishMessage("kobuki/data/ButtonPress3", std::to_string(data.ButtonPress3));
|
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/Charger", std::to_string(data.Charger));
|
||||||
client.publishMessage("kobuki/data/Battery", std::to_string(data.Battery));
|
client.publishMessage("kobuki/data/Battery", std::to_string(data.Battery));
|
||||||
client.publishMessage("kobuki/data/overCurrent", std::to_string(data.overCurrent));
|
client.publishMessage("kobuki/data/overCurrent",
|
||||||
client.publishMessage("kobuki/data/IRSensorRight", std::to_string(data.IRSensorRight));
|
std::to_string(data.overCurrent));
|
||||||
client.publishMessage("kobuki/data/IRSensorCenter", std::to_string(data.IRSensorCenter));
|
client.publishMessage("kobuki/data/IRSensorRight",
|
||||||
client.publishMessage("kobuki/data/IRSensorLeft", std::to_string(data.IRSensorLeft));
|
std::to_string(data.IRSensorRight));
|
||||||
client.publishMessage("kobuki/data/GyroAngle", std::to_string(data.GyroAngle));
|
client.publishMessage("kobuki/data/IRSensorCenter",
|
||||||
client.publishMessage("kobuki/data/GyroAngleRate", std::to_string(data.GyroAngleRate));
|
std::to_string(data.IRSensorCenter));
|
||||||
client.publishMessage("kobuki/data/CliffSensorRight", std::to_string(data.CliffSensorRight));
|
client.publishMessage("kobuki/data/IRSensorLeft",
|
||||||
client.publishMessage("kobuki/data/CliffSensorCenter", std::to_string(data.CliffSensorCenter));
|
std::to_string(data.IRSensorLeft));
|
||||||
client.publishMessage("kobuki/data/CliffSensorLeft", std::to_string(data.CliffSensorLeft));
|
client.publishMessage("kobuki/data/GyroAngle",
|
||||||
client.publishMessage("kobuki/data/wheelCurrentLeft", std::to_string(data.wheelCurrentLeft));
|
std::to_string(data.GyroAngle));
|
||||||
client.publishMessage("kobuki/data/wheelCurrentRight", std::to_string(data.wheelCurrentRight));
|
client.publishMessage("kobuki/data/GyroAngleRate",
|
||||||
client.publishMessage("kobuki/data/digitalInput", std::to_string(data.digitalInput));
|
std::to_string(data.GyroAngleRate));
|
||||||
client.publishMessage("kobuki/data/analogInputCh0", std::to_string(data.analogInputCh0));
|
client.publishMessage("kobuki/data/CliffSensorRight",
|
||||||
client.publishMessage("kobuki/data/analogInputCh1", std::to_string(data.analogInputCh1));
|
std::to_string(data.CliffSensorRight));
|
||||||
client.publishMessage("kobuki/data/analogInputCh2", std::to_string(data.analogInputCh2));
|
client.publishMessage("kobuki/data/CliffSensorCenter",
|
||||||
client.publishMessage("kobuki/data/analogInputCh3", std::to_string(data.analogInputCh3));
|
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/frameId", std::to_string(data.frameId));
|
||||||
client.publishMessage("kobuki/data/extraInfo/HardwareVersionPatch", std::to_string(data.extraInfo.HardwareVersionPatch));
|
client.publishMessage("kobuki/data/extraInfo/HardwareVersionPatch",
|
||||||
client.publishMessage("kobuki/data/extraInfo/HardwareVersionMinor", std::to_string(data.extraInfo.HardwareVersionMinor));
|
std::to_string(data.extraInfo.HardwareVersionPatch));
|
||||||
client.publishMessage("kobuki/data/extraInfo/HardwareVersionMajor", std::to_string(data.extraInfo.HardwareVersionMajor));
|
client.publishMessage("kobuki/data/extraInfo/HardwareVersionMinor",
|
||||||
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionPatch", std::to_string(data.extraInfo.FirmwareVersionPatch));
|
std::to_string(data.extraInfo.HardwareVersionMinor));
|
||||||
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionMinor", std::to_string(data.extraInfo.FirmwareVersionMinor));
|
client.publishMessage("kobuki/data/extraInfo/HardwareVersionMajor",
|
||||||
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionMajor", std::to_string(data.extraInfo.FirmwareVersionMajor));
|
std::to_string(data.extraInfo.HardwareVersionMajor));
|
||||||
client.publishMessage("kobuki/data/extraInfo/UDID0", std::to_string(data.extraInfo.UDID0));
|
client.publishMessage("kobuki/data/extraInfo/FirmwareVersionPatch",
|
||||||
client.publishMessage("kobuki/data/extraInfo/UDID1", std::to_string(data.extraInfo.UDID1));
|
std::to_string(data.extraInfo.FirmwareVersionPatch));
|
||||||
client.publishMessage("kobuki/data/extraInfo/UDID2", std::to_string(data.extraInfo.UDID2));
|
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()) {
|
if (!data.gyroData.empty())
|
||||||
const auto& latestGyro = data.gyroData.back();
|
{
|
||||||
client.publishMessage("kobuki/data/gyroData/x", std::to_string(latestGyro.x));
|
const auto &latestGyro = data.gyroData.back();
|
||||||
client.publishMessage("kobuki/data/gyroData/y", std::to_string(latestGyro.y));
|
client.publishMessage("kobuki/data/gyroData/x",
|
||||||
client.publishMessage("kobuki/data/gyroData/z", std::to_string(latestGyro.z));
|
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::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string serializeKobukiData(const TKobukiData &data) {
|
std::string serializeKobukiData(const TKobukiData &data)
|
||||||
std::string json = "{\"timestamp\":" + std::to_string(data.timestamp) +
|
{
|
||||||
|
std::string json =
|
||||||
|
"{\"timestamp\":" + std::to_string(data.timestamp) +
|
||||||
",\"BumperCenter\":" + std::to_string(data.BumperCenter) +
|
",\"BumperCenter\":" + std::to_string(data.BumperCenter) +
|
||||||
",\"BumperLeft\":" + std::to_string(data.BumperLeft) +
|
",\"BumperLeft\":" + std::to_string(data.BumperLeft) +
|
||||||
",\"BumperRight\":" + std::to_string(data.BumperRight) +
|
",\"BumperRight\":" + std::to_string(data.BumperRight) +
|
||||||
@@ -245,18 +370,25 @@ std::string serializeKobukiData(const TKobukiData &data) {
|
|||||||
",\"analogInputCh2\":" + std::to_string(data.analogInputCh2) +
|
",\"analogInputCh2\":" + std::to_string(data.analogInputCh2) +
|
||||||
",\"analogInputCh3\":" + std::to_string(data.analogInputCh3) +
|
",\"analogInputCh3\":" + std::to_string(data.analogInputCh3) +
|
||||||
",\"frameId\":" + std::to_string(data.frameId) +
|
",\"frameId\":" + std::to_string(data.frameId) +
|
||||||
",\"extraInfo\":{\"HardwareVersionPatch\":" + std::to_string(data.extraInfo.HardwareVersionPatch) +
|
",\"extraInfo\":{\"HardwareVersionPatch\":" +
|
||||||
",\"HardwareVersionMinor\":" + std::to_string(data.extraInfo.HardwareVersionMinor) +
|
std::to_string(data.extraInfo.HardwareVersionPatch) +
|
||||||
",\"HardwareVersionMajor\":" + std::to_string(data.extraInfo.HardwareVersionMajor) +
|
",\"HardwareVersionMinor\":" +
|
||||||
",\"FirmwareVersionPatch\":" + std::to_string(data.extraInfo.FirmwareVersionPatch) +
|
std::to_string(data.extraInfo.HardwareVersionMinor) +
|
||||||
",\"FirmwareVersionMinor\":" + std::to_string(data.extraInfo.FirmwareVersionMinor) +
|
",\"HardwareVersionMajor\":" +
|
||||||
",\"FirmwareVersionMajor\":" + std::to_string(data.extraInfo.FirmwareVersionMajor) +
|
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) +
|
",\"UDID0\":" + std::to_string(data.extraInfo.UDID0) +
|
||||||
",\"UDID1\":" + std::to_string(data.extraInfo.UDID1) +
|
",\"UDID1\":" + std::to_string(data.extraInfo.UDID1) +
|
||||||
",\"UDID2\":" + std::to_string(data.extraInfo.UDID2) + "},\"gyroData\":[";
|
",\"UDID2\":" + std::to_string(data.extraInfo.UDID2) + "},\"gyroData\":[";
|
||||||
|
|
||||||
if (!data.gyroData.empty()) {
|
if (!data.gyroData.empty())
|
||||||
const auto& latestGyro = data.gyroData.back();
|
{
|
||||||
|
const auto &latestGyro = data.gyroData.back();
|
||||||
json += "{\"x\":" + std::to_string(latestGyro.x) +
|
json += "{\"x\":" + std::to_string(latestGyro.x) +
|
||||||
",\"y\":" + std::to_string(latestGyro.y) +
|
",\"y\":" + std::to_string(latestGyro.y) +
|
||||||
",\"z\":" + std::to_string(latestGyro.z) + "}";
|
",\"z\":" + std::to_string(latestGyro.z) + "}";
|
||||||
@@ -265,11 +397,52 @@ std::string serializeKobukiData(const TKobukiData &data) {
|
|||||||
json += "]}";
|
json += "]}";
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
//create extra function to send the message every 100ms
|
// create extra function to send the message every 100ms
|
||||||
//needed it so it can be threaded
|
// needed it so it can be threaded
|
||||||
void sendKobukiData(TKobukiData &data) {
|
void sendKobukiData(TKobukiData &data)
|
||||||
while (true) {
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
client.publishMessage("kobuki/data", serializeKobukiData(data));
|
client.publishMessage("kobuki/data", serializeKobukiData(data));
|
||||||
|
std::cout << "Sent data" << std::endl;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CapnSend() {
|
||||||
|
VideoCapture cap(0);
|
||||||
|
if (!cap.isOpened()) {
|
||||||
|
cerr << "Error: Could not open camera" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat frame;
|
||||||
|
while (true) {
|
||||||
|
if (!cap.read(frame)) {
|
||||||
|
cout << "Reconnecting camera" << endl;
|
||||||
|
cap.release();
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
// Attempt to reconnect to the camera
|
||||||
|
cap.open(0);
|
||||||
|
if (!cap.isOpened()) {
|
||||||
|
cerr << "Error: Could not reconnect to camera" << endl;
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1)); // Wait before retrying
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
cout << "Reconnected to camera" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the image to a byte array
|
||||||
|
vector<uchar> buf;
|
||||||
|
imencode(".jpg", frame, buf);
|
||||||
|
auto *enc_msg = reinterpret_cast<unsigned char *>(buf.data());
|
||||||
|
|
||||||
|
// 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(200)); // Send image every 200ms
|
||||||
|
}
|
||||||
|
}
|
@@ -1,15 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
|
||||||
|
|
||||||
# Find the Paho MQTT C++ library
|
|
||||||
find_library(PAHO_MQTTPP_LIBRARY paho-mqttpp3 PATHS /usr/local/lib)
|
|
||||||
find_library(PAHO_MQTT_LIBRARY paho-mqtt3a PATHS /usr/local/lib)
|
|
||||||
|
|
||||||
# Include the headers
|
|
||||||
include_directories(/usr/local/include)
|
|
||||||
|
|
||||||
# Add the executable
|
|
||||||
add_executable(my_program main.cpp)
|
|
||||||
|
|
||||||
# Link the libraries
|
|
||||||
target_link_libraries(my_program ${PAHO_MQTTPP_LIBRARY} ${PAHO_MQTT_LIBRARY})
|
|
@@ -1,64 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <mqtt/async_client.h>
|
|
||||||
#include <thread> // For std::this_thread::sleep_for
|
|
||||||
#include <chrono> // For std::chrono::seconds
|
|
||||||
|
|
||||||
// Define the address of the MQTT broker, the client ID, and the topic to subscribe to.
|
|
||||||
const std::string ADDRESS("mqtt://localhost:1883"); // Broker address (Raspberry Pi)
|
|
||||||
const std::string CLIENT_ID("raspberry_pi_client");
|
|
||||||
const std::string TOPIC("home/commands");
|
|
||||||
|
|
||||||
// Define a callback class that handles incoming messages and connection events.
|
|
||||||
class callback : public virtual mqtt::callback {
|
|
||||||
// Called when a message arrives on a subscribed topic.
|
|
||||||
void message_arrived(mqtt::const_message_ptr msg) override {
|
|
||||||
std::cout << "Received message: '" << msg->get_topic()<< "' : " << msg->to_string() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when the connection to the broker is lost.
|
|
||||||
void connection_lost(const std::string& cause) override {
|
|
||||||
std::cerr << "Connection lost. Reason: " << cause << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a message delivery is complete.
|
|
||||||
void delivery_complete(mqtt::delivery_token_ptr token) override {
|
|
||||||
std::cout << "Message delivered!" << std::endl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// Create an MQTT async client and set up the callback class.
|
|
||||||
mqtt::async_client client(ADDRESS, CLIENT_ID);
|
|
||||||
callback cb;
|
|
||||||
client.set_callback(cb);
|
|
||||||
|
|
||||||
// Set up the connection options (such as username and password).
|
|
||||||
mqtt::connect_options connOpts;
|
|
||||||
connOpts.set_clean_session(true);
|
|
||||||
connOpts.set_user_name("ishak");
|
|
||||||
connOpts.set_password("kobuki");
|
|
||||||
connOpts.set_mqtt_version(MQTTVERSION_3_1_1);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Try to connect to the broker and wait until successful.
|
|
||||||
std::cout << "Connecting to broker..." << std::endl;
|
|
||||||
client.connect(connOpts)->wait(); // Connect with the provided options
|
|
||||||
std::cout << "Connected!" << std::endl;
|
|
||||||
|
|
||||||
// Subscribe to the specified topic and wait for confirmation.
|
|
||||||
std::cout << "Subscribing to topic: " << TOPIC << std::endl;
|
|
||||||
client.subscribe(TOPIC, 1)->wait(); // Subscribe with QoS level 1
|
|
||||||
|
|
||||||
// Keep the program running to continue receiving messages from the broker.
|
|
||||||
while (true) {
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1)); // Sleep to reduce CPU usage
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (const mqtt::exception &exc) {
|
|
||||||
// Catch any MQTT exceptions and display the error message.
|
|
||||||
std::cerr << "Error: " << exc.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0; // Return 0 to indicate successful execution
|
|
||||||
}
|
|
44
src/C++/OpenCV/CMakeLists.txt
Normal file
44
src/C++/OpenCV/CMakeLists.txt
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
cmake_minimum_required( VERSION 3.6 )
|
||||||
|
|
||||||
|
# Require C++11 (or later)
|
||||||
|
set( CMAKE_CXX_STANDARD 23 )
|
||||||
|
set( CMAKE_CXX_STANDARD_REQUIRED ON )
|
||||||
|
set( CMAKE_CXX_EXTENSIONS OFF )
|
||||||
|
set(BUILD_MODE Debug)
|
||||||
|
# Create Project
|
||||||
|
project( Sample )
|
||||||
|
add_executable( YOLOv4 util.h main.cpp )
|
||||||
|
|
||||||
|
# Set StartUp Project
|
||||||
|
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "YOLOv4" )
|
||||||
|
|
||||||
|
# Find Package
|
||||||
|
# OpenCV
|
||||||
|
find_package( OpenCV REQUIRED )
|
||||||
|
|
||||||
|
if( OpenCV_FOUND )
|
||||||
|
# Additional Include Directories
|
||||||
|
include_directories( ${OpenCV_INCLUDE_DIRS} )
|
||||||
|
|
||||||
|
# Additional Dependencies
|
||||||
|
target_link_libraries( YOLOv4 ${OpenCV_LIBS} )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Download Model
|
||||||
|
set( MODEL https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights )
|
||||||
|
file( DOWNLOAD
|
||||||
|
"${MODEL}"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/yolov4.weights"
|
||||||
|
EXPECTED_HASH SHA256=e8a4f6c62188738d86dc6898d82724ec0964d0eb9d2ae0f0a9d53d65d108d562
|
||||||
|
SHOW_PROGRESS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Download Config
|
||||||
|
set( CONFIG https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4.cfg )
|
||||||
|
file( DOWNLOAD
|
||||||
|
"${CONFIG}"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/yolov4.cfg"
|
||||||
|
EXPECTED_HASH SHA256=a6d0f8e5c62cc8378384f75a8159b95fa2964d4162e33351b00ac82e0fc46a34
|
||||||
|
SHOW_PROGRESS
|
||||||
|
)
|
BIN
src/C++/OpenCV/YOLOv4
Executable file
BIN
src/C++/OpenCV/YOLOv4
Executable file
Binary file not shown.
80
src/C++/OpenCV/coco.names
Normal file
80
src/C++/OpenCV/coco.names
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
person
|
||||||
|
bicycle
|
||||||
|
car
|
||||||
|
motorbike
|
||||||
|
aeroplane
|
||||||
|
bus
|
||||||
|
train
|
||||||
|
truck
|
||||||
|
boat
|
||||||
|
traffic light
|
||||||
|
fire hydrant
|
||||||
|
stop sign
|
||||||
|
parking meter
|
||||||
|
bench
|
||||||
|
bird
|
||||||
|
cat
|
||||||
|
dog
|
||||||
|
horse
|
||||||
|
sheep
|
||||||
|
cow
|
||||||
|
elephant
|
||||||
|
bear
|
||||||
|
zebra
|
||||||
|
giraffe
|
||||||
|
backpack
|
||||||
|
umbrella
|
||||||
|
handbag
|
||||||
|
tie
|
||||||
|
suitcase
|
||||||
|
frisbee
|
||||||
|
skis
|
||||||
|
snowboard
|
||||||
|
sports ball
|
||||||
|
kite
|
||||||
|
baseball bat
|
||||||
|
baseball glove
|
||||||
|
skateboard
|
||||||
|
surfboard
|
||||||
|
tennis racket
|
||||||
|
bottle
|
||||||
|
wine glass
|
||||||
|
cup
|
||||||
|
fork
|
||||||
|
knife
|
||||||
|
spoon
|
||||||
|
bowl
|
||||||
|
banana
|
||||||
|
apple
|
||||||
|
sandwich
|
||||||
|
orange
|
||||||
|
broccoli
|
||||||
|
carrot
|
||||||
|
hot dog
|
||||||
|
pizza
|
||||||
|
donut
|
||||||
|
cake
|
||||||
|
chair
|
||||||
|
sofa
|
||||||
|
pottedplant
|
||||||
|
bed
|
||||||
|
diningtable
|
||||||
|
toilet
|
||||||
|
tvmonitor
|
||||||
|
laptop
|
||||||
|
mouse
|
||||||
|
remote
|
||||||
|
keyboard
|
||||||
|
cell phone
|
||||||
|
microwave
|
||||||
|
oven
|
||||||
|
toaster
|
||||||
|
sink
|
||||||
|
refrigerator
|
||||||
|
book
|
||||||
|
clock
|
||||||
|
vase
|
||||||
|
scissors
|
||||||
|
teddy bear
|
||||||
|
hair drier
|
||||||
|
toothbrush
|
209
src/C++/OpenCV/main.cpp
Normal file
209
src/C++/OpenCV/main.cpp
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include <opencv2/dnn.hpp>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
// Helper function to check if a file exists
|
||||||
|
bool fileExists(const std::string &path)
|
||||||
|
{
|
||||||
|
return std::filesystem::exists(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to read class names from a file
|
||||||
|
std::vector<std::string> _readClassNameList(const std::string &path)
|
||||||
|
{
|
||||||
|
std::vector<std::string> classes;
|
||||||
|
|
||||||
|
// Check if file exists
|
||||||
|
if (!fileExists(path))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Class names file not found: " + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to open and read file
|
||||||
|
std::ifstream file(path);
|
||||||
|
if (!file.is_open())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Unable to open class names file: " + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(file, line))
|
||||||
|
{
|
||||||
|
if (!line.empty())
|
||||||
|
{
|
||||||
|
classes.push_back(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classes.empty())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("No classes found in file: " + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Open Video Capture
|
||||||
|
cv::VideoCapture capture = cv::VideoCapture(0);
|
||||||
|
if (!capture.isOpened())
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to open camera device" << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read Class Name List and Color Table
|
||||||
|
const std::string list = "coco.names";
|
||||||
|
const std::vector<std::string> classes = _readClassNameList(list);
|
||||||
|
const std::vector<cv::Scalar> colors = getClassColors(classes.size());
|
||||||
|
|
||||||
|
// Debug: Print the size of the colors vector
|
||||||
|
std::cout << "Number of colors: " << colors.size() << std::endl;
|
||||||
|
|
||||||
|
// Read Darknet
|
||||||
|
const std::string model = "yolov4.weights";
|
||||||
|
const std::string config = "yolov4.cfg";
|
||||||
|
cv::dnn::Net net = cv::dnn::readNet(model, config);
|
||||||
|
if (net.empty())
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to load network" << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Preferable Backend
|
||||||
|
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
|
||||||
|
|
||||||
|
// Set Preferable Target
|
||||||
|
net.setPreferableTarget(cv::dnn::DNN_TARGET_OPENCL);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// Read Frame
|
||||||
|
cv::Mat frame;
|
||||||
|
capture >> frame;
|
||||||
|
if (frame.empty())
|
||||||
|
{
|
||||||
|
cv::waitKey(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (frame.channels() == 4)
|
||||||
|
{
|
||||||
|
cv::cvtColor(frame, frame, cv::COLOR_BGRA2BGR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Blob from Input Image
|
||||||
|
cv::Mat blob = cv::dnn::blobFromImage(frame, 1 / 255.f, cv::Size(416, 416), cv::Scalar(), true, false);
|
||||||
|
|
||||||
|
// Set Input Blob
|
||||||
|
net.setInput(blob);
|
||||||
|
|
||||||
|
// Run Forward Network
|
||||||
|
std::vector<cv::Mat> detections;
|
||||||
|
net.forward(detections, getOutputsNames(net));
|
||||||
|
|
||||||
|
// Draw Region
|
||||||
|
std::vector<int32_t> class_ids;
|
||||||
|
std::vector<float> confidences;
|
||||||
|
std::vector<cv::Rect> rectangles;
|
||||||
|
for (cv::Mat &detection : detections)
|
||||||
|
{
|
||||||
|
if (detection.empty())
|
||||||
|
{
|
||||||
|
std::cerr << "Detection matrix is empty!" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < detection.rows; i++)
|
||||||
|
{
|
||||||
|
cv::Mat region = detection.row(i);
|
||||||
|
|
||||||
|
// Retrieve Max Confidence and Class Index
|
||||||
|
cv::Mat scores = region.colRange(5, detection.cols);
|
||||||
|
cv::Point class_id;
|
||||||
|
double confidence;
|
||||||
|
cv::minMaxLoc(scores, 0, &confidence, 0, &class_id);
|
||||||
|
|
||||||
|
// Check Confidence
|
||||||
|
constexpr float threshold = 0.2;
|
||||||
|
if (threshold > confidence)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve Object Position
|
||||||
|
const int32_t x_center = static_cast<int32_t>(region.at<float>(0) * frame.cols);
|
||||||
|
const int32_t y_center = static_cast<int32_t>(region.at<float>(1) * frame.rows);
|
||||||
|
const int32_t width = static_cast<int32_t>(region.at<float>(2) * frame.cols);
|
||||||
|
const int32_t height = static_cast<int32_t>(region.at<float>(3) * frame.rows);
|
||||||
|
const cv::Rect rectangle = cv::Rect(x_center - (width / 2), y_center - (height / 2), width, height);
|
||||||
|
|
||||||
|
// Add Class ID, Confidence, Rectangle
|
||||||
|
class_ids.push_back(class_id.x);
|
||||||
|
confidences.push_back(confidence);
|
||||||
|
rectangles.push_back(rectangle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove Overlap Rectangles using Non-Maximum Suppression
|
||||||
|
constexpr float confidence_threshold = 0.5; // Confidence
|
||||||
|
constexpr float nms_threshold = 0.5; // IoU (Intersection over Union)
|
||||||
|
std::vector<int32_t> indices;
|
||||||
|
cv::dnn::NMSBoxes(rectangles, confidences, confidence_threshold, nms_threshold, indices);
|
||||||
|
|
||||||
|
// Draw Rectangle
|
||||||
|
for (const int32_t &index : indices)
|
||||||
|
{
|
||||||
|
// Bounds checking
|
||||||
|
if (class_ids[index] >= colors.size())
|
||||||
|
{
|
||||||
|
std::cerr << "Color index out of bounds: " << class_ids[index] << " (max: " << colors.size() - 1 << ")" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cv::Rect rectangle = rectangles[index];
|
||||||
|
const cv::Scalar color = colors[class_ids[index]];
|
||||||
|
|
||||||
|
// Debug: Print the index and color
|
||||||
|
std::cout << "Drawing rectangle with color index: " << class_ids[index] << std::endl;
|
||||||
|
|
||||||
|
constexpr int32_t thickness = 3;
|
||||||
|
cv::rectangle(frame, rectangle, color, thickness);
|
||||||
|
|
||||||
|
std::string label = classes[class_ids[index]] + ": " + std::to_string(static_cast<int>(confidences[index] * 100)) + "%";
|
||||||
|
|
||||||
|
int baseLine;
|
||||||
|
cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
|
||||||
|
int top = std::max(rectangle.y, labelSize.height);
|
||||||
|
cv::rectangle(frame, cv::Point(rectangle.x, top - labelSize.height),
|
||||||
|
cv::Point(rectangle.x + labelSize.width, top + baseLine), color, cv::FILLED);
|
||||||
|
cv::putText(frame, label, cv::Point(rectangle.x, top), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(255, 255, 255), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show Image
|
||||||
|
cv::imshow("Object Detection", frame);
|
||||||
|
const int32_t key = cv::waitKey(1);
|
||||||
|
if (key == 'q')
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::destroyAllWindows();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// cloned and fixed from https://github.com/UnaNancyOwen/OpenCVDNNSample/tree/master
|
61
src/C++/OpenCV/util.h
Normal file
61
src/C++/OpenCV/util.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#ifndef __UTIL__
|
||||||
|
#define __UTIL__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <opencv2/dnn.hpp>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
|
||||||
|
// Get Output Layers Name
|
||||||
|
std::vector<std::string> getOutputsNames( const cv::dnn::Net& net )
|
||||||
|
{
|
||||||
|
static std::vector<std::string> names;
|
||||||
|
if( names.empty() ){
|
||||||
|
std::vector<int32_t> out_layers = net.getUnconnectedOutLayers();
|
||||||
|
std::vector<std::string> layers_names = net.getLayerNames();
|
||||||
|
names.resize( out_layers.size() );
|
||||||
|
for( size_t i = 0; i < out_layers.size(); ++i ){
|
||||||
|
names[i] = layers_names[out_layers[i] - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Output Layer Type
|
||||||
|
std::string getOutputLayerType( cv::dnn::Net& net )
|
||||||
|
{
|
||||||
|
const std::vector<int32_t> out_layers = net.getUnconnectedOutLayers();
|
||||||
|
const std::string output_layer_type = net.getLayer( out_layers[0] )->type;
|
||||||
|
return output_layer_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read Class Name List
|
||||||
|
std::vector<std::string> readClassNameList( const std::string list_path )
|
||||||
|
{
|
||||||
|
std::vector<std::string> classes;
|
||||||
|
std::ifstream ifs( list_path );
|
||||||
|
if( !ifs.is_open() ){
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
std::string class_name = "";
|
||||||
|
while( std::getline( ifs, class_name ) ){
|
||||||
|
classes.push_back( class_name );
|
||||||
|
}
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Class Color Table for Visualize
|
||||||
|
std::vector<cv::Scalar> getClassColors( const int32_t number_of_colors )
|
||||||
|
{
|
||||||
|
cv::RNG random;
|
||||||
|
std::vector<cv::Scalar> colors;
|
||||||
|
for( int32_t i = 0; i < number_of_colors; i++ ){
|
||||||
|
cv::Scalar color( random.uniform( 0, 255 ), random.uniform( 0, 255 ), random.uniform( 0, 255 ) );
|
||||||
|
colors.push_back( color );
|
||||||
|
}
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __UTIL__
|
1158
src/C++/OpenCV/yolov4.cfg
Normal file
1158
src/C++/OpenCV/yolov4.cfg
Normal file
File diff suppressed because it is too large
Load Diff
BIN
src/C++/OpenCV/yolov4.weights
Normal file
BIN
src/C++/OpenCV/yolov4.weights
Normal file
Binary file not shown.
41
src/Python/YOLO/app.py
Normal file
41
src/Python/YOLO/app.py
Normal 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()
|
1
src/Python/flask/.dockerignore
Normal file
1
src/Python/flask/.dockerignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
18
src/Python/flask/Dockerfile
Normal file
18
src/Python/flask/Dockerfile
Normal 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" --restart=always flaskapp:latest
|
||||||
|
# need to use network host to connect to the host's mqtt server
|
6
src/Python/flask/requirements.txt
Normal file
6
src/Python/flask/requirements.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Flask==3.1.0
|
||||||
|
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,28 +1,88 @@
|
|||||||
from flask import Flask, request, render_template, jsonify
|
from flask import Flask, Response, request, render_template, jsonify, g
|
||||||
import paho.mqtt.client as mqtt
|
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__)
|
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):
|
def on_message(client, userdata, message):
|
||||||
global kobuki_message #set scope for this variable
|
global kobuki_message, latest_image, processed_image, yolo_results
|
||||||
|
if message.topic == "kobuki/data":
|
||||||
kobuki_message = str(message.payload.decode("utf-8"))
|
kobuki_message = str(message.payload.decode("utf-8"))
|
||||||
print(kobuki_message)
|
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)
|
||||||
|
|
||||||
# Create an MQTT client instance
|
# Create an MQTT client instance
|
||||||
mqtt_client = mqtt.Client()
|
mqtt_client = mqtt.Client()
|
||||||
mqtt_client.username_pw_set("server", "serverwachtwoordofzo")
|
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.loop_start()
|
||||||
mqtt_client.subscribe("kobuki/data")
|
mqtt_client.subscribe("kobuki/data")
|
||||||
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.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
|
||||||
|
|
||||||
|
# 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('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
|
@app.route('/control', methods=["GET", "POST"])
|
||||||
@app.route('/control', methods=["GET","POST"])
|
|
||||||
def control():
|
def control():
|
||||||
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
|
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
|
||||||
return render_template('control.html')
|
return render_template('control.html')
|
||||||
@@ -36,21 +96,82 @@ def move():
|
|||||||
|
|
||||||
# Verstuur de richting via MQTT
|
# Verstuur de richting via MQTT
|
||||||
if direction:
|
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})
|
return jsonify({"status": "success", "direction": direction})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/data', methods=['GET'])
|
@app.route('/data', methods=['GET'])
|
||||||
def data():
|
def data():
|
||||||
|
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()
|
||||||
|
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()
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
print(f"JSON decode error: {e}")
|
||||||
|
except mysql.connector.Error as err:
|
||||||
|
print(f"Database error: {err}")
|
||||||
return kobuki_message
|
return kobuki_message
|
||||||
|
|
||||||
@app.route('/phpmyadmin/<path:path>')
|
|
||||||
def phpmyadmin_passthrough(path):
|
|
||||||
# Laat Apache deze route direct afhandelen
|
|
||||||
return "", 404
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/image')
|
||||||
|
def image():
|
||||||
|
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:
|
||||||
|
db = get_db()
|
||||||
|
with db.cursor() as cursor:
|
||||||
|
sql_yolo = "INSERT INTO image (class, confidence) VALUES (%s, %s)"
|
||||||
|
yolo_tuples = [(result["class"], result["confidence"]) for result in yolo_results]
|
||||||
|
print(f"YOLO Tuples: {yolo_tuples}") # Debug statement
|
||||||
|
cursor.executemany(sql_yolo, yolo_tuples)
|
||||||
|
db.commit()
|
||||||
|
cursor.close()
|
||||||
|
return jsonify(yolo_results)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, port=5000)
|
app.run(debug=True, port=5000)
|
@@ -1,9 +1,9 @@
|
|||||||
// Selecteer alle knoppen en voeg een event listener toe aan elke knop
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
document.querySelectorAll(".btn").forEach(button => {
|
document.querySelectorAll(".btn").forEach(button => {
|
||||||
button.addEventListener("click", function(event) {
|
button.addEventListener("click", function(event) {
|
||||||
event.preventDefault(); // voorkomt pagina-verversing
|
event.preventDefault(); // prevents page refresh
|
||||||
|
|
||||||
// Haal de waarde van de knop op
|
// Get the value of the button
|
||||||
const direction = event.target.value;
|
const direction = event.target.value;
|
||||||
|
|
||||||
fetch("/move", {
|
fetch("/move", {
|
||||||
@@ -21,12 +21,17 @@ document.querySelectorAll(".btn").forEach(button => {
|
|||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Fetch data from the server
|
// Fetch data from the server
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
|
try {
|
||||||
const response = await fetch("/data");
|
const response = await fetch("/data");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error:", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the data and show it on the website
|
// Parse the data and show it on the website
|
||||||
@@ -34,14 +39,25 @@ document.querySelectorAll(".btn").forEach(button => {
|
|||||||
const data = await fetchData();
|
const data = await fetchData();
|
||||||
const sensorDataContainer = document.getElementById("sensor-data");
|
const sensorDataContainer = document.getElementById("sensor-data");
|
||||||
sensorDataContainer.innerHTML = ""; // Clear previous data
|
sensorDataContainer.innerHTML = ""; // Clear previous data
|
||||||
//for each object in json array create a new paragraph element and append it to the sensorDataContainer
|
// For each object in JSON array, create a new paragraph element and append it to the sensorDataContainer
|
||||||
for (const [key, value] of Object.entries(data)) {
|
for (const [key, value] of Object.entries(data)) {
|
||||||
const dataElement = document.createElement("p");
|
const dataElement = document.createElement("p");
|
||||||
dataElement.textContent = `${key}: ${value}`;
|
dataElement.textContent = `${key}: ${value}`;
|
||||||
sensorDataContainer.appendChild(dataElement);
|
sensorDataContainer.appendChild(dataElement); // Add the element to the container
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch and display sensor data every 5 seconds
|
// Update the image
|
||||||
setInterval(parseData, 5000);
|
async function updateImage() {
|
||||||
|
let img = document.getElementById("robot-image");
|
||||||
|
img.src = "/image?" + new Date().getTime(); // Add timestamp to avoid caching
|
||||||
|
// Wait for 200 milliseconds before fetching the next image
|
||||||
|
setTimeout(updateImage, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch and display sensor data every 1 second
|
||||||
|
setInterval(parseData, 1000);
|
||||||
|
|
||||||
|
// Start updating the image
|
||||||
|
updateImage();
|
||||||
});
|
});
|
@@ -1,6 +1,8 @@
|
|||||||
{% extends 'base.html' %} {% block head %}
|
{% extends 'base.html' %}
|
||||||
|
{% block head %}
|
||||||
<link rel="stylesheet" href="../static/style.css" />
|
<link rel="stylesheet" href="../static/style.css" />
|
||||||
{% endblock %} {% block content %}
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@@ -11,8 +13,8 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="image-section">
|
<div class="robot-image">
|
||||||
<img src="kobuki.jpg" alt="Kobuki Robot" id="robot-image" />
|
<img src="/image" alt="Kobuki Camera Feed" id="robot-image" />
|
||||||
</div>
|
</div>
|
||||||
<div class="button-section">
|
<div class="button-section">
|
||||||
<form id="form" action="/move" method="post">
|
<form id="form" action="/move" method="post">
|
||||||
@@ -42,6 +44,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="../static/script.js"></script>
|
<script src="../static/script.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
BIN
src/Python/flask/web/yolo11n.pt
Normal file
BIN
src/Python/flask/web/yolo11n.pt
Normal file
Binary file not shown.
@@ -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
|
|
13
src/config/rpi/kobukiDriver.service
Normal file
13
src/config/rpi/kobukiDriver.service
Normal 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
|
7
src/config/server/mosquitto.conf
Normal file
7
src/config/server/mosquitto.conf
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
allow_anonymous false
|
||||||
|
password_file /etc/mosquitto/passwordfile
|
||||||
|
listener 8080
|
||||||
|
protocol websockets
|
||||||
|
|
||||||
|
listener 1884
|
||||||
|
protocol mqtt
|
22
src/config/server/nginx-sites.conf
Normal file
22
src/config/server/nginx-sites.conf
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name 145.92.224.21;
|
||||||
|
|
||||||
|
# Proxy WebSocket connections for MQTT
|
||||||
|
location /ws/ {
|
||||||
|
proxy_pass http://localhost:9001;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Proxy HTTP connections for Flask
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:5000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
}
|
7
src/config/server/nginx.conf
Normal file
7
src/config/server/nginx.conf
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
stream {
|
||||||
|
server {
|
||||||
|
listen 9001;
|
||||||
|
proxy_pass localhost:8080;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
25
teamdocumentatie/Ishak/etische_aspecten.md
Normal file
25
teamdocumentatie/Ishak/etische_aspecten.md
Normal 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.
|
BIN
teamdocumentatie/Ishak/etische_aspecten.pdf
Normal file
BIN
teamdocumentatie/Ishak/etische_aspecten.pdf
Normal file
Binary file not shown.
7
teamdocumentatie/Ishak/expert.md
Normal file
7
teamdocumentatie/Ishak/expert.md
Normal 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.
|
||||||
|
-
|
BIN
teamdocumentatie/Ishak/image.png
Normal file
BIN
teamdocumentatie/Ishak/image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
teamdocumentatie/Ishak/images/image.png
Normal file
BIN
teamdocumentatie/Ishak/images/image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
21
teamdocumentatie/Ishak/motivatie.md
Normal file
21
teamdocumentatie/Ishak/motivatie.md
Normal 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 bachelor’s 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. Cognizant’s 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
|
64
teamdocumentatie/Ishak/verslag.md
Normal file
64
teamdocumentatie/Ishak/verslag.md
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|

|
||||||
|
|
||||||
|
# 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?
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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. 17–31) [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. 1497–1516) [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
|
BIN
teamdocumentatie/Ishak/verslag.pdf
Normal file
BIN
teamdocumentatie/Ishak/verslag.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user