This page provides instructions how to customise the alphabot so that it's actually usable for research and it provides a C++ API with proper setters and callbacks.
C++ class to control the basic functionality of a customised Alphabot (https://www.waveshare.com/wiki/AlphaBot) with a Raspberry PI:
- Motor control (using the Parallax Continuous Rotation Servo)
- Distance sensor readings (digital and analogue)
- Battery voltage
- IR sensor readings
- 10Hz ADC sampling rate with callback
Throw the original DC motors in the bin and fit the Parallax Continuous Rotation Servo with 90deg brackets. Plug them into the servo ports S1 and S2. This corresponds to:
GPIO27 = Motor left
GPIO22 = Motor right
De-solder the LM2596 and throw it in the bin. It supposed to have a dropout voltage of 1V so that the 7-7.2V from the battery should be fine but it seems to be more 2V. It's not even recommended by TI who recommend the LMR33630 for new designs.
Replace the LM2596 with a REC8-0505SRW/H3/A/M. Just glue it upside down on the PCB and run 4 wires to Vin and +5V.
The Raspberry PI hardware is accessed via the
pigpio
library. Install its package:
apt-get install libpigpio-dev
The demo programs below display the sensor readings with the ncurses library. Install it with
apt-get install libncurses-dev
The built system is cmake
. Just type:
cmake .
make
sudo make install
The online documentation is here: https://berndporr.github.io/alphabot/
Start the communication with the robot:
start()
Stop the communication:
stop()
Setting the speeds of the left/right wheels:
setLeftWheelSpeed(float speed);
setRightWheelSpeed(float speed);
where speed is between -1 and +1.
The digital functions are boolean values which are true if the distance sensor threshold (set with the potentiometer) has been reached:
bool getCollisionLeft();
bool getCollisionRight();
The analogue readings from the sensors from 0..1 can be read with:
float getLeftDistance()
float getRightDistance()
The function getBatteryLevel()
provides the voltage of the battery
in volt.
float (&getIR())[nIR]
returns a reference to the whole array of IR sensor readings normalised between 0..1.
Whenever a new set of analogue readings is available the callback step
in StepCallback
is called. It contains the reference to the Alphabot
class itself so that one can read the different ADC values.
testIO
is a simple test program which displays the different
senor readings and you can test the motors. It also shows
how the callback is used to display the sensor readings.
testMotor
ramps up the motor speed and back again.
obstacleAvoid.cpp
implements a Braitenberg vehicle
and it has an emergency stop if the digital readings from
the collision sensors are triggered. This is an
instructional example and needs to be tweaked. The
fun begins here! :)