turn: allow negative values for orientation input, but only positive for velocity
[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 * Global objects we need
48 */
49 OsModel::Os os;
50 OsModel::Timer::self_t timer;
51 Roomba roomba;
52 RoombaUart roomba_uart(os);
53 ControlledMotion ctrl_motion;
54
55 /**
56 * Sensor data we need, filled in callback
57 */
58 struct SensorData {
59 uint16_t capacity, charge;
60 uint8_t charging;
61 int16_t current;
62 int8_t temperature;
63 uint16_t voltage;
64 } sensor_data;
65
66 /**
67 * Callback that fills the sensor data when data is available
68 */
69 struct DataAvailable {
70 void cb(int foo) {
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;
76 }
77 } data_available;
78
79 /**
80 * main function
81 */
82 int main(int argc, char ** argv) {
83
84 // init stuff
85 roomba_uart.set_baudrate(19200);
86 roomba_uart.enable_serial_comm();
87 roomba.init(roomba_uart, timer, Roomba::BATTERY_AND_TEMPERATURE);
88
89 cerr << "Got roomba at " << roomba_uart.address() << endl;
90
91 roomba.reset_distance();
92 roomba.reset_angle();
93 ctrl_motion.init(roomba);
94
95 roomba.register_state_callback<DataAvailable, &DataAvailable::cb> (
96 &data_available);
97 roomba.notify_state_receivers(Roomba::DATA_AVAILABLE);
98
99 while(true) {
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;
103 sleep(1000);
104 }
105 }
This page took 0.061831 seconds and 5 git commands to generate.