Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
M
mBot Konsole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Labor Systemanalyse und Optimierung
mBot
mBot Konsole
Commits
74c46363
Commit
74c46363
authored
Jul 01, 2020
by
Fabian Löbbers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init Commit
parent
95714a1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
220 additions
and
0 deletions
+220
-0
mBot_Konsole/konsole.cpp
mBot_Konsole/konsole.cpp
+220
-0
No files found.
mBot_Konsole/konsole.cpp
0 → 100644
View file @
74c46363
#include "konsole.h"
#include "ui_konsole.h"
#include "QDateTime"
Konsole
::
Konsole
(
QWidget
*
parent
)
:
QMainWindow
(
parent
),
ui
(
new
Ui
::
Konsole
)
{
ui
->
setupUi
(
this
);
init_Nachricht
();
}
Konsole
::~
Konsole
()
{
delete
ui
;
}
void
Konsole
::
init_Nachricht
(){
//Init Nachricht, die in der UI im Konsolenbereich bei Programmstart ausgegeben wird
ui
->
tf_konsole
->
append
(
"So läufts:"
);
ui
->
tf_konsole
->
append
(
"Sorge dafür, dass Bot und PC im gleichen Netzwerk sind."
);
ui
->
tf_konsole
->
append
(
"Drücke Autoconnect. Alternativ kannst du auch direkt die IP eingeben und Verbinden drücken"
);
ui
->
tf_konsole
->
append
(
"Benutze die Steuerfelder rechts, um den Bot zu steuern."
);
ui
->
tf_konsole
->
append
(
"ODER"
);
ui
->
tf_konsole
->
append
(
"Tippe unten einen Befehl ein"
);
ui
->
tf_konsole
->
append
(
"Tippe 'help' für mehr Infos"
);
ui
->
tf_konsole
->
append
(
""
);
}
void
Konsole
::
on_bt_verbinden_clicked
()
{
socket
=
new
QUdpSocket
(
this
);
ip_addr
=
ui
->
tf_ipaddr
->
text
();
port
=
ui
->
tf_port
->
text
().
toUShort
();
socket
->
bind
(
QHostAddress
(
ip_addr
),
port
);
connect
(
socket
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
updateKonsole
()));
qDebug
()
<<
"Verbinden"
;
ping
();
}
void
Konsole
::
ping
(){
//Test Funktion
sendCommand
(
"PING "
);
}
QString
Konsole
::
updateKonsole
(){
qDebug
()
<<
"Kommt an"
;
QByteArray
Buffer
;
Buffer
.
resize
(
socket
->
pendingDatagramSize
());
//Buffer wird erstellt und resized, da NAchrichten immer unterschiedlich lang sind
QHostAddress
sender
;
quint16
senderPort
;
socket
->
readDatagram
(
Buffer
.
data
(),
Buffer
.
size
(),
&
sender
,
&
senderPort
);
//read DAtagramm ließt die NAchricht
if
(
Buffer
!=
""
){
//Abfangen, dass der Buffer auch gefüllt ist.
qDebug
()
<<
"Message from: "
<<
sender
.
toString
();
qDebug
()
<<
"Message Port: "
<<
senderPort
;
qDebug
()
<<
"Buffer: "
<<
Buffer
;
QString
message
=
"Roboter <["
+
sender
.
toString
()
+
"]"
+
QTime
::
currentTime
().
toString
()
+
"> "
+
Buffer
;
ui
->
tf_konsole
->
append
(
message
);
if
(
firstrun
){
connectionSucc
();
firstrun
=
false
;
}
ui
->
tf_ipaddr
->
setText
(
sender
.
toString
());
}
else
{
qDebug
()
<<
"Keine Antwort"
;
//Ist die Antwort leer, wird "Keine Antwort" ausgegeben
}
return
Buffer
;
}
void
Konsole
::
sendCommand
(
QString
command_str
){
//Sendet Nachricht an IP und PORT per UDP
if
(
command_str
==
"help"
){
ui
->
tf_konsole
->
append
(
helptext
);
return
;
}
ip_addr
=
ui
->
tf_ipaddr
->
text
();
port
=
ui
->
tf_port
->
text
().
toUShort
();
qDebug
()
<<
port
;
qDebug
()
<<
ip_addr
;
QByteArray
Data
;
Data
.
append
(
QString
::
number
(
commandID
)
+
" "
+
command_str
+
" ;"
);
// damit der mBot weiß, wann der Befehl zuende ist
commandID
+=
1
;
try
{
// Fängt fehler ab
socket
->
writeDatagram
(
Data
,
QHostAddress
(
ip_addr
),
port
);
//Sendet DATA per UDP, an IP und PORT
}
catch
(...){
qDebug
()
<<
"Senden fehlgeschlagen"
;
}
}
void
Konsole
::
on_bt_send_clicked
(){
sendCommand
(
ui
->
tf_nachricht
->
text
());
QString
message
=
"Server <"
+
QTime
::
currentTime
().
toString
()
+
"> "
+
ui
->
tf_nachricht
->
text
();
ui
->
tf_konsole
->
append
(
message
);
ui
->
tf_nachricht
->
clear
();
}
void
Konsole
::
on_tf_nachricht_returnPressed
()
{
on_bt_send_clicked
();
}
void
Konsole
::
on_dial_winkel_rechts_sliderMoved
(
int
position
)
{
if
(
position
<
0
){
position
=
position
*-
1
;
ui
->
dial_winkel_rechts
->
setValue
(
position
);
}
ui
->
tf_winkel_rechts
->
setText
(
QString
::
number
(
position
));
}
void
Konsole
::
on_dial_winkel_links_sliderMoved
(
int
position
)
{
if
(
position
>
0
){
position
=
position
*-
1
;
ui
->
dial_winkel_links
->
setValue
(
position
);
}
ui
->
tf_winkel_links
->
setText
(
QString
::
number
(
position
*-
1
));
}
void
Konsole
::
on_slider_clicks_sliderMoved
(
int
position
)
{
ui
->
lb_clicks
->
setText
(
QString
::
number
(
position
));
}
void
Konsole
::
connectionSucc
(){
//Bei erfolgreicher Verbindung, werden die Steuerfelder ENABLED
ui
->
cb_watchdog
->
setEnabled
(
true
);
ui
->
tf_nachricht
->
setEnabled
(
true
);
ui
->
bt_send
->
setEnabled
(
true
);
ui
->
tf_ipaddr
->
setEnabled
(
false
);
ui
->
bt_verbinden
->
setEnabled
(
false
);
ui
->
bt_autoconnect
->
setEnabled
(
false
);
ui
->
tf_port
->
setEnabled
(
false
);
ui
->
bt_up
->
setEnabled
(
true
);
ui
->
bt_down
->
setEnabled
(
true
);
ui
->
bt_turnleft
->
setEnabled
(
true
);
ui
->
bt_turnright
->
setEnabled
(
true
);
ui
->
bt_hupe
->
setEnabled
(
true
);
ui
->
bt_hupe
->
setFocus
();
if
(
ui
->
cb_watchdog
->
isChecked
()){
sendCommand
(
"WDE"
);
}
else
{
sendCommand
(
"WDD"
);
}
sendCommand
(
"SP "
+
ui
->
lb_speed
->
text
());
}
void
Konsole
::
on_bt_autoconnect_clicked
()
{
QString
addr
=
"192.168.0.255"
;
//als IP wird die BROADCAST adresse des Subnetzes verwendet
ui
->
tf_ipaddr
->
setText
(
"192.168.0.255"
);
//diese wird in das Textfeld eingefügt
qint32
port
=
ui
->
tf_port
->
text
().
toInt
();
//port wird aus textfeld gelesen
socket
=
new
QUdpSocket
(
this
);
//Neues UDP Socket wird erstellt
socket
->
bind
(
QHostAddress
(
addr
),
port
);
//Socket wird an Adresse udn port gebunden
connect
(
socket
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
updateKonsole
()));
//socket wird mit readyready verbunden und löst ping() aus
sendCommand
(
"PING "
);
//Ping wird gesendet
}
void
Konsole
::
on_bt_up_clicked
()
{
QString
value
=
QString
::
number
(
ui
->
slider_clicks
->
value
());
QString
command
=
"GO "
+
value
+
" "
+
value
;
sendCommand
(
command
);
}
void
Konsole
::
on_bt_turnleft_clicked
()
{
int
winkel
=
ui
->
tf_winkel_links
->
text
().
toInt
();
double
faktor
=
842.0
/
360.0
;
//anpassungsfaktor: für 360 Graddrehung benötigt der Bot 842 Schritte
QString
value
=
QString
::
number
(
winkel
*
faktor
);
QString
command
=
"GO -"
+
value
+
" "
+
value
;
sendCommand
(
command
);
}
void
Konsole
::
on_bt_turnright_clicked
()
{
int
winkel
=
ui
->
tf_winkel_rechts
->
text
().
toInt
();
double
faktor
=
842.0
/
360.0
;
//anpassungsfaktor: für 360 Graddrehung benötigt der Bot 842 Schritte
QString
value
=
QString
::
number
(
winkel
*
faktor
);
QString
command
=
"GO "
+
value
+
" -"
+
value
;
sendCommand
(
command
);
}
void
Konsole
::
on_bt_down_clicked
()
{
QString
value
=
QString
::
number
(
ui
->
slider_clicks
->
value
());
QString
command
=
"GO -"
+
value
+
" -"
+
value
;
sendCommand
(
command
);
}
void
Konsole
::
on_bt_hupe_clicked
()
{
QString
command
=
"HUPE"
;
sendCommand
(
command
);
}
void
Konsole
::
on_cb_watchdog_stateChanged
(
int
arg1
)
{
if
(
arg1
){
sendCommand
(
"WDE"
);
}
else
{
sendCommand
(
"WDD"
);
}
}
void
Konsole
::
on_slider_speed_sliderMoved
(
int
position
)
{
ui
->
lb_speed
->
setText
(
QString
::
number
(
position
));
}
void
Konsole
::
on_slider_speed_sliderReleased
()
{
sendCommand
(
"SP "
+
ui
->
lb_speed
->
text
());
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment