Package: onepi
bnronepiPython library to interface with Bot'n Roll One A.1. Installation:1.1. Setup Raspberry Pi:If you already have a Raspberry Pi setup with SPI and I2C enabled please skip to step 1.21.2. Install onepi library:You can chose to install the onepi library by following one of the two options listed below.1.2.1 Install using pip (option 1):pip3installonepi1.2.1 Install form github (option 2):mkdir~/src;cd~/srcgitclonehttps://github.com/ninopereira/bnronepi.git# or download and extract zip filecdbnronepi-mainpythonsetup.pysdistpipinstall.1.3. TroubleshootingIf you find an error when installing matplotlitb you might need to install the Open Blas library:sudoapt-getinstalllibopenblas-dev2. Usage:Simple example:
Displays a message "Hello Pi!" on the robot lcd.fromonepi.oneimportBnrOneAone=BnrOneA(0,0)# object variable to control the Bot'n Roll ONE Aone.stop()# stop motorsone.lcd1(" Hello Pi! ")# print data on LCD line 13. ExamplesYou can find lots of examples in the examples folder.
It contains several complete programs to allow you to take the most out of Bot'n Roll One A robot.All the examples are documented and easy to follow.
You can use them as a starting point for your applications.3.1 basicThe basic folder contains a series of examples for you to interact with the hardware of the Bot'n Roll One A.The list includes examples such as:battery: displays the battery level and sets the minum valuebuzzer: plays a short tunelcd: displays a message using both lines of the lcdled: blinks the yellow LED on the robotmotors: moves the motors in a variety of wayspush_buttons: reads and displays the button pressed by the user3.2 advancedThe advanced folder contains a set of examples which are just a bit more advanced relatively to the basic examples.
These include:compass_calibration: used to calibrate the CMPS11 compassir_sensors: shows how to enable and read ir_sensors for obstacle detectionmotors_calibration: to calibrate the minimum torque for the motorsstart_race_detection: example to detect the start signal for the race of champions challenge (seehttps://www.roboparty.org).3.3 extraThe extra folder comtains examples used by extra hardware you may wish to complement your robot with.
The examples provided include:compass_read: to read bearing, pitch and roll from the CMPS11 compass via I2C busgripper: to control the gripper by using PMW signalsservos: to control a couple of servos you may wish to attachsonar: to read the distance from a sonar HC-SR04 attached to the robot3.4 line_sensorInside the line_sensor folder there are many examples for you to use and learn with.01_sensor_read: reads and displays raw sensor values from the line sensor02_line_follow: simple example showing how to use sensor readings to drive the robot and follow the back line.03_1_line_read_weight: reads and averages the top values read from the line sensor03_2_line_follow_weight: drives the robot to follow a line using average weight from the sensor03_3_line_follow_weight_lin: drives the robot by applying a linear gain04_1_line_calibration: routine to calibrate the line sensor04_2_line_read_linear: displays the sensor reading in the range [-100: 100]04_3_line_follow_linear: drives the robot to follow the line using a linear gain04_4_line_follow_wave: drives the robot to follow the line using a wave control04_5_line_follow_pid: drives the robot to follow the line using a pid controller3.5 obstacles_sensorThe obstacles_sensor folder contains examples to use for obstacle detection and avoidance, namely:01_emitters_on_off: to turn on/off the ir emitters02_obstacles_read: reads and displays a different value depending on which sensor(s) are detecting obstacles03_obstacles_avoidance: runs the robot by avoiding obstacles3.6 fun_challengeRoutines useful for the fun challenge (seehttps://www.roboparty.org).fun_challenge_delays: sets a timer to control the duration of the challengestart_end_fun_challenge: routines to start timer and stop the robot on timeoutfun_challenge_state_machine: implements a state machine with different actions for the robot.4. TestsThe tests folder contains useful routines to test all the public methods of the packet and also for the additional libraries it uses (see utils folder).4.1 test_onepiTo run all the tests in test_onepi run:pytesttest_onepi.py-sOptionally you can choose to run individual tests by using the -k option, e.g.pytesttest_onepi.py-s-ktest_obstacle_sensorsThese tests require you to use the robot and interact with it.
Some of them require you to reboot it so it's better if you can just run the individually run the tests you're looking for instead of running them all at once.4.2 test_line_detectorThe test line detector contains a suite of tests to test the public interfaces of the class LineDetector.
To run all tests:pytesttest_line_detector.py-s4.3 test_configThe test config exercises all the public interfaces of the class Config used to store the relevant config values for line detection.5. CalibrationYou should calibrate your robot before using it. This is not mandatory as it comes with working default values but it is always good to run the calibration in order to take the most out of your particular hardware.5.1 calibrate motorsTo calibrate the motors you need to run examples -> advanced -> motors_calibration.py
Just place the robot on the floor, run the code and follow the instructions.5.2 calibrate line sensorTo calibrate the line sensors place the robot on top of a black line making sure the line is in the middle of the sensor to start with.
Run the program in examples -> line_sensor -> 04_1_line_calibration.py and follow the instructions.
The final configuration is saved in utils -> config.json.
In this case you can choose to do a simple or full calibration.
The simple calibration only stores the minimum and maximum values for each sensor whereas the full calibration also allows you to chose the threshold and correction factor. For more information please read the description in 04_1_line_calibration.py.5.3 calibrate compassIf you're using a CMPS11 you should calibrate it using the routine available in examples -> advanced -> compass_calibration.py.
Place the robot on a flat surface, making sure it has enough room to rotate on the spot and execute the program following the instructions.6. UtilsThe utils folder contains additional libraries used by onepi.py. These are essential for the normal functioning of the main packet. You should not modify, delete, rename or move these files. Note that the config.json file can be modified directly but that is not recommended. Instead you should use the 04_1_line_calibration routine in the examples -> line_sensor folder.7. DiagnosticsThe diagnostics folder contains useful tools to visualise and diagnose problems.7.1 plot_line_sensorYou can test the line sensor and visualise the raw readings from the sensors in a column type chart. Just place the robot on top of a black line and execute plot_line_sensor.py from the diagnostics folder.
In the title you can see the value of the line that gets output from the line_detector.7.2 simulate_gaussianThe simulate_gaussian program simulates a discretised gaussian reading which emulates the expected raw readings from the sensors.
The emulated readings change from the lowest range all the way up to the top range of expected values.
It then passes them through the line_detector. We can visualise both the generated sensor readings and the computed line by the line detector in the charted plot.