Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions examples/battery_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,32 @@ 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;
return 1;
}

// 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 << "%";

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;
}
47 changes: 18 additions & 29 deletions examples/bumpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,46 @@ 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;
return 1;
}

// 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);

uint16_t light_signals[6];
bool light_bumpers[6];
bool contact_bumpers[2];

while (!robot->isCleanButtonPressed()) {
while (true) {
// Get light sensor data (only available for Create 2 or later robots)
if (model == create::RobotModel::CREATE_2) {
// Get raw light signal values
light_signals[0] = robot->getLightSignalLeft();
light_signals[1] = robot->getLightSignalFrontLeft();
light_signals[2] = robot->getLightSignalCenterLeft();
light_signals[3] = robot->getLightSignalCenterRight();
light_signals[4] = robot->getLightSignalFrontRight();
light_signals[5] = robot->getLightSignalRight();
light_signals[0] = robot.getLightSignalLeft();
light_signals[1] = robot.getLightSignalFrontLeft();
light_signals[2] = robot.getLightSignalCenterLeft();
light_signals[3] = robot.getLightSignalCenterRight();
light_signals[4] = robot.getLightSignalFrontRight();
light_signals[5] = robot.getLightSignalRight();

// Get obstacle data from light sensors (true/false)
light_bumpers[0] = robot->isLightBumperLeft();
light_bumpers[1] = robot->isLightBumperFrontLeft();
light_bumpers[2] = robot->isLightBumperCenterLeft();
light_bumpers[3] = robot->isLightBumperCenterRight();
light_bumpers[4] = robot->isLightBumperFrontRight();
light_bumpers[5] = robot->isLightBumperRight();
light_bumpers[0] = robot.isLightBumperLeft();
light_bumpers[1] = robot.isLightBumperFrontLeft();
light_bumpers[2] = robot.isLightBumperCenterLeft();
light_bumpers[3] = robot.isLightBumperCenterRight();
light_bumpers[4] = robot.isLightBumperFrontRight();
light_bumpers[5] = robot.isLightBumperRight();
}

// Get state of bumpers
contact_bumpers[0] = robot->isLeftBumper();
contact_bumpers[1] = robot->isRightBumper();
contact_bumpers[0] = robot.isLeftBumper();
contact_bumpers[1] = robot.isRightBumper();

// Print signals from left to right
std::cout << "[ " << light_signals[0] << " , "
Expand All @@ -113,14 +111,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;
}
26 changes: 8 additions & 18 deletions examples/cliffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -59,16 +59,14 @@ int main(int argc, char** argv) {
}

// Switch to Full mode
robot->setMode(create::MODE_FULL);
robot.setMode(create::MODE_FULL);

std::cout << std::endl << "Press center 'Clean' button to disconnect and end program" << std::endl;

while (!robot->isCleanButtonPressed()) {
while (true) {
// Get cliff status
const bool cliff_left = robot->isCliffLeft();
const bool cliff_front_left = robot->isCliffFrontLeft();
const bool cliff_front_right = robot->isCliffFrontRight();
const bool cliff_right = robot->isCliffRight();
const bool cliff_left = robot.isCliffLeft();
const bool cliff_front_left = robot.isCliffFrontLeft();
const bool cliff_front_right = robot.isCliffFrontRight();
const bool cliff_right = robot.isCliffRight();

// Print status
std::cout << "\rCliffs (left to right): [ " <<
Expand All @@ -84,13 +82,5 @@ int main(int argc, char** argv) {
usleep(10000); // 10 Hz
}

std::cout << std::endl;

// Call disconnect to avoid leaving robot in Full mode
robot->disconnect();

// Clean up
delete robot;

return 0;
}
24 changes: 6 additions & 18 deletions examples/drive_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,34 @@ 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;
return 1;
}

// 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);

// There's a delay between switching modes and when the robot will accept drive commands
usleep(100000);

// Command robot to drive a radius of 0.15 metres at 0.2 m/s
robot->driveRadius(0.2, 0.15);
robot.driveRadius(0.2, 0.15);

while (!robot->isCleanButtonPressed()) {
while (true) {
// Get robot odometry and print
const create::Pose pose = robot->getPose();
const create::Pose pose = robot.getPose();

std::cout << std::fixed << std::setprecision(2) << "\rOdometry (x, y, yaw): ("
<< pose.x << ", " << pose.y << ", " << pose.yaw << ") ";

usleep(10000); // 10 Hz
}

std::cout << std::endl;

// Call disconnect to avoid leaving robot in Full mode
// Also, this consequently stops the robot from moving
robot->disconnect();

// Clean up
delete robot;

std::cout << "Bye!" << std::endl;
return 0;
}
33 changes: 11 additions & 22 deletions examples/leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,38 @@ 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;
return 1;
}

// 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);

bool enable_check_robot_led = true;
bool enable_debris_led = false;
bool enable_dock_led = true;
bool enable_spot_led = false;
uint8_t power_led = 0;
uint8_t power_led = 0;
char digit_buffer[5];

while (!robot->isCleanButtonPressed()) {
while (true) {
// Set LEDs
robot->enableCheckRobotLED(enable_check_robot_led);
robot->enableDebrisLED(enable_debris_led);
robot->enableDockLED(enable_dock_led);
robot->enableSpotLED(enable_spot_led);
robot->setPowerLED(power_led);
robot.enableCheckRobotLED(enable_check_robot_led);
robot.enableDebrisLED(enable_debris_led);
robot.enableDockLED(enable_dock_led);
robot.enableSpotLED(enable_spot_led);
robot.setPowerLED(power_led);

// Set 7-segment displays
const int len = sprintf(digit_buffer, "%d", power_led);
for (int i = len; i < 4; i++) digit_buffer[i] = ' ';
robot->setDigitsASCII(digit_buffer[0], digit_buffer[1], digit_buffer[2], digit_buffer[3]);
robot.setDigitsASCII(digit_buffer[0], digit_buffer[1], digit_buffer[2], digit_buffer[3]);

// Update LED values
enable_check_robot_led = !enable_check_robot_led;
Expand All @@ -92,14 +90,5 @@ int main(int argc, char** argv) {
usleep(250000); // 5 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;
}
24 changes: 5 additions & 19 deletions examples/packets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,26 @@ 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;
return 1;
}

// Switch to Full mode
// robot->setMode(create::MODE_FULL);

std::cout << std::endl << "Press center 'Clean' button to disconnect and end program" << std::endl;

while (!robot->isCleanButtonPressed()) {
while (true) {
// Get serial packet statistics
const uint64_t total_packets = robot->getTotalPackets();
const uint64_t num_corrupt_packets = robot->getNumCorruptPackets();
const uint64_t total_packets = robot.getTotalPackets();
const uint64_t num_corrupt_packets = robot.getNumCorruptPackets();

// Print packet stats
std::cout << "\rTotal packets: " << total_packets << " Corrupt packets: " << num_corrupt_packets;

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