From 49199722be3d0f5373e204dd244352efb32bdb11 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 2 Apr 2024 11:47:09 -0500 Subject: [PATCH 01/10] Removed Create Connect button and Create Connected State Label --- src/Create3Widget.cpp | 23 +++------------- ui/Create3Widget.ui | 64 ------------------------------------------- 2 files changed, 4 insertions(+), 83 deletions(-) diff --git a/src/Create3Widget.cpp b/src/Create3Widget.cpp index 8ed61b29..0d73d211 100644 --- a/src/Create3Widget.cpp +++ b/src/Create3Widget.cpp @@ -39,8 +39,7 @@ Create3Widget::Create3Widget(Device *device, QWidget *parent) ui->setupUi(this); performStandardSetup(tr("Create 3"), false); setStyleSheet("QScrollBar:vertical {border: 2px solid grey;background:grey ;width: 100px; margin: 22px 0 22px 0; } QScrollBar::handle:vertical { border: 2px solid grey;background: white; min-height: 20px; } QScrollBar::add-line:vertical { border: 2px solid grey;background: #32CC99; height: 20px; subcontrol-position: bottom; subcontrol-origin: margin; } QScrollBar::sub-line:vertical {border: 2px solid grey; background: #32CC99; height: 20px; subcontrol-position: top; subcontrol-origin: margin; } QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { border: 2px solid grey;width: 3px; height: 3px; background: white; }QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {border: 2px solid grey; background: none;}"); - connect(ui->CreateConnectButton, SIGNAL(clicked()), SLOT(create3Connect())); - // connect(ui->ResetServerButton, SIGNAL(clicked()), SLOT(resetServer())); + connect(ui->Create3SensorListButton, SIGNAL(clicked()), SLOT(sensorList())); connect(ui->Create3ExampleProgramButton, SIGNAL(clicked()), SLOT(exampleList())); @@ -69,19 +68,7 @@ Create3Widget::Create3Widget(Device *device, QWidget *parent) connect(ui->toggleSwitch, SIGNAL(stateChanged(int)), this, SLOT(toggleChanged())); - if(ui->create3IP->text() == ""){ - ui->CreateConnectButton->setEnabled(false); - ui->Create3SensorListButton->setEnabled(false); - ui->Create3ExampleProgramButton->setEnabled(false); - ui->toggleSwitch->setEnabled(false); - } - else{ - ui->CreateConnectButton->setEnabled(true); - ui->Create3SensorListButton->setEnabled(true); - ui->Create3ExampleProgramButton->setEnabled(true); - ui->toggleSwitch->setEnabled(true); - } } Create3Widget::~Create3Widget() @@ -93,7 +80,7 @@ void Create3Widget::toggleChanged() { StandardWidget::disableMenuBar(); - ui->CreateConnectButton->setEnabled(false); + ui->toggleSwitch->setEnabled(false); ui->Create3SensorListButton->setEnabled(false); ui->Create3ExampleProgramButton->setEnabled(false); @@ -120,7 +107,6 @@ void Create3Widget::toggleChanged() StandardWidget::enableMenuBar(); ui->toggleSwitch->setChecked(false); //Wifi toggle side - ui->CreateConnectButton->setEnabled(true); ui->toggleSwitch->setEnabled(true); ui->Create3SensorListButton->setEnabled(true); ui->Create3ExampleProgramButton->setEnabled(true); @@ -142,7 +128,6 @@ void Create3Widget::toggleChanged() StandardWidget::enableMenuBar(); ui->toggleSwitch->setChecked(true); //Ethernet toggle side - ui->CreateConnectButton->setEnabled(true); ui->toggleSwitch->setEnabled(true); ui->Create3SensorListButton->setEnabled(true); ui->Create3ExampleProgramButton->setEnabled(true); @@ -218,11 +203,11 @@ void Create3Widget::create3Connect() if (connected == 1) { qDebug() << "Create connected"; - ui->createConnectState->setText("Connected"); + } else { qDebug() << "Create not connected"; - ui->createConnectState->setText("Not Connected"); + } } diff --git a/ui/Create3Widget.ui b/ui/Create3Widget.ui index 8a00ac8f..9aed9b32 100644 --- a/ui/Create3Widget.ui +++ b/ui/Create3Widget.ui @@ -30,39 +30,6 @@ 0 - - - - true - - - - 0 - 0 - - - - - 1 - 80 - - - - - 16777215 - 16777215 - - - - - 33 - - - - Create Connect - - - @@ -162,37 +129,6 @@ QCheckBox::indicator:unchecked{ - - - - - - - 22 - - - - Create3 Connected State: - - - - - - - - 22 - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - From e67e935f833f4de93254b7b19e1a3613f5cc95c3 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 3 Apr 2024 14:51:06 -0500 Subject: [PATCH 02/10] Removed A,B,C buttons from bottom of Create3ExampleWidget UI --- ui/Create3ExampleWidget.ui | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/ui/Create3ExampleWidget.ui b/ui/Create3ExampleWidget.ui index 8b8d239e..1f3da24b 100644 --- a/ui/Create3ExampleWidget.ui +++ b/ui/Create3ExampleWidget.ui @@ -93,42 +93,6 @@ 0 - - - - - 33 - - - - A - - - - - - - - 33 - - - - B - - - - - - - - 33 - - - - C - - - From ee0d75fb75f70bab9cacda03177fa889ad1cdaf7 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 3 Apr 2024 14:51:23 -0500 Subject: [PATCH 03/10] Temporarily commenting out everything in Create3ExampleWidget --- include/botui/Create3ExampleWidget.h | 84 +-- src/Create3ExampleWidget.cpp | 954 +++++++++++++-------------- 2 files changed, 519 insertions(+), 519 deletions(-) diff --git a/include/botui/Create3ExampleWidget.h b/include/botui/Create3ExampleWidget.h index f0849113..3ea367d3 100644 --- a/include/botui/Create3ExampleWidget.h +++ b/include/botui/Create3ExampleWidget.h @@ -1,42 +1,42 @@ -#ifndef _CREATE3EXAMPLEWIDGET_H_ -#define _CREATE3EXAMPLEWIDGET_H_ - -#include "StandardWidget.h" - -#include -#include -namespace Ui -{ - class Create3ExampleWidget; -} - -class Create3SensorModel; - -class Create3ExampleWidget : public StandardWidget -{ - Q_OBJECT -public: - Create3ExampleWidget(Device *device, QWidget *parent = 0); - ~Create3ExampleWidget(); - -private slots: - - int create3Connect(); - int isConnected(); - void indexChanged(int index); - void run(); - -private: - Ui::Create3ExampleWidget *ui; - - Create3SensorModel *_model; - double m_setpointVal; - double m_feedbackVal; - int m_position_1; - double m_vel_1; - void update(); - QStringListModel *model; - void updatePids(); -}; - -#endif +// #ifndef _CREATE3EXAMPLEWIDGET_H_ +// #define _CREATE3EXAMPLEWIDGET_H_ + +// #include "StandardWidget.h" + +// #include +// #include +// namespace Ui +// { +// class Create3ExampleWidget; +// } + +// class Create3SensorModel; + +// class Create3ExampleWidget : public StandardWidget +// { +// Q_OBJECT +// public: +// Create3ExampleWidget(Device *device, QWidget *parent = 0); +// ~Create3ExampleWidget(); + +// private slots: + +// int create3Connect(); +// int isConnected(); +// void indexChanged(int index); +// void run(); + +// private: +// Ui::Create3ExampleWidget *ui; + +// Create3SensorModel *_model; +// double m_setpointVal; +// double m_feedbackVal; +// int m_position_1; +// double m_vel_1; +// void update(); +// QStringListModel *model; +// void updatePids(); +// }; + +// #endif diff --git a/src/Create3ExampleWidget.cpp b/src/Create3ExampleWidget.cpp index 1a1ece3c..ac924fae 100644 --- a/src/Create3ExampleWidget.cpp +++ b/src/Create3ExampleWidget.cpp @@ -1,481 +1,481 @@ -#include "Create3ExampleWidget.h" -#include "ui_Create3ExampleWidget.h" -#include "Create3SensorListWidget.h" -#include -#include -#include "NumpadDialog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "RootController.h" -#include -#include -#include -#include -int exampleIndex; -QStringList programList; -// QStandardItemModel model(4,4); -Create3ExampleWidget::Create3ExampleWidget(Device *device, QWidget *parent) - : StandardWidget(device, parent), - ui(new Ui::Create3ExampleWidget) -{ - ui->setupUi(this); - performStandardSetup(tr("Create 3 Examples"), false); - connect(ui->exampleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); - - connect(ui->exampleRunButton, SIGNAL(clicked()), SLOT(run())); - - // Create model - model = new QStringListModel(this); - ui->listWidget->clear(); - programList.clear(); - programList << "printf('Connecting to Create3 robot...');" - << "create3_connect_manual('192.168.125.1', 50051);" - << "printf('Connected!');"; - - ui->listWidget->addItems(programList); - model->setStringList(programList); - qDebug() << "Program List: " << programList; - ui->listWidget->setSpacing(6); -} - -Create3ExampleWidget::~Create3ExampleWidget() -{ - delete ui; -} - -int Create3ExampleWidget::isConnected() -{ - int connected = 0; - try - { - connected = create3_is_connected(); - qDebug() << "Create connected? " << connected; - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - return connected; -} - -int Create3ExampleWidget::create3Connect() -{ - int connected = 0; - try - { - connected = create3_connect_manual("192.168.125.1", 50051); - qDebug() << "Create connected? " << connected; - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - return connected; -} -void Create3ExampleWidget::run() -{ - exampleIndex = ui->exampleComboBox->currentIndex(); - switch (exampleIndex) - { - - case 0: - { // 01_Connect - try - { - printf("Connecting to Create3 robot...\n"); - create3_connect_manual("192.168.125.1", 50051); - printf("Connected!\n"); - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - break; - } - - case 1: // 02_Dock_Undock - { - - try - { - printf("Connecting to Create3 robot...\n"); - - create3_connect_manual("192.168.125.1", 50051); - - printf("Connected!\n"); - - printf("Undocking...\n"); - // Move forward at 0.5 m/s for 1 second - create3_undock(); - - create3_wait(); - - printf("Docking...\n"); - - create3_dock(); - - create3_wait(); - - printf("Done!\n"); - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - - break; - } - - case 2: // 03_Move_Velocity - { - try - { - printf("Connecting to Create3 robot...\n"); - - create3_connect_manual("192.168.125.1", 50051); - - printf("Connected!\n"); - - printf("Moving forward at 0.5 m/s for 1 second...\n"); - - // Move forward at 0.5 m/s for 1 second - create3_velocity_set_components(0.5, 0); - - // Wait for 1 second - usleep(1000000); - - // Stop - create3_velocity_set_components(0.0, 0.0); - - printf("Done!\n"); - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - break; - } - - case 3: // 04_Rotate - { - try - { - printf("Connecting to Create3 robot...\n"); - - create3_connect_manual("192.168.125.1", 50051); - - printf("Connected!\n"); - - printf("Rotate at 0.5 m/s for 1 second...\n"); - - // Rotate at 90 deg/s (PI/2 rad/s) to 90 degrees (PI/2 radians) - create3_rotate_degrees(90, 90); - create3_rotate_radians(1.57, 1.57); - - // Wait for 1 second - create3_wait(); - - printf("Done!\n"); - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - - break; - } +// #include "Create3ExampleWidget.h" +// #include "ui_Create3ExampleWidget.h" +// #include "Create3SensorListWidget.h" +// #include +// #include +// #include "NumpadDialog.h" +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include "RootController.h" +// #include +// #include +// #include +// #include +// int exampleIndex; +// QStringList programList; +// // QStandardItemModel model(4,4); +// Create3ExampleWidget::Create3ExampleWidget(Device *device, QWidget *parent) +// : StandardWidget(device, parent), +// ui(new Ui::Create3ExampleWidget) +// { +// ui->setupUi(this); +// performStandardSetup(tr("Create 3 Examples"), false); +// connect(ui->exampleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); + +// connect(ui->exampleRunButton, SIGNAL(clicked()), SLOT(run())); + +// // Create model +// model = new QStringListModel(this); +// ui->listWidget->clear(); +// programList.clear(); +// programList << "printf('Connecting to Create3 robot...');" +// << "create3_connect_manual('192.168.125.1', 50051);" +// << "printf('Connected!');"; + +// ui->listWidget->addItems(programList); +// model->setStringList(programList); +// qDebug() << "Program List: " << programList; +// ui->listWidget->setSpacing(6); +// } + +// Create3ExampleWidget::~Create3ExampleWidget() +// { +// delete ui; +// } + +// int Create3ExampleWidget::isConnected() +// { +// int connected = 0; +// try +// { +// connected = create3_is_connected(); +// qDebug() << "Create connected? " << connected; +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } +// return connected; +// } + +// int Create3ExampleWidget::create3Connect() +// { +// int connected = 0; +// try +// { +// connected = create3_connect_manual("192.168.125.1", 50051); +// qDebug() << "Create connected? " << connected; +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } +// return connected; +// } +// void Create3ExampleWidget::run() +// { +// exampleIndex = ui->exampleComboBox->currentIndex(); +// switch (exampleIndex) +// { + +// case 0: +// { // 01_Connect +// try +// { +// printf("Connecting to Create3 robot...\n"); +// create3_connect_manual("192.168.125.1", 50051); +// printf("Connected!\n"); +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } +// break; +// } + +// case 1: // 02_Dock_Undock +// { + +// try +// { +// printf("Connecting to Create3 robot...\n"); + +// create3_connect_manual("192.168.125.1", 50051); + +// printf("Connected!\n"); + +// printf("Undocking...\n"); +// // Move forward at 0.5 m/s for 1 second +// create3_undock(); + +// create3_wait(); + +// printf("Docking...\n"); + +// create3_dock(); + +// create3_wait(); + +// printf("Done!\n"); +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } + +// break; +// } + +// case 2: // 03_Move_Velocity +// { +// try +// { +// printf("Connecting to Create3 robot...\n"); + +// create3_connect_manual("192.168.125.1", 50051); + +// printf("Connected!\n"); + +// printf("Moving forward at 0.5 m/s for 1 second...\n"); + +// // Move forward at 0.5 m/s for 1 second +// create3_velocity_set_components(0.5, 0); + +// // Wait for 1 second +// usleep(1000000); + +// // Stop +// create3_velocity_set_components(0.0, 0.0); + +// printf("Done!\n"); +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } +// break; +// } + +// case 3: // 04_Rotate +// { +// try +// { +// printf("Connecting to Create3 robot...\n"); + +// create3_connect_manual("192.168.125.1", 50051); + +// printf("Connected!\n"); + +// printf("Rotate at 0.5 m/s for 1 second...\n"); + +// // Rotate at 90 deg/s (PI/2 rad/s) to 90 degrees (PI/2 radians) +// create3_rotate_degrees(90, 90); +// create3_rotate_radians(1.57, 1.57); + +// // Wait for 1 second +// create3_wait(); + +// printf("Done!\n"); +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } + +// break; +// } - case 4: // 05_Arc - { - try - { - printf("Connecting to Create3 robot...\n"); +// case 4: // 05_Arc +// { +// try +// { +// printf("Connecting to Create3 robot...\n"); - create3_connect_manual("192.168.125.1", 50051); +// create3_connect_manual("192.168.125.1", 50051); - printf("Connected!\n"); +// printf("Connected!\n"); - printf("Rotate at 0.5 m/s for 1 second...\n"); - - // Arc of 90 deg (PI/2 rad) with radius of 0.5 m - create3_drive_arc_degrees(0.5, 90, 0.306); - create3_drive_arc_radians(0.5, -1.57, 0.460); - - // Wait for 1 second - create3_wait(); - - printf("Done!\n"); - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - - break; - } - - case 5: // 06_led_test - { - try - { - printf("Connecting to Create3 robot...\n"); - - create3_connect_manual("192.168.125.1", 50051); - - printf("Connected!\n"); - - printf("Blinking lights...\n"); - // Blink the lights green for 5 seconds. - - Create3LedColor green; - green.r = 0; - green.g = 255; - green.b = 0; - - Create3Lightring lightring; - lightring.led0 = green; - lightring.led1 = green; - lightring.led2 = green; - lightring.led3 = green; - lightring.led4 = green; - lightring.led5 = green; - - create3_led_animation(Create3BlinkLights, lightring, 5.0); // Blink the lights green for 5 seconds. - - // Wait for 1 second - create3_wait(); - - printf("Done!\n"); - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - - break; - } - case 6: // 07_sensors - { - try - { - printf("Connecting to Create3 robot...\n"); - - create3_connect_manual("192.168.125.1", 50051); - - printf("Connected!\n"); - - printf("Sensor Values:\n"); - printf(" Left Side Cliff: %d\n", create3_sensor_cliff(0)); - printf(" Left Front Cliff: %d\n", create3_sensor_cliff(1)); - printf(" Right Front Cliff: %d\n", create3_sensor_cliff(2)); - printf(" Right Side Cliff: %d\n", create3_sensor_cliff(3)); - printf("\n"); - printf(" Left Side IR: %d\n", create3_sensor_ir(0)); - printf(" Left IR: %d\n", create3_sensor_ir(1)); - printf(" Left Front IR: %d\n", create3_sensor_ir(2)); - printf(" Left Center IR: %d\n", create3_sensor_ir(3)); - printf(" Right Center IR: %d\n", create3_sensor_ir(4)); - printf(" Right Front IR: %d\n", create3_sensor_ir(5)); - printf(" Right IR: %d\n", create3_sensor_ir(6)); - - printf(" Left Bumper: %d\n", create3_sensor_bump(0)); - printf(" Left Front Bumper: %d\n", create3_sensor_bump(1)); - printf(" Center Front Bumper: %d\n", create3_sensor_bump(2)); - printf(" Right Front Bumper: %d\n", create3_sensor_bump(3)); - printf(" Right Bumper: %d\n", create3_sensor_bump(4)); - - while (create3_sensor_bump(3) == 0) - { - if (create3_sensor_bump(3) == 1) - { - create3_velocity_set_components(0.0, 0.0); - break; - } - create3_velocity_set_components(0.15, 0.0); - } - - printf("Done!\n"); - } - catch (const std::exception &e) - { - std::cerr << e.what() << '\n'; - } - } - - default: - break; - } -} -void Create3ExampleWidget::indexChanged(int index) -{ - - programList.clear(); - ui->listWidget->clear(); - ui->listWidget->addItems(programList); - model->setStringList(programList); - switch (index) - { - case 0: // 01_Connect - { - - programList << "printf('Connecting to Create3 robot...');" - << "create3_connect_manual('192.168.125.1', 50051);" - << "printf('Connected!');"; - qDebug() << "Program List: " << programList; - ui->listWidget->addItems(programList); - model->setStringList(programList); - break; - } - - case 1: // 02_Dock_Undock - { - programList.clear(); - programList << "printf('Connecting to Create3 robot...');" - << "create3_connect_manual('192.168.125.1', 50051);" - << "printf('Connected!');" - << "printf('Undocking...');" - << "create3_undock();" - << "create3_wait();" - << "printf('Done!');"; - qDebug() << "Program List: " << programList; - - ui->listWidget->addItems(programList); - model->setStringList(programList); - break; - } - case 2: // 03_Move_Velocity - { - - programList - << "printf('Connecting to Create3 robot...');" - << "create3_connect_manual('192.168.125.1', 50051);" - << "printf('Connected!');" - << "printf('Moving forward at 0.5 m/s for 1 second...');" - << "//Move forward at 0.5 m/s for 1 second" - << "create3_velocity_set_components(0.5, 0);" - << "//Wait for 1 second" - << "usleep(1000000);" - << "//Stop" - << "create3_velocity_set_components(0.0, 0.0);" - << "printf('Done!');"; - qDebug() << "Program List: " << programList; - ui->listWidget->addItems(programList); - model->setStringList(programList); - ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); - ui->listWidget->item(6)->setForeground(QColor(0, 128, 0)); - ui->listWidget->item(8)->setForeground(QColor(0, 128, 0)); - - break; - } - case 3: // 04_Rotate - programList - << "printf('Connecting to Create3 robot...');" - << "create3_connect_manual('192.168.125.1', 50051);" - << "printf('Connected!');" - << "printf('Rotate at 0.5 m/s for 1 second...');" - << "//Rotate at 90 deg/s (PI/2 rad/s) to 90 degrees (PI/2 radians)" - << "create3_rotate_degrees(90, 90);" - << "create3_rotate_radians(1.57, 1.57);" - << "//Wait for 1 second" - << "create3_wait();" - << "printf('Done!');"; - ui->listWidget->addItems(programList); - model->setStringList(programList); - ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); - ui->listWidget->item(7)->setForeground(QColor(0, 128, 0)); - - break; - case 4: // 05_Arc - programList - << "printf('Connecting to Create3 robot...');" - << "create3_connect_manual('192.168.125.1', 50051);" - << "printf('Connected!');" - << "printf('Rotate at 0.5 m/s for 1 second...');" - << "//Arc of 90 deg (PI/2 rad) with radius of 0.5 m" - << "create3_drive_arc_degrees(0.5, 90, 0.306);" - << "create3_drive_arc_radians(0.5, -1.57, 0.460);" - << "//Wait for 1 second" - << "create3_wait();" - << "printf('Done!');"; - ui->listWidget->addItems(programList); - model->setStringList(programList); - ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); - ui->listWidget->item(7)->setForeground(QColor(0, 128, 0)); - break; - case 5: // 06_led_test - programList - << "printf('Connecting to Create3 robot...');" - << "create3_connect_manual('192.168.125.1', 50051);" - << "printf('Connected!');" - << "printf('Blinking lights...');" - << "//Blink the lights green for 5 seconds." - << "Create3LedColor green;" - << "green.r = 0;" - << "green.g = 255;" - << "green.b = 0;" - << "Create3Lightring lightring;" - << "lightring.led0 = green;" - << "lightring.led1 = green;" - << "lightring.led2 = green;" - << "lightring.led3 = green;" - << "lightring.led4 = green;" - << "lightring.led5 = green;" - << "// Blink the lights green for 5 seconds." - << "create3_led_animation(Create3BlinkLights, lightring, 5.0);" - << "//Wait for 1 second" - << "create3_wait();" - << "printf('Done!');"; - ui->listWidget->addItems(programList); - model->setStringList(programList); - ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); - ui->listWidget->item(16)->setForeground(QColor(0, 128, 0)); - ui->listWidget->item(18)->setForeground(QColor(0, 128, 0)); - break; - case 6: // 07_sensors - programList - << "printf('Connecting to Create3 robot...');" - << "create3_connect_manual('192.168.125.1', 50051);" - << "printf('Connected!');" - << "printf('Sensor Values:');" - << "printf(' Left Side Cliff: %d', create3_sensor_cliff(0));" - << "printf(' Left Front Cliff: %d', create3_sensor_cliff(1));" - << "printf(' Right Front Cliff: %d', create3_sensor_cliff(2));" - << "printf(' Right Side Cliff: %d', create3_sensor_cliff(3));" - << "printf(' Left Side IR: %d', create3_sensor_ir(0));" - << "printf(' Left IR: %d', create3_sensor_ir(1));" - << "printf(' Left Front IR: %d', create3_sensor_ir(2));" - << "printf(' Left Center IR: %d', create3_sensor_ir(3));" - << "printf(' Right Center IR: %d', create3_sensor_ir(4));" - << "printf(' Right Front IR: %d', create3_sensor_ir(5));" - << "printf(' Right IR: %d', create3_sensor_ir(6));" - << "printf(' Left Bumper: %d', create3_sensor_bump(0));" - << "printf(' Left Front Bumper: %d', create3_sensor_bump(1));" - << "printf(' Center Front Bumper: %d', create3_sensor_bump(2));" - << "printf(' Right Front Bumper: %d', create3_sensor_bump(3));" - << "printf(' Right Bumper: %d', create3_sensor_bump(4));" - << "while (create3_sensor_bump(3) == 0)" - << "{" - << " if (create3_sensor_bump(3) == 1)" - << " {" - << " create3_velocity_set_components(0.0, 0.0);" - << " break;" - << " }" - << " create3_velocity_set_components(0.15, 0.0);" - << "}" - << "printf('Done!');"; - ui->listWidget->addItems(programList); - model->setStringList(programList); - - break; - default: - break; - } -} +// printf("Rotate at 0.5 m/s for 1 second...\n"); + +// // Arc of 90 deg (PI/2 rad) with radius of 0.5 m +// create3_drive_arc_degrees(0.5, 90, 0.306); +// create3_drive_arc_radians(0.5, -1.57, 0.460); + +// // Wait for 1 second +// create3_wait(); + +// printf("Done!\n"); +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } + +// break; +// } + +// case 5: // 06_led_test +// { +// try +// { +// printf("Connecting to Create3 robot...\n"); + +// create3_connect_manual("192.168.125.1", 50051); + +// printf("Connected!\n"); + +// printf("Blinking lights...\n"); +// // Blink the lights green for 5 seconds. + +// Create3LedColor green; +// green.r = 0; +// green.g = 255; +// green.b = 0; + +// Create3Lightring lightring; +// lightring.led0 = green; +// lightring.led1 = green; +// lightring.led2 = green; +// lightring.led3 = green; +// lightring.led4 = green; +// lightring.led5 = green; + +// create3_led_animation(Create3BlinkLights, lightring, 5.0); // Blink the lights green for 5 seconds. + +// // Wait for 1 second +// create3_wait(); + +// printf("Done!\n"); +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } + +// break; +// } +// case 6: // 07_sensors +// { +// try +// { +// printf("Connecting to Create3 robot...\n"); + +// create3_connect_manual("192.168.125.1", 50051); + +// printf("Connected!\n"); + +// printf("Sensor Values:\n"); +// printf(" Left Side Cliff: %d\n", create3_sensor_cliff(0)); +// printf(" Left Front Cliff: %d\n", create3_sensor_cliff(1)); +// printf(" Right Front Cliff: %d\n", create3_sensor_cliff(2)); +// printf(" Right Side Cliff: %d\n", create3_sensor_cliff(3)); +// printf("\n"); +// printf(" Left Side IR: %d\n", create3_sensor_ir(0)); +// printf(" Left IR: %d\n", create3_sensor_ir(1)); +// printf(" Left Front IR: %d\n", create3_sensor_ir(2)); +// printf(" Left Center IR: %d\n", create3_sensor_ir(3)); +// printf(" Right Center IR: %d\n", create3_sensor_ir(4)); +// printf(" Right Front IR: %d\n", create3_sensor_ir(5)); +// printf(" Right IR: %d\n", create3_sensor_ir(6)); + +// printf(" Left Bumper: %d\n", create3_sensor_bump(0)); +// printf(" Left Front Bumper: %d\n", create3_sensor_bump(1)); +// printf(" Center Front Bumper: %d\n", create3_sensor_bump(2)); +// printf(" Right Front Bumper: %d\n", create3_sensor_bump(3)); +// printf(" Right Bumper: %d\n", create3_sensor_bump(4)); + +// while (create3_sensor_bump(3) == 0) +// { +// if (create3_sensor_bump(3) == 1) +// { +// create3_velocity_set_components(0.0, 0.0); +// break; +// } +// create3_velocity_set_components(0.15, 0.0); +// } + +// printf("Done!\n"); +// } +// catch (const std::exception &e) +// { +// std::cerr << e.what() << '\n'; +// } +// } + +// default: +// break; +// } +// } +// void Create3ExampleWidget::indexChanged(int index) +// { + +// programList.clear(); +// ui->listWidget->clear(); +// ui->listWidget->addItems(programList); +// model->setStringList(programList); +// switch (index) +// { +// case 0: // 01_Connect +// { + +// programList << "printf('Connecting to Create3 robot...');" +// << "create3_connect_manual('192.168.125.1', 50051);" +// << "printf('Connected!');"; +// qDebug() << "Program List: " << programList; +// ui->listWidget->addItems(programList); +// model->setStringList(programList); +// break; +// } + +// case 1: // 02_Dock_Undock +// { +// programList.clear(); +// programList << "printf('Connecting to Create3 robot...');" +// << "create3_connect_manual('192.168.125.1', 50051);" +// << "printf('Connected!');" +// << "printf('Undocking...');" +// << "create3_undock();" +// << "create3_wait();" +// << "printf('Done!');"; +// qDebug() << "Program List: " << programList; + +// ui->listWidget->addItems(programList); +// model->setStringList(programList); +// break; +// } +// case 2: // 03_Move_Velocity +// { + +// programList +// << "printf('Connecting to Create3 robot...');" +// << "create3_connect_manual('192.168.125.1', 50051);" +// << "printf('Connected!');" +// << "printf('Moving forward at 0.5 m/s for 1 second...');" +// << "//Move forward at 0.5 m/s for 1 second" +// << "create3_velocity_set_components(0.5, 0);" +// << "//Wait for 1 second" +// << "usleep(1000000);" +// << "//Stop" +// << "create3_velocity_set_components(0.0, 0.0);" +// << "printf('Done!');"; +// qDebug() << "Program List: " << programList; +// ui->listWidget->addItems(programList); +// model->setStringList(programList); +// ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); +// ui->listWidget->item(6)->setForeground(QColor(0, 128, 0)); +// ui->listWidget->item(8)->setForeground(QColor(0, 128, 0)); + +// break; +// } +// case 3: // 04_Rotate +// programList +// << "printf('Connecting to Create3 robot...');" +// << "create3_connect_manual('192.168.125.1', 50051);" +// << "printf('Connected!');" +// << "printf('Rotate at 0.5 m/s for 1 second...');" +// << "//Rotate at 90 deg/s (PI/2 rad/s) to 90 degrees (PI/2 radians)" +// << "create3_rotate_degrees(90, 90);" +// << "create3_rotate_radians(1.57, 1.57);" +// << "//Wait for 1 second" +// << "create3_wait();" +// << "printf('Done!');"; +// ui->listWidget->addItems(programList); +// model->setStringList(programList); +// ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); +// ui->listWidget->item(7)->setForeground(QColor(0, 128, 0)); + +// break; +// case 4: // 05_Arc +// programList +// << "printf('Connecting to Create3 robot...');" +// << "create3_connect_manual('192.168.125.1', 50051);" +// << "printf('Connected!');" +// << "printf('Rotate at 0.5 m/s for 1 second...');" +// << "//Arc of 90 deg (PI/2 rad) with radius of 0.5 m" +// << "create3_drive_arc_degrees(0.5, 90, 0.306);" +// << "create3_drive_arc_radians(0.5, -1.57, 0.460);" +// << "//Wait for 1 second" +// << "create3_wait();" +// << "printf('Done!');"; +// ui->listWidget->addItems(programList); +// model->setStringList(programList); +// ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); +// ui->listWidget->item(7)->setForeground(QColor(0, 128, 0)); +// break; +// case 5: // 06_led_test +// programList +// << "printf('Connecting to Create3 robot...');" +// << "create3_connect_manual('192.168.125.1', 50051);" +// << "printf('Connected!');" +// << "printf('Blinking lights...');" +// << "//Blink the lights green for 5 seconds." +// << "Create3LedColor green;" +// << "green.r = 0;" +// << "green.g = 255;" +// << "green.b = 0;" +// << "Create3Lightring lightring;" +// << "lightring.led0 = green;" +// << "lightring.led1 = green;" +// << "lightring.led2 = green;" +// << "lightring.led3 = green;" +// << "lightring.led4 = green;" +// << "lightring.led5 = green;" +// << "// Blink the lights green for 5 seconds." +// << "create3_led_animation(Create3BlinkLights, lightring, 5.0);" +// << "//Wait for 1 second" +// << "create3_wait();" +// << "printf('Done!');"; +// ui->listWidget->addItems(programList); +// model->setStringList(programList); +// ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); +// ui->listWidget->item(16)->setForeground(QColor(0, 128, 0)); +// ui->listWidget->item(18)->setForeground(QColor(0, 128, 0)); +// break; +// case 6: // 07_sensors +// programList +// << "printf('Connecting to Create3 robot...');" +// << "create3_connect_manual('192.168.125.1', 50051);" +// << "printf('Connected!');" +// << "printf('Sensor Values:');" +// << "printf(' Left Side Cliff: %d', create3_sensor_cliff(0));" +// << "printf(' Left Front Cliff: %d', create3_sensor_cliff(1));" +// << "printf(' Right Front Cliff: %d', create3_sensor_cliff(2));" +// << "printf(' Right Side Cliff: %d', create3_sensor_cliff(3));" +// << "printf(' Left Side IR: %d', create3_sensor_ir(0));" +// << "printf(' Left IR: %d', create3_sensor_ir(1));" +// << "printf(' Left Front IR: %d', create3_sensor_ir(2));" +// << "printf(' Left Center IR: %d', create3_sensor_ir(3));" +// << "printf(' Right Center IR: %d', create3_sensor_ir(4));" +// << "printf(' Right Front IR: %d', create3_sensor_ir(5));" +// << "printf(' Right IR: %d', create3_sensor_ir(6));" +// << "printf(' Left Bumper: %d', create3_sensor_bump(0));" +// << "printf(' Left Front Bumper: %d', create3_sensor_bump(1));" +// << "printf(' Center Front Bumper: %d', create3_sensor_bump(2));" +// << "printf(' Right Front Bumper: %d', create3_sensor_bump(3));" +// << "printf(' Right Bumper: %d', create3_sensor_bump(4));" +// << "while (create3_sensor_bump(3) == 0)" +// << "{" +// << " if (create3_sensor_bump(3) == 1)" +// << " {" +// << " create3_velocity_set_components(0.0, 0.0);" +// << " break;" +// << " }" +// << " create3_velocity_set_components(0.15, 0.0);" +// << "}" +// << "printf('Done!');"; +// ui->listWidget->addItems(programList); +// model->setStringList(programList); + +// break; +// default: +// break; +// } +// } From 1e71f1dc8d548375cf826719e6d1616be51de194 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 3 Apr 2024 14:52:23 -0500 Subject: [PATCH 04/10] Added example programs to main Create 3 page --- include/botui/Create3Widget.h | 14 +- src/Create3Widget.cpp | 463 +++++++++++++++++++++++++++++++--- ui/Create3Widget.ui | 218 ++++++++++------ 3 files changed, 570 insertions(+), 125 deletions(-) diff --git a/include/botui/Create3Widget.h b/include/botui/Create3Widget.h index 3705148a..5dd693c4 100644 --- a/include/botui/Create3Widget.h +++ b/include/botui/Create3Widget.h @@ -4,6 +4,7 @@ #include "StandardWidget.h" #include +#include #include namespace Ui @@ -15,30 +16,27 @@ class Create3SensorModel; class Create3Widget : public StandardWidget { -Q_OBJECT + Q_OBJECT public: Create3Widget(Device *device, QWidget *parent = 0); ~Create3Widget(); private slots: - void create3Connect(); - // void resetServer(); - void sensorList(); - void exampleList(); QString getIP(); void toggleChanged(); - + void indexChanged(int index); + void run(); private: Ui::Create3Widget *ui; - Create3SensorModel *_model; + Create3SensorModel *_model; double m_setpointVal; double m_feedbackVal; int m_position_1; + QStringListModel *model; double m_vel_1; }; - #endif diff --git a/src/Create3Widget.cpp b/src/Create3Widget.cpp index 0d73d211..4e885d44 100644 --- a/src/Create3Widget.cpp +++ b/src/Create3Widget.cpp @@ -1,7 +1,7 @@ #include "Create3Widget.h" #include "ui_Create3Widget.h" #include "Create3SensorListWidget.h" -#include "Create3ExampleWidget.h" + #include "Create3SensorModel.h" #include #include @@ -18,6 +18,9 @@ #include #include "RootController.h" +int exampleIndex; +QStringList programList; + class Create3SensorItemDelegate : public QItemDelegate { public: @@ -40,9 +43,6 @@ Create3Widget::Create3Widget(Device *device, QWidget *parent) performStandardSetup(tr("Create 3"), false); setStyleSheet("QScrollBar:vertical {border: 2px solid grey;background:grey ;width: 100px; margin: 22px 0 22px 0; } QScrollBar::handle:vertical { border: 2px solid grey;background: white; min-height: 20px; } QScrollBar::add-line:vertical { border: 2px solid grey;background: #32CC99; height: 20px; subcontrol-position: bottom; subcontrol-origin: margin; } QScrollBar::sub-line:vertical {border: 2px solid grey; background: #32CC99; height: 20px; subcontrol-position: top; subcontrol-origin: margin; } QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { border: 2px solid grey;width: 3px; height: 3px; background: white; }QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {border: 2px solid grey; background: none;}"); - connect(ui->Create3SensorListButton, SIGNAL(clicked()), SLOT(sensorList())); - connect(ui->Create3ExampleProgramButton, SIGNAL(clicked()), SLOT(exampleList())); - ui->create3IP->setText(getIP()); QStringList arguments; @@ -59,16 +59,30 @@ Create3Widget::Create3Widget(Device *device, QWidget *parent) if (ipOutput == "192.168.125.1") { - ui->toggleSwitch->setChecked(false); //Wifi toggle side + ui->toggleSwitch->setChecked(false); // Wifi toggle side } else if (ipOutput == "192.168.186.3") { - ui->toggleSwitch->setChecked(true); //Ethernet toggle side + ui->toggleSwitch->setChecked(true); // Ethernet toggle side } connect(ui->toggleSwitch, SIGNAL(stateChanged(int)), this, SLOT(toggleChanged())); - - + connect(ui->exampleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); + + connect(ui->exampleRunButton, SIGNAL(clicked()), SLOT(run())); + + // Create model + model = new QStringListModel(this); + ui->listWidget->clear(); + programList.clear(); + programList << "printf('Connecting to Create3 robot...');" + << "create3_connect_manual('192.168.125.1', 50051);" + << "printf('Connected!');"; + + ui->listWidget->addItems(programList); + model->setStringList(programList); + qDebug() << "Program List: " << programList; + ui->listWidget->setSpacing(6); } Create3Widget::~Create3Widget() @@ -82,8 +96,8 @@ void Create3Widget::toggleChanged() StandardWidget::disableMenuBar(); ui->toggleSwitch->setEnabled(false); - ui->Create3SensorListButton->setEnabled(false); - ui->Create3ExampleProgramButton->setEnabled(false); + ui->exampleComboBox->setEnabled(false); + ui->exampleRunButton->setEnabled(false); QProcess checkCreate3IPState; QString startCommand = "cat"; @@ -106,10 +120,11 @@ void Create3Widget::toggleChanged() { StandardWidget::enableMenuBar(); - ui->toggleSwitch->setChecked(false); //Wifi toggle side + ui->toggleSwitch->setChecked(false); // Wifi toggle side ui->toggleSwitch->setEnabled(true); - ui->Create3SensorListButton->setEnabled(true); - ui->Create3ExampleProgramButton->setEnabled(true); + ui->exampleComboBox->setEnabled(true); + ui->exampleRunButton->setEnabled(true); + return; } else @@ -127,10 +142,11 @@ void Create3Widget::toggleChanged() { StandardWidget::enableMenuBar(); - ui->toggleSwitch->setChecked(true); //Ethernet toggle side + ui->toggleSwitch->setChecked(true); // Ethernet toggle side ui->toggleSwitch->setEnabled(true); - ui->Create3SensorListButton->setEnabled(true); - ui->Create3ExampleProgramButton->setEnabled(true); + ui->exampleComboBox->setEnabled(true); + ui->exampleRunButton->setEnabled(true); + return; } else @@ -178,36 +194,413 @@ QString Create3Widget::getIP() return output; } -void Create3Widget::sensorList() -{ - RootController::ref().presentWidget(new Create3SensorListWidget(device())); -} +// void Create3Widget::sensorList() +// { +// RootController::ref().presentWidget(new Create3SensorListWidget(device())); +// } + +// void Create3Widget::exampleList() +// { +// RootController::ref().presentWidget(new Create3ExampleWidget(device())); +// } -void Create3Widget::exampleList() +void Create3Widget::indexChanged(int index) { - RootController::ref().presentWidget(new Create3ExampleWidget(device())); + + programList.clear(); + ui->listWidget->clear(); + ui->listWidget->addItems(programList); + model->setStringList(programList); + switch (index) + { + case 0: // 01_Connect + { + + programList << "printf('Connecting to Create3 robot...');" + << "create3_connect_manual('192.168.125.1', 50051);" + << "printf('Connected!');"; + qDebug() << "Program List: " << programList; + ui->listWidget->addItems(programList); + model->setStringList(programList); + break; + } + + case 1: // 02_Dock_Undock + { + programList.clear(); + programList << "printf('Connecting to Create3 robot...');" + << "create3_connect_manual('192.168.125.1', 50051);" + << "printf('Connected!');" + << "printf('Undocking...');" + << "create3_undock();" + << "create3_wait();" + << "printf('Done!');"; + qDebug() << "Program List: " << programList; + + ui->listWidget->addItems(programList); + model->setStringList(programList); + break; + } + case 2: // 03_Move_Velocity + { + + programList + << "printf('Connecting to Create3 robot...');" + << "create3_connect_manual('192.168.125.1', 50051);" + << "printf('Connected!');" + << "printf('Moving forward at 0.5 m/s for 1 second...');" + << "//Move forward at 0.5 m/s for 1 second" + << "create3_velocity_set_components(0.5, 0);" + << "//Wait for 1 second" + << "usleep(1000000);" + << "//Stop" + << "create3_velocity_set_components(0.0, 0.0);" + << "printf('Done!');"; + qDebug() << "Program List: " << programList; + ui->listWidget->addItems(programList); + model->setStringList(programList); + ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); + ui->listWidget->item(6)->setForeground(QColor(0, 128, 0)); + ui->listWidget->item(8)->setForeground(QColor(0, 128, 0)); + + break; + } + case 3: // 04_Rotate + programList + << "printf('Connecting to Create3 robot...');" + << "create3_connect_manual('192.168.125.1', 50051);" + << "printf('Connected!');" + << "printf('Rotate at 0.5 m/s for 1 second...');" + << "//Rotate at 90 deg/s (PI/2 rad/s) to 90 degrees (PI/2 radians)" + << "create3_rotate_degrees(90, 90);" + << "create3_rotate_radians(1.57, 1.57);" + << "//Wait for 1 second" + << "create3_wait();" + << "printf('Done!');"; + ui->listWidget->addItems(programList); + model->setStringList(programList); + ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); + ui->listWidget->item(7)->setForeground(QColor(0, 128, 0)); + + break; + case 4: // 05_Arc + programList + << "printf('Connecting to Create3 robot...');" + << "create3_connect_manual('192.168.125.1', 50051);" + << "printf('Connected!');" + << "printf('Rotate at 0.5 m/s for 1 second...');" + << "//Arc of 90 deg (PI/2 rad) with radius of 0.5 m" + << "create3_drive_arc_degrees(0.5, 90, 0.306);" + << "create3_drive_arc_radians(0.5, -1.57, 0.460);" + << "//Wait for 1 second" + << "create3_wait();" + << "printf('Done!');"; + ui->listWidget->addItems(programList); + model->setStringList(programList); + ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); + ui->listWidget->item(7)->setForeground(QColor(0, 128, 0)); + break; + case 5: // 06_led_test + programList + << "printf('Connecting to Create3 robot...');" + << "create3_connect_manual('192.168.125.1', 50051);" + << "printf('Connected!');" + << "printf('Blinking lights...');" + << "//Blink the lights green for 5 seconds." + << "Create3LedColor green;" + << "green.r = 0;" + << "green.g = 255;" + << "green.b = 0;" + << "Create3Lightring lightring;" + << "lightring.led0 = green;" + << "lightring.led1 = green;" + << "lightring.led2 = green;" + << "lightring.led3 = green;" + << "lightring.led4 = green;" + << "lightring.led5 = green;" + << "// Blink the lights green for 5 seconds." + << "create3_led_animation(Create3BlinkLights, lightring, 5.0);" + << "//Wait for 1 second" + << "create3_wait();" + << "printf('Done!');"; + ui->listWidget->addItems(programList); + model->setStringList(programList); + ui->listWidget->item(4)->setForeground(QColor(0, 128, 0)); + ui->listWidget->item(16)->setForeground(QColor(0, 128, 0)); + ui->listWidget->item(18)->setForeground(QColor(0, 128, 0)); + break; + case 6: // 07_sensors + programList + << "printf('Connecting to Create3 robot...');" + << "create3_connect_manual('192.168.125.1', 50051);" + << "printf('Connected!');" + << "printf('Sensor Values:');" + << "printf(' Left Side Cliff: %d', create3_sensor_cliff(0));" + << "printf(' Left Front Cliff: %d', create3_sensor_cliff(1));" + << "printf(' Right Front Cliff: %d', create3_sensor_cliff(2));" + << "printf(' Right Side Cliff: %d', create3_sensor_cliff(3));" + << "printf(' Left Side IR: %d', create3_sensor_ir(0));" + << "printf(' Left IR: %d', create3_sensor_ir(1));" + << "printf(' Left Front IR: %d', create3_sensor_ir(2));" + << "printf(' Left Center IR: %d', create3_sensor_ir(3));" + << "printf(' Right Center IR: %d', create3_sensor_ir(4));" + << "printf(' Right Front IR: %d', create3_sensor_ir(5));" + << "printf(' Right IR: %d', create3_sensor_ir(6));" + << "printf(' Left Bumper: %d', create3_sensor_bump(0));" + << "printf(' Left Front Bumper: %d', create3_sensor_bump(1));" + << "printf(' Center Front Bumper: %d', create3_sensor_bump(2));" + << "printf(' Right Front Bumper: %d', create3_sensor_bump(3));" + << "printf(' Right Bumper: %d', create3_sensor_bump(4));" + << "while (create3_sensor_bump(3) == 0)" + << "{" + << " if (create3_sensor_bump(3) == 1)" + << " {" + << " create3_velocity_set_components(0.0, 0.0);" + << " break;" + << " }" + << " create3_velocity_set_components(0.15, 0.0);" + << "}" + << "printf('Done!');"; + ui->listWidget->addItems(programList); + model->setStringList(programList); + + break; + default: + break; + } } -void Create3Widget::create3Connect() +void Create3Widget::run() { - int connected = 0; - try + exampleIndex = ui->exampleComboBox->currentIndex(); + switch (exampleIndex) { - connected = create3_connect(); - qDebug() << "Create connected? " << connected; + + case 0: + { // 01_Connect + try + { + printf("Connecting to Create3 robot...\n"); + create3_connect_manual("192.168.125.1", 50051); + printf("Connected!\n"); + } + catch (const std::exception &e) + { + std::cerr << e.what() << '\n'; + } + break; } - catch (const std::exception &e) + + case 1: // 02_Dock_Undock { - std::cerr << e.what() << '\n'; + + try + { + printf("Connecting to Create3 robot...\n"); + + create3_connect_manual("192.168.125.1", 50051); + + printf("Connected!\n"); + + printf("Undocking...\n"); + // Move forward at 0.5 m/s for 1 second + create3_undock(); + + create3_wait(); + + printf("Docking...\n"); + + create3_dock(); + + create3_wait(); + + printf("Done!\n"); + } + catch (const std::exception &e) + { + std::cerr << e.what() << '\n'; + } + + break; } - if (connected == 1) + + case 2: // 03_Move_Velocity { - qDebug() << "Create connected"; - + try + { + printf("Connecting to Create3 robot...\n"); + + create3_connect_manual("192.168.125.1", 50051); + + printf("Connected!\n"); + + printf("Moving forward at 0.5 m/s for 1 second...\n"); + + // Move forward at 0.5 m/s for 1 second + create3_velocity_set_components(0.5, 0); + + // Wait for 1 second + usleep(1000000); + + // Stop + create3_velocity_set_components(0.0, 0.0); + + printf("Done!\n"); + } + catch (const std::exception &e) + { + std::cerr << e.what() << '\n'; + } + break; + } + + case 3: // 04_Rotate + { + try + { + printf("Connecting to Create3 robot...\n"); + + create3_connect_manual("192.168.125.1", 50051); + + printf("Connected!\n"); + + printf("Rotate at 0.5 m/s for 1 second...\n"); + + // Rotate at 90 deg/s (PI/2 rad/s) to 90 degrees (PI/2 radians) + create3_rotate_degrees(90, 90); + create3_rotate_radians(1.57, 1.57); + + // Wait for 1 second + create3_wait(); + + printf("Done!\n"); + } + catch (const std::exception &e) + { + std::cerr << e.what() << '\n'; + } + + break; } - else + + case 4: // 05_Arc { - qDebug() << "Create not connected"; - + try + { + printf("Connecting to Create3 robot...\n"); + + create3_connect_manual("192.168.125.1", 50051); + + printf("Connected!\n"); + + printf("Rotate at 0.5 m/s for 1 second...\n"); + + // Arc of 90 deg (PI/2 rad) with radius of 0.5 m + create3_drive_arc_degrees(0.5, 90, 0.306); + create3_drive_arc_radians(0.5, -1.57, 0.460); + + // Wait for 1 second + create3_wait(); + + printf("Done!\n"); + } + catch (const std::exception &e) + { + std::cerr << e.what() << '\n'; + } + + break; + } + + case 5: // 06_led_test + { + try + { + printf("Connecting to Create3 robot...\n"); + + create3_connect_manual("192.168.125.1", 50051); + + printf("Connected!\n"); + + printf("Blinking lights...\n"); + // Blink the lights green for 5 seconds. + + Create3LedColor green; + green.r = 0; + green.g = 255; + green.b = 0; + + Create3Lightring lightring; + lightring.led0 = green; + lightring.led1 = green; + lightring.led2 = green; + lightring.led3 = green; + lightring.led4 = green; + lightring.led5 = green; + + create3_led_animation(Create3BlinkLights, lightring, 5.0); // Blink the lights green for 5 seconds. + + // Wait for 1 second + create3_wait(); + + printf("Done!\n"); + } + catch (const std::exception &e) + { + std::cerr << e.what() << '\n'; + } + + break; + } + case 6: // 07_sensors + { + try + { + printf("Connecting to Create3 robot...\n"); + + create3_connect_manual("192.168.125.1", 50051); + + printf("Connected!\n"); + + printf("Sensor Values:\n"); + printf(" Left Side Cliff: %d\n", create3_sensor_cliff(0)); + printf(" Left Front Cliff: %d\n", create3_sensor_cliff(1)); + printf(" Right Front Cliff: %d\n", create3_sensor_cliff(2)); + printf(" Right Side Cliff: %d\n", create3_sensor_cliff(3)); + printf("\n"); + printf(" Left Side IR: %d\n", create3_sensor_ir(0)); + printf(" Left IR: %d\n", create3_sensor_ir(1)); + printf(" Left Front IR: %d\n", create3_sensor_ir(2)); + printf(" Left Center IR: %d\n", create3_sensor_ir(3)); + printf(" Right Center IR: %d\n", create3_sensor_ir(4)); + printf(" Right Front IR: %d\n", create3_sensor_ir(5)); + printf(" Right IR: %d\n", create3_sensor_ir(6)); + + printf(" Left Bumper: %d\n", create3_sensor_bump(0)); + printf(" Left Front Bumper: %d\n", create3_sensor_bump(1)); + printf(" Center Front Bumper: %d\n", create3_sensor_bump(2)); + printf(" Right Front Bumper: %d\n", create3_sensor_bump(3)); + printf(" Right Bumper: %d\n", create3_sensor_bump(4)); + + while (create3_sensor_bump(3) == 0) + { + if (create3_sensor_bump(3) == 1) + { + create3_velocity_set_components(0.0, 0.0); + break; + } + create3_velocity_set_components(0.15, 0.0); + } + + printf("Done!\n"); + } + catch (const std::exception &e) + { + std::cerr << e.what() << '\n'; + } + } + + default: + break; } } diff --git a/ui/Create3Widget.ui b/ui/Create3Widget.ui index 9aed9b32..06c3bb09 100644 --- a/ui/Create3Widget.ui +++ b/ui/Create3Widget.ui @@ -25,7 +25,7 @@ - 0 + 11 0 @@ -41,6 +41,49 @@ 35 + + + + + + + 160 + 16777215 + + + + + 22 + + + + Create3 IP: + + + + + + + + 25 + 0 + + + + + 22 + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + @@ -130,87 +173,98 @@ QCheckBox::indicator:unchecked{ - - - - - - 160 - 16777215 - - - - - 22 - - - - Create3 IP: - - - - - - - - 25 - 0 - - - - - 22 - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - - - - 0 - 80 - - - - - 21 - - - - Create 3 Sensor List - - - - - - - - 0 - 80 - - - - - 21 - - - - Create 3 Example Programs - - - - + + + + 22 + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + 16777215 + 16777215 + + + + + 01_Connect + + + + + 02_Dock_Undock + + + + + 03_Move_Velocity + + + + + 04_Rotate + + + + + 05_Arc + + + + + 06_LED + + + + + 07_Sensors + + + + + + + + Run + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + From 0632bb91d97eab1e10c349b4f29e6c87e297732f Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 9 Apr 2024 12:38:52 -0500 Subject: [PATCH 05/10] Layout changes to Create3Widget --- src/Create3Widget.cpp | 2 +- ui/Create3Widget.ui | 109 ++++++++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 54 deletions(-) diff --git a/src/Create3Widget.cpp b/src/Create3Widget.cpp index 4e885d44..d1c4ce0d 100644 --- a/src/Create3Widget.cpp +++ b/src/Create3Widget.cpp @@ -41,7 +41,7 @@ Create3Widget::Create3Widget(Device *device, QWidget *parent) { ui->setupUi(this); performStandardSetup(tr("Create 3"), false); - setStyleSheet("QScrollBar:vertical {border: 2px solid grey;background:grey ;width: 100px; margin: 22px 0 22px 0; } QScrollBar::handle:vertical { border: 2px solid grey;background: white; min-height: 20px; } QScrollBar::add-line:vertical { border: 2px solid grey;background: #32CC99; height: 20px; subcontrol-position: bottom; subcontrol-origin: margin; } QScrollBar::sub-line:vertical {border: 2px solid grey; background: #32CC99; height: 20px; subcontrol-position: top; subcontrol-origin: margin; } QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { border: 2px solid grey;width: 3px; height: 3px; background: white; }QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {border: 2px solid grey; background: none;}"); + setStyleSheet("QScrollBar:vertical {border: 2px solid grey;background:grey ;width: 80px; margin: 22px 0 22px 0; } QScrollBar::handle:vertical { border: 2px solid grey;background: white; min-height: 20px; } QScrollBar::add-line:vertical { border: 2px solid grey;background: #32CC99; height: 20px; subcontrol-position: bottom; subcontrol-origin: margin; } QScrollBar::sub-line:vertical {border: 2px solid grey; background: #32CC99; height: 20px; subcontrol-position: top; subcontrol-origin: margin; } QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { border: 2px solid grey;width: 3px; height: 3px; background: white; }QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {border: 2px solid grey; background: none;}"); ui->create3IP->setText(getIP()); diff --git a/ui/Create3Widget.ui b/ui/Create3Widget.ui index 06c3bb09..428cf0c2 100644 --- a/ui/Create3Widget.ui +++ b/ui/Create3Widget.ui @@ -23,67 +23,70 @@ - + - 11 + 7 0 + + 0 + - - - 7 - - - 0 - - - 35 - + - - - - - - 160 - 16777215 - - - - - 22 - - - - Create3 IP: - - - - - - - - 25 - 0 - - - - - 22 - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - + + + + 180 + 16777215 + + + + + Ubuntu + 25 + false + true + + + + font: 700 25pt "Ubuntu"; + + + Create3 IP: + + + + + + + 25 + 0 + + + + + 22 + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + 10 + From 2a50bb8f30791668b9f7a4b47052f7858638257f Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 16 Apr 2024 14:19:05 -0500 Subject: [PATCH 06/10] Added includes --- src/Create3Widget.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Create3Widget.cpp b/src/Create3Widget.cpp index d1c4ce0d..e08edede 100644 --- a/src/Create3Widget.cpp +++ b/src/Create3Widget.cpp @@ -1,7 +1,7 @@ #include "Create3Widget.h" #include "ui_Create3Widget.h" #include "Create3SensorListWidget.h" - +#include "kj/exception.h" #include "Create3SensorModel.h" #include #include @@ -17,7 +17,7 @@ #include #include #include "RootController.h" - +#include "kipr/create3/create3.capnp.h" int exampleIndex; QStringList programList; @@ -372,6 +372,7 @@ void Create3Widget::indexChanged(int index) void Create3Widget::run() { + exampleIndex = ui->exampleComboBox->currentIndex(); switch (exampleIndex) { @@ -544,10 +545,13 @@ void Create3Widget::run() create3_wait(); printf("Done!\n"); + + } - catch (const std::exception &e) + // catch (const std::exception &e) + catch (const kj::Exception &e) { - std::cerr << e.what() << '\n'; + std::cerr << e << '\n'; } break; From 7da7e2eba290a143a43ac7b07e5bca206d86b3fd Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 11 Jun 2024 13:00:15 -0500 Subject: [PATCH 07/10] Tello Network Widget UI --- ui/TelloNetworksWidget.ui | 143 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 ui/TelloNetworksWidget.ui diff --git a/ui/TelloNetworksWidget.ui b/ui/TelloNetworksWidget.ui new file mode 100644 index 00000000..9c46062b --- /dev/null +++ b/ui/TelloNetworksWidget.ui @@ -0,0 +1,143 @@ + + + TelloNetworksWidget + + + + 0 + 0 + 800 + 480 + + + + Connect + + + + 6 + + + 6 + + + 6 + + + 0 + + + + + + + + 22 + + + + QAbstractItemView::NoEditTriggers + + + + + + + + + + 280 + 0 + + + + + 33 + + + + Connect + + + + :/icons/fontawesome/regular/icons/fontawesome/regular/handshake.svg:/icons/fontawesome/regular/icons/fontawesome/regular/handshake.svg + + + + 25 + 25 + + + + + + + + + 33 + + + + Other... + + + + :/icons/fontawesome/solid/icons/fontawesome/solid/podcast.svg:/icons/fontawesome/solid/icons/fontawesome/solid/podcast.svg + + + + 25 + 25 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + false + + + + 33 + + + + Refresh + + + + :/icons/fontawesome/solid/icons/fontawesome/solid/sync-alt.svg:/icons/fontawesome/solid/icons/fontawesome/solid/sync-alt.svg + + + + 25 + 25 + + + + + + + + + + + + + + + From 4afe887eb9fa9da21350ba18d953ca22423cb774 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 11 Jun 2024 14:00:04 -0500 Subject: [PATCH 08/10] Removed kj exception from catch --- src/Create3Widget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Create3Widget.cpp b/src/Create3Widget.cpp index e08edede..31e214bb 100644 --- a/src/Create3Widget.cpp +++ b/src/Create3Widget.cpp @@ -549,9 +549,9 @@ void Create3Widget::run() } // catch (const std::exception &e) - catch (const kj::Exception &e) + catch (const std::exception &e) { - std::cerr << e << '\n'; + std::cerr << e.what() << '\n'; } break; From 4b0a69ad45d6fd2c4214028097f40031a9f52d7d Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 11 Jun 2024 14:22:20 -0500 Subject: [PATCH 09/10] formatting adjustment to Create3 IP --- ui/Create3Widget.ui | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/Create3Widget.ui b/ui/Create3Widget.ui index 428cf0c2..328f3f66 100644 --- a/ui/Create3Widget.ui +++ b/ui/Create3Widget.ui @@ -35,11 +35,20 @@ + + 10 + - + 180 + 37 + + + + + 225 16777215 @@ -49,6 +58,9 @@ 25 false true + false + false + true From 8d0e64621bc5e6aafda7208cb40f5862d6163c35 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 11 Jun 2024 15:47:54 -0500 Subject: [PATCH 10/10] Removed TelloNetworksWidget.ui --- ui/TelloNetworksWidget.ui | 143 -------------------------------------- 1 file changed, 143 deletions(-) delete mode 100644 ui/TelloNetworksWidget.ui diff --git a/ui/TelloNetworksWidget.ui b/ui/TelloNetworksWidget.ui deleted file mode 100644 index 9c46062b..00000000 --- a/ui/TelloNetworksWidget.ui +++ /dev/null @@ -1,143 +0,0 @@ - - - TelloNetworksWidget - - - - 0 - 0 - 800 - 480 - - - - Connect - - - - 6 - - - 6 - - - 6 - - - 0 - - - - - - - - 22 - - - - QAbstractItemView::NoEditTriggers - - - - - - - - - - 280 - 0 - - - - - 33 - - - - Connect - - - - :/icons/fontawesome/regular/icons/fontawesome/regular/handshake.svg:/icons/fontawesome/regular/icons/fontawesome/regular/handshake.svg - - - - 25 - 25 - - - - - - - - - 33 - - - - Other... - - - - :/icons/fontawesome/solid/icons/fontawesome/solid/podcast.svg:/icons/fontawesome/solid/icons/fontawesome/solid/podcast.svg - - - - 25 - 25 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - false - - - - 33 - - - - Refresh - - - - :/icons/fontawesome/solid/icons/fontawesome/solid/sync-alt.svg:/icons/fontawesome/solid/icons/fontawesome/solid/sync-alt.svg - - - - 25 - 25 - - - - - - - - - - - - - - -