From 7682d848008691dd9c01b5b1b2663dfd8c2952cc Mon Sep 17 00:00:00 2001 From: svnhieber Date: Wed, 1 Dec 2010 21:09:16 +0000 Subject: [PATCH] battery_test.cc: Application that writes the Roomba's battery status to stdout repeatedly git-svn-id: https://svn.itm.uni-luebeck.de/wisebed/wiselib/trunk/pc_apps/roomba_tests@3660 f8795833-4959-0410-8ae9-8bcb0cfab428 --- Makefile | 3 ++ battery_test.cc | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 battery_test.cc diff --git a/Makefile b/Makefile index be04c1b..752a33f 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,6 @@ export CXXFLAGS=-I/usr/include/qt4 -I/usr/include/qt4/QtCore \ -I/usr/include/QtGui -lQtGui include ../Makefile.base + +battery_test: battery_test.cc + $(CXX) -I$(WISELIB_STABLE) -I$(WISELIB_TESTING) -lpthread -o battery_test battery_test.cc diff --git a/battery_test.cc b/battery_test.cc new file mode 100644 index 0000000..e884c42 --- /dev/null +++ b/battery_test.cc @@ -0,0 +1,75 @@ +/** + * @file battery_test.cc + * @date 1 Dec 2010 + * @author Roland Hieber + * + * Application that writes the Roomba's battery status to stdout repeatedly. + * + * Permission is hereby granted, free of charge, to any person obtaining + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +// UART port on which we communicate with the Roomba +char uart[] = "/dev/ttyUSB0"; + +typedef wiselib::PCOsModel OsModel; +typedef wiselib::StandaloneMath Math; +typedef wiselib::PCComUartModel RoombaUart; +typedef wiselib::RoombaModel Roomba; +typedef wiselib::ControlledMotion ControlledMotion; + +/** + * main function + */ +int main(int argc, char ** argv) { + + OsModel::Os os; + OsModel::Timer::self_t timer; + Roomba roomba; + RoombaUart roomba_uart(os); + ControlledMotion ctrl_motion; + + // init stuff + roomba_uart.set_baudrate(19200); + roomba_uart.enable_serial_comm(); + roomba.init(roomba_uart, timer, Roomba::POSITION + | Roomba::BATTERY_AND_TEMPERATURE); + + cout << "Got roomba at " << roomba_uart.address() << endl; + + roomba.reset_distance(); + roomba.reset_angle(); + ctrl_motion.init(roomba); + + while(true) { + cout << "batt_charge=" << roomba().charge << " batt_capacity=" + << roomba().capacity << " batt_voltage=" << roomba().voltage + << " batt_current=" << roomba().current << endl; + sleep(1); + } +} -- 2.20.1