2 * @file battery_test.cc
4 * @author Roland Hieber <rohieb@rohieb.name>
6 * Application that writes the Roomba's battery status to stdout repeatedly.
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 #include <external_interface/pc/pc_os_model.h>
30 #include <external_interface/pc/pc_com_uart.h>
31 #include <external_interface/pc/pc_timer.h>
32 #include <intermediate/robot/roomba/roomba.h>
33 #include <intermediate/robot/controlled_motion.h>
37 // UART port on which we communicate with the Roomba
38 char uart
[] = "/dev/ttyUSB0";
40 typedef wiselib::PCOsModel OsModel
;
41 typedef wiselib::StandaloneMath Math
;
42 typedef wiselib::PCComUartModel
<OsModel
, uart
> RoombaUart
;
43 typedef wiselib::RoombaModel
<OsModel
, RoombaUart
> Roomba
;
44 typedef wiselib::ControlledMotion
<OsModel
, Roomba
> ControlledMotion
;
49 int main(int argc
, char ** argv
) {
52 OsModel::Timer::self_t timer
;
54 RoombaUart
roomba_uart(os
);
55 ControlledMotion ctrl_motion
;
58 roomba_uart
.set_baudrate(19200);
59 roomba_uart
.enable_serial_comm();
60 roomba
.init(roomba_uart
, timer
, Roomba::POSITION
61 | Roomba::BATTERY_AND_TEMPERATURE
);
63 cout
<< "Got roomba at " << roomba_uart
.address() << endl
;
65 roomba
.reset_distance();
67 ctrl_motion
.init(roomba
);
70 cout
<< "batt_charge=" << roomba().charge
<< " batt_capacity="
71 << roomba().capacity
<< " batt_voltage=" << roomba().voltage
72 << " batt_current=" << roomba().current
<< endl
;