virtual joystick, standard game controller & TXT4.0

Alles rund um TX(T) und RoboPro, mit ft-Hard- und Software
Computing using original ft hard- and software
Forumsregeln
Bitte beachte die Forumsregeln!
Antworten
vleeuwen
Beiträge: 1557
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

virtual joystick, standard game controller & TXT4.0

Beitrag von vleeuwen » 18 Jan 2022, 16:54

Example of a virtual joystick and generic game controller interface communicating with the TXT4.0 via a web socket.
Both can be used to control the fischertechnik model.
WebInterface01.JPG
WebInterface01.JPG (82.05 KiB) 3930 mal betrachtet
In this case, a wireless XBOX game controller is attached to the laptop.
I have published the web socket software on this forum before.
1) The virtual x-y joystick
2) The status of the connected game controller (0 to 4). This information can also be sent to TXT4.0
software enigineer/teacher/advisor
Google translate
http://tescaweb.nl/Carel/?p=713

Techum
Beiträge: 84
Registriert: 25 Dez 2014, 20:50
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von Techum » 23 Jan 2022, 16:28

Hello vleeuwen,

reads great!
Could You upload Your complete virtual joystick solution in the new GitLab or elsewhere?
I had a flask based approach with a JS client almost ready when I had to realize, that one cannot upload html files in the txt4.0 folder...

Would be highly appreciated!

Techum

vleeuwen
Beiträge: 1557
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von vleeuwen » 24 Jan 2022, 11:31

I will publish the code later on my own web site.
It is for the moment not possible to add additional files, like this HTML code to a RoboPro Coding project.
I publish a similar project a couple of year ago for the TXT with a RoboPro SLi extension.
The joystick and the game control connector are the same.
software enigineer/teacher/advisor
Google translate
http://tescaweb.nl/Carel/?p=713

vleeuwen
Beiträge: 1557
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von vleeuwen » 24 Jan 2022, 22:00

@Technum
This results of the two introduction project are available at
http://tescaweb.nl/Carel/?p=713
software enigineer/teacher/advisor
Google translate
http://tescaweb.nl/Carel/?p=713

Techum
Beiträge: 84
Registriert: 25 Dez 2014, 20:50
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von Techum » 30 Jan 2022, 19:38

Hello vleeuwen,

I have had a look at your code, especially the webserver part.
ROBO Pro Coding likes to use global variables which almost seems to be a "no go" with flask. With your webserver solution this is not a problem at all.
I do not own any USB joysticks (and still hope, that fischertechnik will provide a solution for the control set), hence I was looking for a pure software solution. Ideally, it would not need to run anything on the client, but a html page is probably fine for now.
I had started from this solution: https://github.com/stemkoski/HTML-Joysticks and I already successfully transfer the x/y position of both joysticks to your webserver solution on the TXT4.0. Since I have declared the position variables global, I should be able to access them from any other little program in ROBO Pro Coding and can then use the variables for model control - not sure about Your doubts on Your website "How to to bring the data to Blockly-level?"

So far, so great.

Just an observation: The time lag is quite significant. Around half a second, rather a bit more. Currently I have the TXT4.0 connected by USB.
Have You experienced the same?

Have a nice evening!
Techum

vleeuwen
Beiträge: 1557
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von vleeuwen » 30 Jan 2022, 21:37

My closed control loops are always located on the TXT4.0 itself.
And only the control signals come from external.
The question is whether Python is the best language for Robot programming and reliable closed fast control loops.
From what I've read, Python code is 50 to 400 times slower than well-compiled C++ code. Personally, I'm not a fan of untyped programming languages. It encourages design flaws.
The overhead of a web socket with JSON is still relatively large.
For faster control, I want to experiment with a Berkely socket and a transfer area with compression in the future.
The slowness also applies to the REST API, which is also text-based.
It would be nice if Blockly enabled user-defined REST api.
I also hope that a good C++/C library will be available soon. From what I read, Python code is relatively slow compared to compiled and optimized C++/C code.
software enigineer/teacher/advisor
Google translate
http://tescaweb.nl/Carel/?p=713

Techum
Beiträge: 84
Registriert: 25 Dez 2014, 20:50
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von Techum » 10 Feb 2022, 20:23

Hello vleeuwen,

In the meantime I was able to create a fluent control of the hightech robot with a continuous control stream, which updates every 200ms.
I use your webserver approach which I start, after starting a continuous motor control thread.

In your webserver code I store the incoming Json data in global variables which the motor control thread consumes.
If you don't mind, I will upload the solution to Gitab.

Have a nice evening
Techum

vleeuwen
Beiträge: 1557
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von vleeuwen » 10 Feb 2022, 23:36

@Techum
Thanks a lot for your update about your results.
Your welcome to publish your results on GitLab/GitHub.
I think that the communication could be improved by switching to binary data or compressed data; there exist special compilers for that.
Kind regards,
Carel
software enigineer/teacher/advisor
Google translate
http://tescaweb.nl/Carel/?p=713

Techum
Beiträge: 84
Registriert: 25 Dez 2014, 20:50
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von Techum » 13 Feb 2022, 23:11

Hello Carel,

solution is public on GitLab: http://git.fischertechnik-cloud.com/FH_ ... ontrol.git
As the gitlab project contains both the ft file and the html, one cannot simply import it. Maybe I will create a second one, which only has the ft file content.
Youtube demo here: https://youtu.be/jlEjl9ScS9o

There is for sure a lot of room for improvement - I had so far never programmed nor adjusted a single line of JS before...
For our needs it works well enough, now back to model desgin ...

Have a nice evening!
Frank
Zuletzt geändert von Techum am 14 Feb 2022, 12:58, insgesamt 1-mal geändert.

Benutzeravatar
Dirk Fox
ft:pedia-Herausgeber
Beiträge: 1832
Registriert: 01 Nov 2010, 00:49
Wohnort: Karlsruhe
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von Dirk Fox » 14 Feb 2022, 00:40

Hallo Frank,

sehr schnuckelig!
Eine tolle Smartphone-Fernsteuerung... sehr cool.

Herzliche Grüße,
Dirk

Techum
Beiträge: 84
Registriert: 25 Dez 2014, 20:50
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von Techum » 15 Feb 2022, 08:09

Danke Dirk,

ich mag vor allem, dass er jetzt doch ordentlich schnell anspricht. Dabei sind bisher noch wait Befehle von 0,1s eingebaut, es geht also ganz sicher besser.
Klasse ist natürlich auch, dass man relativ leicht weitere Elemente wie den Feuerkopf ergänzen kann.

Mein Highlight ist, wie mein Sohn in bester Biathlon-Manier im Vorbeifahren die Scheiben abräumt. Der Schießvorgang wird in einem Thread ausgeführt.

Wer sich mit Mobiltelefonen auskennt:
Die Clientseitige Losung besteht ja nur aus einer einzigen HTML Seite und fünf Bildern, allerdings macht das Anzeigen der Bilder Probleme. Im Beispiel habe ich die HTML Seite direkt unter Android unter den Chrome Browserdaten gespeichert. Vermutlich geht das aber nur mit Root Rechten auf dem Phone. Hier wäre ein Tipp toll, wie man das besser macht.

Viele Grüße
Frank

vleeuwen
Beiträge: 1557
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von vleeuwen » 15 Feb 2022, 18:23

In my original solution (already publish in 2020) with virtual joystick and also the standard game control and the use of a Web socket, I put the HTML, supporting JScript module and CSS on the TXT and used the TXT webserver to make this page available.
This is also possible with the Apache web server on the TXT4.0, or simple install a Civet Webserver on the TXT4.0..
This to avoid local security problem.
The communication over the web socket is not limited to HTML but can also done with for example: local Node-Red dashboard (using the web socket node), application written in all languages that has a web socket library, etc.
software enigineer/teacher/advisor
Google translate
http://tescaweb.nl/Carel/?p=713

Techum
Beiträge: 84
Registriert: 25 Dez 2014, 20:50
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von Techum » 15 Feb 2022, 20:18

Hello Carel
vleeuwen hat geschrieben:
15 Feb 2022, 18:23
This is also possible with the Apache web server on the TXT4.0, or simple install a Civet Webserver on the TXT4.0..
This to avoid local security problem.
Possibly I misunderstand the hint, but I gave up my original approach with Flask, when I recognized, that I could not store any html code on the TXT4.0.
I do not quite understand, how You work around that problem with e.g. an Apache web server on the TXT4.0.
Clearly on the TXT with root access there was no such limitation.

Anyway, as mentioned, this web-stuff is not my domain at all and maybe the others benefit.
Have a nice evening and thanks for Your great support!

Frank

vleeuwen
Beiträge: 1557
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: virtual joystick, standard game controller & TXT4.0

Beitrag von vleeuwen » 15 Feb 2022, 20:59

I did not figure out how o change the Apache settings yet.
But it would also possible to compile a Civetweb server for the TXT4.0 and start it there under de ft-account.
The C/C++ toolchain is available on the TXT4.0 for this.
(use a different port)
For the moment I am busy with another project, extending the fischertechnik factory (not the factory4.0) RoboPro with MQTT messages so I donn't have time to try this.
software enigineer/teacher/advisor
Google translate
http://tescaweb.nl/Carel/?p=713

Antworten