forked from compAIR/libcreate
Cleanup examples
Signed-off-by: Jacob Perron <jacobmperron@gmail.com>
This commit is contained in:
parent
eaeea24a21
commit
dff0308b1b
8 changed files with 69 additions and 153 deletions
|
@ -47,10 +47,10 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
// Construct robot object
|
||||
create::Create* robot = new create::Create(model);
|
||||
create::Create robot(model);
|
||||
|
||||
// Connect to robot
|
||||
if (robot->connect(port, baud))
|
||||
if (robot.connect(port, baud))
|
||||
std::cout << "Connected to robot" << std::endl;
|
||||
else {
|
||||
std::cout << "Failed to connect to robot on port " << port.c_str() << std::endl;
|
||||
|
@ -58,17 +58,15 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
// Switch to Full mode
|
||||
robot->setMode(create::MODE_FULL);
|
||||
|
||||
std::cout << std::endl << "Press center 'Clean' button to disconnect and end program" << std::endl;
|
||||
robot.setMode(create::MODE_FULL);
|
||||
|
||||
// Get battery capacity (max charge)
|
||||
const float battery_capacity = robot->getBatteryCapacity();
|
||||
const float battery_capacity = robot.getBatteryCapacity();
|
||||
|
||||
float battery_charge = 0.0f;
|
||||
while (!robot->isCleanButtonPressed()) {
|
||||
while (true) {
|
||||
// Get battery charge
|
||||
battery_charge = robot->getBatteryCharge();
|
||||
battery_charge = robot.getBatteryCharge();
|
||||
|
||||
// Print battery percentage
|
||||
std::cout << "\rBattery level: " << (battery_charge / battery_capacity) * 100.0 << "%";
|
||||
|
@ -76,14 +74,5 @@ int main(int argc, char** argv) {
|
|||
usleep(100000); // 10 Hz
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
// Call disconnect to avoid leaving robot in Full mode
|
||||
robot->disconnect();
|
||||
|
||||
// Clean up
|
||||
delete robot;
|
||||
|
||||
std::cout << "Bye!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue