19 Commits

Author SHA1 Message Date
d31c70269c remove old parser 2024-11-04 15:16:18 +01:00
206bf965e5 fix safety 2024-11-04 14:42:53 +01:00
9cb5468885 flip rotation value to negative 2024-11-04 14:39:05 +01:00
a422456747 change rotation way 2024-11-04 14:36:46 +01:00
a508d5c881 stop the robot 2024-11-04 14:10:17 +01:00
ishak jmilou.ishak
4aa0356a8a Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79 2024-11-04 14:06:28 +01:00
ishak jmilou.ishak
1b747edb8d FIXED CSS 2024-11-04 14:06:27 +01:00
f3033b1632 change rotation controls 2024-11-04 14:00:35 +01:00
f111030e73 added better safety 2024-11-04 13:37:09 +01:00
0a43e2ef57 added more preciese controls 2024-11-04 13:31:40 +01:00
95bd144c2e drive testing 2024-11-04 13:29:18 +01:00
c3270a1c47 fix thread going out of scope 2024-11-04 13:23:02 +01:00
0dc267536e fix nullpointer 2024-11-04 13:19:31 +01:00
60a51daf7b added sleep 2024-11-04 13:16:10 +01:00
3af23f61cf start safety thread 2024-11-04 13:10:16 +01:00
b90bca0060 re-added robotsafety 2024-11-04 13:05:17 +01:00
ishak jmilou.ishak
7cc2fbd8ec Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79 2024-11-04 12:32:33 +01:00
ishak jmilou.ishak
d14108d656 Add 'Stop' button to direction control in index.html 2024-11-04 12:32:32 +01:00
3d7bcf84e4 added more drive logic 2024-11-04 12:31:30 +01:00
5 changed files with 64 additions and 257 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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)

View File

@@ -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 */
}

View File

@@ -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 %}