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
;
47 * Global objects we need
50 OsModel::Timer::self_t timer
;
52 RoombaUart
roomba_uart(os
);
53 ControlledMotion ctrl_motion
;
56 * Sensor data we need, filled in callback
59 uint16_t capacity
, charge
;
67 * Callback that fills the sensor data when data is available
69 struct DataAvailable
{
71 sensor_data
.capacity
= roomba().capacity
;
72 sensor_data
.charge
= roomba().charge
;
73 sensor_data
.charging
= roomba().charging
;
74 sensor_data
.current
= roomba().current
;
75 sensor_data
.voltage
= roomba().voltage
;
82 int main(int argc
, char ** argv
) {
85 roomba_uart
.set_baudrate(19200);
86 roomba_uart
.enable_serial_comm();
87 roomba
.init(roomba_uart
, timer
, Roomba::BATTERY_AND_TEMPERATURE
);
89 cout
<< "Got roomba at " << roomba_uart
.address() << endl
;
91 roomba
.reset_distance();
93 ctrl_motion
.init(roomba
);
95 roomba
.register_state_callback
<DataAvailable
, &DataAvailable::cb
> (
97 roomba
.notify_state_receivers(Roomba::DATA_AVAILABLE
);
100 cout
<< "batt_charge=" << sensor_data
.charge
<< "\t batt_capacity="
101 << sensor_data
.capacity
<< "\t batt_voltage=" << sensor_data
.voltage
102 << "\t batt_current=" << sensor_data
.current
<< endl
;