Commit fdb0d76d authored by Douglas Gore's avatar Douglas Gore Committed by Gogs

Merge branch 'mgall/1' of picymru/webbot into master

parents 3d168648 31047b72
NAME := webbot
.PHONY: install
install:
pip3 install -r requirements.txt
\ No newline at end of file
Browser controlled robot
========================
# webbot - A simple browser controlled robot
This is a very simple Python based robot project for the Raspberry Pi designed for use with the Cam Jam 3 robotics kit. Using gpiozero and CherryPy the program will host it's own web page which can be used to control the robot.
Hardware required:
- Raspberry Pi
- CamJam EduKit 3 robotics kit
- Official Raspberry Pi camera (optional but recommended)
- Wi-Fi connection
## Kit
- [Raspberry Pi](https://thepihut.com/collections/raspberry-pi/products/raspberry-pi-3-model-b)
- [CamJam EduKit 3 - Robotics Kit](https://thepihut.com/products/camjam-edukit-3-robotics)
- [Official Raspberry Pi Camera](https://thepihut.com/collections/raspberry-pi-camera/products/raspberry-pi-camera-module) (optional but recommended)
- Wi-Fi connection (Built into the Raspberry Pi 3), or Ethernet connection
Software required:
- CherryPy Python module
- gpiozero Python module
## Installation
We've made installing everything you need to get started with our browser controlled robot easy!
Cherry Py can be installed with the following command:
pip3 install cherrypy
git clone https://codedin.wales/picymru/webbot.git
cd webbot
make install
The gpiozero module comes pre-installed on recent Raspbian releases but can be installed manually if not available with the following command:
sudo apt-get install python3-gpiozero
## Usage
Running the project is easy. From your Raspberry Pi command line, run the following:
You can run the project from the command line simply by typing:
python3 webbot.py
python3 webbot.py
Once running you can connect to the robot from any web browser on the same network as the robot. If your Raspberry Pi has the default network settings you can access it at the following URL:
Once running, the software will display a web address for you to connect to from any web browser connected to the same network as your robot! If your Raspberry Pi has the default network settings you can access it at the following URL:
http://raspberrypi.lan:8080/static/index.html
Once connected you can use the following keys on your keyboard to control the robot:
### Control
Once connected in your browser, by default, you can use the following keys on your keyboard to control the robot:
- Arrow keys for forwards, backwards, left turn and right turn
- 'c' key to capture and display an image from the camera if connected
- 'u' key to turn on/off an ultrasonic distance measurement every 2 seconds
This project has been developed by PiCymru as part of our education and learning programme. We are happy for you to use and adapt this project to your needs but please provide attribution as required.
## License
If you do use this project or have any feedback we would love to hear from you, tweet us at @PiCymru or e-mail us at [email protected]
This project has been developed by PiCymru as part of our education and learning programme. This project is hereby released under the terms of the MIT License, and is included below
A big thanks to Tim Richardson & Mike Horne for the fantastic CamJam 3 and Ben Nuttall and the gpiozero team for such a simple library.
MIT License
Copyright (c) 2016 PiCymru
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
Visit us at http://picymru.org.uk/
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
## Support
Have a question? Need assistance? Don't stay stuck! If you do use this project or have any feedback we would love to hear from you, tweet us at [@PiCymru](https://twitter.com/PiCymru) or drop us an [e-mail](mailto:[email protected])
## Thanks
A big thanks to Tim Richardson & Mike Horne for the fantastic CamJam 3 and Ben Nuttall and the gpiozero team for such a simple library.
cherrypy
gpiozero
\ No newline at end of file
# Web controlled robot by PiCymru (@picymru / http://picymru.org.uk)
#!/usr/bin/env python3
##
# webbot - A browser controlled robot! Your little frIEnd.
##
# Copyright (c) 2016 PiCymru
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import subprocess
import time
import os
import socket
import cherrypy
from gpiozero import Robot, DistanceSensor
robot = Robot(left=(10, 9), right=(8, 7))
......@@ -64,9 +84,13 @@ if __name__ == '__main__':
}
}
robot.stop()
cherrypy.config.update({'server.socket_host': '0.0.0.0'})
cherrypy.config.update({'server.socket_host': os.getenv('IP', '0.0.0.0')})
# We'll make life easy, and detect the LAN IP to show you where to visit!
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 1))
print("Web controlled robot by PiCymru")
print("Control me from: " + cherrypy.url() + "/static/index.html")
print("Want to control me? In your browser, visit http://{}:8080/static/index.html".format(s.getsockname()[0]))
cherrypy.quickstart(WebControl(), '/', conf)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment