e884c42f12c516c88719f30084875362f3b2c8b2
[bachelor-thesis/roomba_tests.git] / battery_test.cc
1 /**
2 * @file battery_test.cc
3 * @date 1 Dec 2010
4 * @author Roland Hieber <rohieb@rohieb.name>
5 *
6 * Application that writes the Roomba's battery status to stdout repeatedly.
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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
24 * THE SOFTWARE.
25 */
26
27 #include <iostream>
28 #include <stdint.h>
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>
34
35 using namespace std;
36
37 // UART port on which we communicate with the Roomba
38 char uart[] = "/dev/ttyUSB0";
39
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;
45
46 /**
47 * main function
48 */
49 int main(int argc, char ** argv) {
50
51 OsModel::Os os;
52 OsModel::Timer::self_t timer;
53 Roomba roomba;
54 RoombaUart roomba_uart(os);
55 ControlledMotion ctrl_motion;
56
57 // init stuff
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);
62
63 cout << "Got roomba at " << roomba_uart.address() << endl;
64
65 roomba.reset_distance();
66 roomba.reset_angle();
67 ctrl_motion.init(roomba);
68
69 while(true) {
70 cout << "batt_charge=" << roomba().charge << " batt_capacity="
71 << roomba().capacity << " batt_voltage=" << roomba().voltage
72 << " batt_current=" << roomba().current << endl;
73 sleep(1);
74 }
75 }
This page took 0.038152 seconds and 3 git commands to generate.