mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-05 12:54:57 +00:00
Compare commits
19 Commits
25a179ded6
...
d31c70269c
Author | SHA1 | Date | |
---|---|---|---|
d31c70269c | |||
206bf965e5 | |||
9cb5468885 | |||
a422456747 | |||
a508d5c881 | |||
|
4aa0356a8a | ||
|
1b747edb8d | ||
f3033b1632 | |||
f111030e73 | |||
0a43e2ef57 | |||
95bd144c2e | |||
c3270a1c47 | |||
0dc267536e | |||
60a51daf7b | |||
3af23f61cf | |||
b90bca0060 | |||
|
7cc2fbd8ec | ||
|
d14108d656 | ||
3d7bcf84e4 |
@@ -282,198 +282,6 @@ int CKobuki::measure() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// int CKobuki::parseKobukiMessage(TKobukiData &output, unsigned char *data)
|
||||
// {
|
||||
// int rtrnvalue = checkChecksum(data);
|
||||
// // ak je zly checksum,tak kaslat na to
|
||||
// if (rtrnvalue != 0)
|
||||
// return -2;
|
||||
|
||||
// int checkedValue = 1;
|
||||
// // kym neprejdeme celu dlzku
|
||||
// while (checkedValue < data[0])
|
||||
// {
|
||||
// // basic data subload
|
||||
// if (data[checkedValue] == 0x01)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x0F)
|
||||
// return -1;
|
||||
// checkedValue++;
|
||||
// output.timestamp = data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue]; checkedValue += 2; output.BumperCenter =
|
||||
// data[checkedValue] && 0x02; output.BumperLeft =
|
||||
// data[checkedValue] && 0x04; output.BumperRight =
|
||||
// data[checkedValue] && 0x01; checkedValue++; output.WheelDropLeft
|
||||
// = data[checkedValue] && 0x02; output.WheelDropRight =
|
||||
// data[checkedValue] && 0x01; checkedValue++; output.CliffCenter =
|
||||
// data[checkedValue] && 0x02; output.CliffLeft = data[checkedValue]
|
||||
// && 0x04; output.CliffRight = data[checkedValue] && 0x01;
|
||||
// checkedValue++;
|
||||
// output.EncoderLeft = data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue]; checkedValue += 2; output.EncoderRight =
|
||||
// data[checkedValue + 1] * 256 + data[checkedValue]; checkedValue
|
||||
// += 2; output.PWMleft = data[checkedValue]; checkedValue++;
|
||||
// output.PWMright = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.ButtonPress = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.Charger = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.Battery = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.overCurrent = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x03)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x03)
|
||||
// return -3;
|
||||
// checkedValue++;
|
||||
// output.IRSensorRight = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.IRSensorCenter = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.IRSensorLeft = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x04)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x07)
|
||||
// return -4;
|
||||
// checkedValue++;
|
||||
// output.GyroAngle = data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue]; checkedValue += 2; output.GyroAngleRate =
|
||||
// data[checkedValue + 1] * 256 + data[checkedValue]; checkedValue
|
||||
// += 5; // 3 unsued
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x05)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x06)
|
||||
// return -5;
|
||||
// checkedValue++;
|
||||
// output.CliffSensorRight =
|
||||
// data[checkedValue + 1] * 256 + data[checkedValue];
|
||||
// checkedValue += 2;
|
||||
// output.CliffSensorCenter =
|
||||
// data[checkedValue + 1] * 256 + data[checkedValue];
|
||||
// checkedValue += 2;
|
||||
// output.CliffSensorLeft =
|
||||
// data[checkedValue + 1] * 256 + data[checkedValue];
|
||||
// checkedValue += 2;
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x06)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x02)
|
||||
// return -6;
|
||||
// checkedValue++;
|
||||
// output.wheelCurrentLeft = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.wheelCurrentRight = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x0A)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x04)
|
||||
// return -7;
|
||||
// checkedValue++;
|
||||
// output.extraInfo.HardwareVersionPatch = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.extraInfo.HardwareVersionMinor = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.extraInfo.HardwareVersionMajor = data[checkedValue];
|
||||
// checkedValue += 2;
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x0B)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x04)
|
||||
// return -8;
|
||||
// checkedValue++;
|
||||
// output.extraInfo.FirmwareVersionPatch = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.extraInfo.FirmwareVersionMinor = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// output.extraInfo.FirmwareVersionMajor = data[checkedValue];
|
||||
// checkedValue += 2;
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x0D)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] % 2 != 0)
|
||||
// return -9;
|
||||
// checkedValue++;
|
||||
// output.frameId = data[checkedValue];
|
||||
// checkedValue++;
|
||||
// int howmanyFrames = data[checkedValue] / 3;
|
||||
// checkedValue++;
|
||||
// output.gyroData.reserve(howmanyFrames);
|
||||
// output.gyroData.clear();
|
||||
// for (int hk = 0; hk < howmanyFrames; hk++)
|
||||
// {
|
||||
// TRawGyroData temp;
|
||||
// temp.x = data[checkedValue + 1] * 256 + data[checkedValue];
|
||||
// checkedValue += 2;
|
||||
// temp.y = data[checkedValue + 1] * 256 + data[checkedValue];
|
||||
// checkedValue += 2;
|
||||
// temp.z = data[checkedValue + 1] * 256 + data[checkedValue];
|
||||
// checkedValue += 2;
|
||||
// output.gyroData.push_back(temp);
|
||||
// }
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x10)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x10)
|
||||
// return -10;
|
||||
// checkedValue++;
|
||||
// output.digitalInput = data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue]; checkedValue += 2; output.analogInputCh0 =
|
||||
// data[checkedValue + 1] * 256 + data[checkedValue]; checkedValue
|
||||
// += 2; output.analogInputCh1 = data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue]; checkedValue += 2; output.analogInputCh2 =
|
||||
// data[checkedValue + 1] * 256 + data[checkedValue]; checkedValue
|
||||
// += 2; output.analogInputCh3 = data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue]; checkedValue += 8; // 2+6
|
||||
// }
|
||||
// else if (data[checkedValue] == 0x13)
|
||||
// {
|
||||
// checkedValue++;
|
||||
// if (data[checkedValue] != 0x0C)
|
||||
// return -11;
|
||||
// checkedValue++;
|
||||
// output.extraInfo.UDID0 = data[checkedValue + 3] * 256 * 256 * 256
|
||||
// +
|
||||
// data[checkedValue + 2] * 256 * 256 +
|
||||
// data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue];
|
||||
// checkedValue += 4;
|
||||
// output.extraInfo.UDID1 = data[checkedValue + 3] * 256 * 256 * 256
|
||||
// +
|
||||
// data[checkedValue + 2] * 256 * 256 +
|
||||
// data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue];
|
||||
// checkedValue += 4;
|
||||
// output.extraInfo.UDID2 = data[checkedValue + 3] * 256 * 256 * 256
|
||||
// +
|
||||
// data[checkedValue + 2] * 256 * 256 +
|
||||
// data[checkedValue + 1] * 256 +
|
||||
// data[checkedValue];
|
||||
// checkedValue += 4;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// checkedValue++;
|
||||
// checkedValue += data[checkedValue] + 1;
|
||||
// }
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
long double CKobuki::gyroToRad(signed short GyroAngle) {
|
||||
|
||||
@@ -781,6 +589,22 @@ void CKobuki::Rotate(int degrees) {
|
||||
}
|
||||
|
||||
|
||||
void CKobuki::robotSafety(std::string *pointerToMessage) {
|
||||
while (true) {
|
||||
|
||||
if (parser.data.BumperCenter || parser.data.BumperLeft || parser.data.BumperRight ||
|
||||
parser.data.CliffLeft || parser.data.CliffCenter || parser.data.CliffRight) {
|
||||
std::cout << "Safety condition triggered!" << std::endl; // Debug print
|
||||
*pointerToMessage = "estop";
|
||||
forward(-100); // reverse the robot
|
||||
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(100)));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CKobuki::robotSafety() {
|
||||
while (true) {
|
||||
|
||||
|
@@ -76,7 +76,8 @@ public:
|
||||
void goToXy(long double xx, long double yy);
|
||||
void Rotate(int degrees);
|
||||
std::ofstream odometry_log;
|
||||
void robotSafety();
|
||||
void robotSafety(std::string *pointerToMessage);
|
||||
void robotSafety(); //overload
|
||||
void sendNullMessage();
|
||||
KobukiParser parser;
|
||||
|
||||
|
@@ -8,30 +8,33 @@
|
||||
|
||||
using namespace std;
|
||||
CKobuki robot;
|
||||
int movement();
|
||||
std::string readMQTT();
|
||||
void parseMQTT(std::string message);
|
||||
MqttClient client("mqtt://145.92.224.21:1883", "KobukiRPI", "ishak", "kobuki"); //create a client object
|
||||
|
||||
std::string message = "stop";
|
||||
|
||||
void setup(){
|
||||
unsigned char *null_ptr(0);
|
||||
robot.startCommunication("/dev/ttyUSB0", true, null_ptr);
|
||||
client.connect();
|
||||
client.subscribe("home/commands");
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
setup();
|
||||
std::thread safety([&]() { robot.robotSafety(&message); });
|
||||
while(true){
|
||||
parseMQTT(readMQTT());
|
||||
}
|
||||
safety.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string readMQTT()
|
||||
{
|
||||
std::string message = client.getLastMessage();
|
||||
message = client.getLastMessage();
|
||||
if (!message.empty()) {
|
||||
std::cout << "MQTT Message: " << message << std::endl;
|
||||
}
|
||||
@@ -43,60 +46,30 @@ std::string readMQTT()
|
||||
|
||||
void parseMQTT(std::string message){
|
||||
if(message == "up"){
|
||||
robot.forward(600);
|
||||
robot.forward(1024);
|
||||
}
|
||||
else if(message == "left"){
|
||||
robot.Rotate(90);
|
||||
robot.setRotationSpeed(4);
|
||||
|
||||
}
|
||||
else if(message == "right"){
|
||||
robot.setRotationSpeed(-4);
|
||||
}
|
||||
else if(message == "down"){
|
||||
robot.Rotate(-90);
|
||||
robot.forward(-800);
|
||||
}
|
||||
else if(message == "stop"){
|
||||
robot.sendNullMessage();
|
||||
robot.sendNullMessage();
|
||||
}
|
||||
else if (message == "estop"){
|
||||
robot.forward(-400);
|
||||
}
|
||||
else{
|
||||
std::cout << "Invalid command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int movement()
|
||||
{
|
||||
int text;
|
||||
while (true)
|
||||
{
|
||||
cout << "gimme input: ";
|
||||
cin >> text;
|
||||
|
||||
if (text == 1)
|
||||
{
|
||||
robot.forward(400);
|
||||
}
|
||||
else if (text == 2)
|
||||
{
|
||||
// 1 is full circle
|
||||
robot.Rotate(90);
|
||||
}
|
||||
else if (text == 3)
|
||||
{
|
||||
// Add your code here for text == 3
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
robot.doRotation(text);
|
||||
throw "NaN";
|
||||
}
|
||||
catch (const char *msg)
|
||||
{
|
||||
cerr << msg << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void logToFile()
|
||||
{
|
||||
while (true)
|
||||
|
@@ -73,47 +73,51 @@ body {
|
||||
transition: transform 0.2s ease, background-color 0.2s ease;
|
||||
}
|
||||
|
||||
/* Middenknop */
|
||||
.btn:nth-child(1) {
|
||||
/* Direction buttons */
|
||||
.btn:nth-child(1) { /* Left */
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-125%, -50%);
|
||||
transform: translate(-160%, -50%);
|
||||
}
|
||||
|
||||
/* Knop boven */
|
||||
.btn:nth-child(2) {
|
||||
.btn:nth-child(2) { /* Up */
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
transform: translate(-50%, -35%);
|
||||
}
|
||||
|
||||
/* Knop rechts */
|
||||
.btn:nth-child(3) {
|
||||
.btn:nth-child(3) { /* Right */
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
transform: translate(35%,-50%);
|
||||
}
|
||||
|
||||
/* Knop onder */
|
||||
.btn:nth-child(4) {
|
||||
.btn:nth-child(4) { /* Down */
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
transform: translate(-50%, 35%);
|
||||
}
|
||||
|
||||
/* Knop links */
|
||||
.btn:nth-child(5) {
|
||||
.btn:nth-child(5) { /* Stop Button */
|
||||
top: 50%;
|
||||
left: 0;
|
||||
transform: translateY(-50%);
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background-color: red; /* Distinct color for the stop button */
|
||||
width: 60px; /* Slightly larger for emphasis */
|
||||
height: 60px; /* Slightly larger for emphasis */
|
||||
line-height: 60px; /* Center text vertically */
|
||||
}
|
||||
|
||||
/* Hover effects */
|
||||
.btn:hover {
|
||||
background-color: #0056b3;
|
||||
/* transform: scale(1.1); */
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
background-color: #004494;
|
||||
}
|
||||
|
||||
.stop-button:hover {
|
||||
background-color: darkred; /* Different hover color for the stop button */
|
||||
}
|
||||
|
@@ -1,10 +1,15 @@
|
||||
{%extends 'base.html'%} {%block head%} {%endblock%} {%block content%}
|
||||
{% extends 'base.html' %}
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="../static/style.css" />
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Kobuki</title>
|
||||
<link rel="stylesheet" href="../static/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@@ -12,11 +17,12 @@
|
||||
<img src="kobuki.jpg" alt="Kobuki Robot" id="robot-image" />
|
||||
</div>
|
||||
<div class="button-section">
|
||||
<form id = "form" action="/move" method="post">
|
||||
<form id="form" action="/move" method="post">
|
||||
<button class="btn" name="direction" value="left">←</button>
|
||||
<button class="btn" name="direction" value="up">↑</button>
|
||||
<button class="btn" name="direction" value="right">→</button>
|
||||
<button class="btn" name="direction" value="down">↓</button>
|
||||
<button class="btn stop-button" name="direction" value="stop">Stop</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -26,5 +32,4 @@
|
||||
<script src="../static/script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
{%endblock%}
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user