Skip to content

Ivo/keybaord controller#173

Merged
thias15 merged 14 commits into
ob-f:masterfrom
izivkov:ivo/keybaord-controller
Apr 10, 2021
Merged

Ivo/keybaord controller#173
thias15 merged 14 commits into
ob-f:masterfrom
izivkov:ivo/keybaord-controller

Conversation

@izivkov

@izivkov izivkov commented Apr 2, 2021

Copy link
Copy Markdown
Contributor

Added a python program to act as a controller. This program can run on a Linux-based computer (including Raspberry PI) and allow the user to control the robot from the keyboard. Can be used for fast prototyping of new commands, or as a controller from wireless keyboard.

Has not been tested on Windows, but should run as well.

@thias15

thias15 commented Apr 6, 2021

Copy link
Copy Markdown
Collaborator

This is great. Just one comment, I feel like the control is not very natural. If the keyboard button is released, I would expect throttle to be lowered until 0. Similar with the steering.

@izivkov

izivkov commented Apr 6, 2021

Copy link
Copy Markdown
Contributor Author

This is great. Just one comment, I feel like the control is not very natural. If the keyboard button is released, I would expect throttle to be lowered until 0. Similar with the steering.

Ok, this is good idea. I will work on this. I will have an update soon, so maybe wait for that.

@thias15

thias15 commented Apr 6, 2021

Copy link
Copy Markdown
Collaborator

Ok, I will wait and then merge. Another question. Is there any difference between the connection to the Python script and the phone controller now? I'm wondering if we should update the UI to have one more controller option or maybe swap the phone icon for something more generic.

@izivkov

izivkov commented Apr 6, 2021

Copy link
Copy Markdown
Contributor Author

Ok, I will wait and then merge. Another question. Is there any difference between the connection to the Python script and the phone controller now? I'm wondering if we should update the UI to have one more controller option or maybe swap the phone icon for something more generic.

The python script uses the exact same connection as the android controller does. It locates services on the LAN by service name and type. Both controller and robot app have to be on the same LAN. So, we can call the controller something like WiFi controller, or something like this. But I am not sure the python script will be used a lot outside of prototyping. Maybe for Raspberry PI the controller could me more useful.

There is also something called pygame, which allows you to create UI in python for games, so this maybe useful

@izivkov

izivkov commented Apr 6, 2021

Copy link
Copy Markdown
Contributor Author

This is great. Just one comment, I feel like the control is not very natural. If the keyboard button is released, I would expect throttle to be lowered until 0. Similar with the steering.

One concern I have is how to make the bot run at a constant speed? If we stop pressing the up arrow, the robot will slow down and stop. With the dual drive controls, we can leave them the bot will move at the same speed, but if we let go the keyboard, the robot will stop. On the other hand, if we keep pressing the keyboard, the robot will accelerate.

I can see if we stop pressing the left/right arrows, the robot will stop turning, so this makes sence.

@thias15

thias15 commented Apr 7, 2021

Copy link
Copy Markdown
Collaborator

But even for the phone controller we discussed that it would be nice for the sliders to bounce back if the user releases them. Same logic, it is not very natural to manually move the sliders back down. I think to keep the button/slider pressed to keep a constant speed is expected. It is the same way the bot is controller with the BT controller and pretty much in any video game. For keeping constant speed, we could just have a cruise control key. If you press it, we will keep the same speed until it is pressed again.

@thias15

thias15 commented Apr 7, 2021

Copy link
Copy Markdown
Collaborator

I think using pygame or even just vlc player to get the video stream on the laptop would be very nice.

@izivkov izivkov force-pushed the ivo/keybaord-controller branch from eb9206f to 453be24 Compare April 8, 2021 01:33
@izivkov

izivkov commented Apr 8, 2021

Copy link
Copy Markdown
Contributor Author

Now the controls on the keyboard-controller revert back to 0/0 in steps within 4 seconds after the user stops pressing the arrow keys .

@thias15

thias15 commented Apr 10, 2021

Copy link
Copy Markdown
Collaborator

Great, I will test it again. I think one second would be enough to stop the car. Four seconds seems quite long if someone needs to stop the car. What do you think? I also noticed that you also removed the flashlight control from the controller app. Did you not get this to work?

@thias15 thias15 merged commit f6b174c into ob-f:master Apr 10, 2021
@thias15

thias15 commented Apr 10, 2021

Copy link
Copy Markdown
Collaborator

Hi @izivkov. I have merged the PR now. Again, thank you very much for your contribution. I feel that the control is still not very natural. In most video games, you would expect that the car will go a full speed when pressing the forward button and stop (coast) once you release the button. Similarly for turning left and right, but if the forward button is still pressed the car would be expected to continue driving forward instead of controls going to 0. I wonder if it would be easier to implement with callbacks on key_pressed and key_release. I came across this library. What do you think?

Another thing we could do is just provide throttle and steering to the bot and use the functions in the GameController to convert to the left and right control values. But I guess the challenge with the keyboard is that everything is binary, either pressed or release.

@izivkov

izivkov commented Apr 10, 2021 via email

Copy link
Copy Markdown
Contributor Author

@izivkov

izivkov commented Apr 10, 2021 via email

Copy link
Copy Markdown
Contributor Author

lacykaltgr pushed a commit to satinavrobotics/SatiBot that referenced this pull request Jun 1, 2025
* Added a python example on how to connect and communicate to the smartphone app from a Raspberry Pi.
* Added python script `keyboard-controller.py` to control the robot remotely.
* Updated README file.

Co-authored-by: Ivo Zivkov <ivo.zivkov2@ontario.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants