{ "info": { "author": "Ya\u015far \u0130dikut, Sarp Yoel Kastro", "author_email": "yasar.idikut@hisarschool.k12.tr, sarp.kastro@hisarschool.k12.tr", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta" ], "description": "\n# PiWars Turkey 2019: Python library for the distributed robot kits by HisarCS\n\nThis python library was created for the purposes of easing the understanding between software, sensors, and movables on the robot kits designed by HisarCS for attendees of Pi Wars Turkey 2019.\n\n\n## Installation\n\nUse the following commands to install the library\n```bash \ngit clone https://github.com/HisarCS/PiWars2019.git\ncd PiWars2019\nsudo python setup.py install\n```\n\n## Usage\n\n```python\nimport HisarCSPiWars2019\n```\n\n## Documentation\n\nThe library includes 5 classes as of now these are:\n- OptimizedPiCam (for a simplified and optimized way to use the Pi Camera and OpenCV)\n- Kumanda (for an easy way to use the pygame Joystick class with the sixaxis PS3 controller)\n- MotorControl (for an easy way to use the Pololu DRV8835 motor control circuit for the Raspberry Pi with a controller)\n- ServoControl (for a simple way to use servo motors on the Raspberry Pi using GPIO pins)\n- UltrasonicSensor (for an easy way to use HC-SR04 ultrasonic distance sensors on the Raspberry Pi)\n\nFor the purposes of performance, some of the classes include multithtreading. This prevents some parts of the code to not have an effect on other parts of the code. Multithreading was especially implemented to OptimizedPiCam (for both grabbing and showing the frames), Controller (to get the controller values continuously), ServoControl(to prevent any sleep function in the class to affect the main thread).\n\nOptimizedPiCam:\n-\n- Methods\n```python\nupdateData()\n```\nUpdates the data obtained from the Pi Camera.\n\n```python\nstartReadingData()\n```\nCreates a new Thread to call ``` updateData()``` in order to update the data without slowing down the main thread.\n\n```python\nreadData()\n```\nReturns the current data of the camera as a numpy array.\n\n```python\nupdateShownFrame()\n```\nCreates and updates the opencv window that shows the image the Pi Camera is seeing. The \"q\" key can be used to close the window.\n\n```python\nshowFrame()\n```\nCalls ``` updateShownFrame()``` in a new Thread to create a visual window without slowing down the main thread.\n\n- Example Usage\n```python\nfrom HisarCSPiWars2019 import OptimizedPiCam\n\ncamera = OptimizedPiCam()\ncamera.startReadingData()\ncamera.showFrame()\n```\nThe above example creates a new OptimizedPiCam object and uses it to show the image the camera is seeing until the \"q\" key is pressed. \n\nThe default resolution of 640x480 for camera is set when the constructor is called. If you want a different resolution settings, for instance 1280x720 ,then set the camera object as follows:\n ``` camera = OptimizedPiCam(resolution=(1280, 720))```\n\nKeep in mind that the data has to be received using ``` camera.startReadingData()``` with ``` camera.readData()``` or ``` camera.currentFrame``` , if further vision processing is wanted. ``` camera.currentFrame``` is the current frame variable in numpy array, where the function ``` camera.readData()``` returns variable ``` camera.currentFrame```. \n\nThe below example code will grab the frame from the camera in numpy array format, grayscale it, and display the frames in the **main thread**.\n```python\nfrom HisarCSPiWars2019 import OptmizedPiCam\nimport cv2\n\ncamera = OptimizedPiCam()\ncamera.startReadingData()\n\nwhile True:\n\tframe = camera.readData()\n\tgray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n\tcv2.imshow(\"gray\", gray)\n```\nWheras in the example below, the grayscaled frames are both grabbed and displayed in **different threads**, **not in the main thread**. This method is strongly encouraged to increase the performance as much as possible.\n```python\nfrom HisarCSPiWars2019 import OptimizedPiCam\nimport cv2\n\ncamera = OptimizedPiCam()\ncamera.startReadingData()\ncamera.showFrame()\n\nwhile True:\n\tframe = camera.currentFrame\n\tgray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n\tcamera.suAnkiKare = gray\n```\nKumanda\n-\n- Methods\n```python\nrefresh()\n```\nRefreshes the values obtained from the controller inside a while loop. **Not recommended** to call in the main thread since the program will stuck in this method.\n\n```python\nstartListening()\n```\nCalls ```python refresh()``` in a new thread. Allowing the while loop of the main thread to be faster. \n\n```python\nreadLeftValues()\n```\nReturns the values of the left joystick of the controller as two float values, x and y.\n\n```python\nreadRightValues()\n```\nReturns the values of the right joystick of the controller as two float values, x and y.\n\n```python\nreadButtons()\n```\nReturns an array of the numerical values of all the buttons pressed.\n\n```python\nreadData()\n```\nReturns all values of the controller ```(python readLeftValues(), python readRightValues(), python readButtons())```\n\n- Example Usage\n```python\nimport HisarCSPiWars2019\n\ncontroller = HisarCSPiWars2019.Controller()\ncontroller.startListening()\n\nwhile True:\n lx, ly = controller.readLeftValues()\n rx, ry = controller.readRightValues()\n buttons = controller.readButtons()\n\n print(\"The left joystick values are: \", lx, ly)\n print(\"The right joystick values are: \", rx, ry)\n\n if(0 in buttons):\n print(\"Button 0 was pressed!\")\n```\nThe above code initializes a Kumanda object and prints the values from the left and right joysticks, as well as a set string when a button is pressed. Keep in mind that ```python startListening()``` has to be called once when the main code is executed, or the data won't be read from the controller.\n\nMotorControl\n-\n- Methods -\n```python\nsetSpeeds(rightSpeed, leftSpeed)\n```\nSets the speeds of the motors using the pololu-drv8835-rpi library. The range for the speeds are -480 to 480 where -480 is maximum speed in reverse. The right and left speeds are for motor 1 and motor 2 depending on which side they are on.\n\n```python\ncontrollerDataToMotorSpeed(x, y, t)\n```\nReturns the speed for the motor according to the values of a joystick from the controller. x and y are the x and y values of the joystick and t is a boolean value with True for the right motor and False for the left motor.\n\n- Example Usage\n```python\nimport HisarCSPiWars2019\nmotors = HisarCSPiWars2019.MotorControl()\n\nwhile True:\n motors.setSpeeds(480, 480)\n```\nThis code initializes motors and sets both of them to max speed.\n\n- Example Usage w/ Controller\n```python\nimport HisarCSPiWars2019\n\nmotors = HisarCSPiWars2019.MotorControl()\n\ncontroller = HisarCSPiWars2019.Controller()\ncontroller.startListening()\n\nwhile True:\n lx, ly = controller.readLeftValues()\n rightSpeed = motors.controllerDataToMotorSpeed(lx, -ly, True)\n leftSpeed = motors.controllerDataToMotorSpeed(lx, -ly, False)\n\n motors.setSpeeds(rightSpeed, leftSpeed)\n```\nThe above code initializes the motors and the controller and goes into a while loop. Inside the loop, the ```controllerDataToMotorData()```function is used to get the speed values for the motors. The y value is set to negative because on PS3 controllers specifically forwards on the joystick returns negative values. \n\nServoControl\n-\n- Methods -\n```python\nsetToContinuous()\nsetToNotContinuous()\n```\nSwitches the servo from continous and not continuous respectively. Continuous requires dynamic values to be provided while not continuous turns the servo between provided angles.\n\n```python\nsetAngle(angle)\n```\nTurns the servo to the provided angle in degrees. Provides a sleep statement and a separate thread when the servo is set to not continuous. \n\n- Example Usage -\nContinuous:\n```python\nservo = HisarCSPiWars2019.ServoControl()\nservo.setToContinuous()\n\nangle = 0\nadd = 0\nwhile True:\n servo.setAngle(angle)\n\n if(angle == 180):\n add = -1\n elif(angle == 0):\n add = 1\n angle += add\n sleep(0.01)\n```\nIn this case, the servo is set to continuous. A while loop is used to constantly change the angle of the servo by 1 and set the new angle.\n\n- Example Usage -\nNon-Continuous:\n```python\nimport HisarCSPiWars2019\nfrom time import sleep\n\nservo = HisarCSPiWars2019.ServoControl()\nservo.setToNotContinuous()\n\nwhile True:\n servo.setAngle(180)\n sleep(1)\n servo.aetAngle(0)\n sleep(1)\n```\nIn this case, the servo is set to non-continuous. A while loop is used to set the angle of servo with one minute sleeps\n\nUltrasonicSensor\n-\n- Methods \n```python\ngetDistance()\n```\nReturns the distance measured by the ultrasonic sensor\n\n- Example Usage\n```python\nultra = HisarCSPiWars2019.UltrasonicSensor(38, 40)\n\nwhile True:\n print(ultra.getDistance())\n```\nThe code above prints the distance. The integers inside the initializer for the class are the pins it is attached to.\n\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "HisarCSPiwars2019", "package_url": "https://pypi.org/project/HisarCSPiwars2019/", "platform": "", "project_url": "https://pypi.org/project/HisarCSPiwars2019/", "project_urls": null, "release_url": "https://pypi.org/project/HisarCSPiwars2019/0.9.5/", "requires_dist": null, "requires_python": "", "summary": "Library that makes use of sensors, motors, and servos made for the PiWars competition by HisarCS", "version": "0.9.5" }, "last_serial": 4765198, "releases": { "0.9.5": [ { "comment_text": "", "digests": { "md5": "e8fd45e379275e99a84ea573ac827243", "sha256": "773ee30c9bf19d6bb4a7a41d82731b6a73d49de40961dd306a653ba765b37fba" }, "downloads": -1, "filename": "HisarCSPiwars2019-0.9.5-py3-none-any.whl", "has_sig": false, "md5_digest": "e8fd45e379275e99a84ea573ac827243", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7423, "upload_time": "2019-01-31T19:50:46", "url": "https://files.pythonhosted.org/packages/7e/6a/277eb79696b417da695fa3ce0746be54be4af63dcd134dfe9f88b2714b1b/HisarCSPiwars2019-0.9.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "faf548e5e1b465db1a59d4919634b5a0", "sha256": "8eff4eb9c19d63cebb349ed237fb73d3019aec0584f4067c140071bf1cd4565d" }, "downloads": -1, "filename": "HisarCSPiwars2019-0.9.5.tar.gz", "has_sig": false, "md5_digest": "faf548e5e1b465db1a59d4919634b5a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6405, "upload_time": "2019-01-31T19:50:49", "url": "https://files.pythonhosted.org/packages/bc/2d/7c0c41f7dd99d1c1e0686827629e9ffa7418d9a7b949a36a481a56860df8/HisarCSPiwars2019-0.9.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e8fd45e379275e99a84ea573ac827243", "sha256": "773ee30c9bf19d6bb4a7a41d82731b6a73d49de40961dd306a653ba765b37fba" }, "downloads": -1, "filename": "HisarCSPiwars2019-0.9.5-py3-none-any.whl", "has_sig": false, "md5_digest": "e8fd45e379275e99a84ea573ac827243", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7423, "upload_time": "2019-01-31T19:50:46", "url": "https://files.pythonhosted.org/packages/7e/6a/277eb79696b417da695fa3ce0746be54be4af63dcd134dfe9f88b2714b1b/HisarCSPiwars2019-0.9.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "faf548e5e1b465db1a59d4919634b5a0", "sha256": "8eff4eb9c19d63cebb349ed237fb73d3019aec0584f4067c140071bf1cd4565d" }, "downloads": -1, "filename": "HisarCSPiwars2019-0.9.5.tar.gz", "has_sig": false, "md5_digest": "faf548e5e1b465db1a59d4919634b5a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6405, "upload_time": "2019-01-31T19:50:49", "url": "https://files.pythonhosted.org/packages/bc/2d/7c0c41f7dd99d1c1e0686827629e9ffa7418d9a7b949a36a481a56860df8/HisarCSPiwars2019-0.9.5.tar.gz" } ] }