Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cwbollinger/mobile api wip #69

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
103 changes: 103 additions & 0 deletions kits/base/omni_mobile_io_control.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

#include "util/mobile_io.hpp"
#include "util/omni_base.hpp"

using namespace hebi;
using namespace experimental;
using namespace mobile;


int main(int argc, char* argv[]) {

//////////////////////////
//// MobileIO Setup //////
//////////////////////////

std::cout << "Creating MobileIO" << std::endl;

std::string family = "Rosie";

// Create the MobileIO object
std::unique_ptr<MobileIO> mobile = MobileIO::create(family, "mobileIO");
while(!mobile) {
std::cout << "Couldn't find mobileIO, trying again..." << std::endl;
mobile = MobileIO::create(family, "mobileIO");
}

std::string instructions("A1/A2 - Move Base\n"
"A7 - Turn Base\n"
"B8 - Quit\n");

// Clear any garbage on screen
mobile -> clearText();

// Display instructions on screen
mobile -> sendText(instructions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these have bool return values; I'm not sure about the balance between making the example more complex vs. more robust by handling them


//////////////////////////
//// OmniBase Setup //////
//////////////////////////

// Set module names for mobile base
OmniBase::Params p;
p.families_ = {family};
p.names_ = {"W1", "W2", "W3"};

std::cout << "Creating Omni Base" << std::endl;

auto base = OmniBase::create(p);

if (!base) {
std::cout << "Failed to create base, exiting!" << std::endl;
exit(EXIT_FAILURE);
}

auto last_state = mobile->getState();

//////////////////////////
//// Main Control Loop ///
//////////////////////////

while(base->update())
{
auto state = mobile->getState();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me...I think we still need to fix the MobileIO::getState call to not block in C++, or accept a timeout. I'll track this as a separate issue.

MobileIODiff diff(last_state, state);

/////////////////
// Input Handling
/////////////////

auto dy = -1 * state.getAxis(7) / 2.0;
auto dx = state.getAxis(8) / 2.0;
auto dtheta = -1 * state.getAxis(1);

// Button B8 - End Demo
if (diff.get(8) == MobileIODiff::ButtonState::ToOn)
{
// Clear MobileIO text
mobile->clearText();
return 1;
}

/////////////////
// Update & send
/////////////////

// create Vel Goal for 0.5 second, 0.25 second ramp down
auto goal = CartesianGoal::createFromVelocity(Vel{dx, dy, dtheta}, 0.5, 0.25);

// send goal to base
base->setGoal(goal);

// Update to the new last_state for mobile device
last_state = state;

// Send latest commands to the base
base->send();
}

// Clear MobileIO text
mobile -> clearText();

return 0;
};
75 changes: 75 additions & 0 deletions kits/base/omni_waypoints.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

#include "util/omni_base.hpp"

using namespace hebi;
using namespace experimental;
using namespace mobile;


int main(int argc, char* argv[]) {

//////////////////////////
//// OmniBase Setup //////
//////////////////////////

// Set module names for mobile base
OmniBase::Params p;
p.families_ = {"Rosie"};
p.names_ = {"W1", "W2", "W3"};

std::cout << "Creating Omni Base" << std::endl;

auto base = OmniBase::create(p);

if (!base) {
std::cout << "Failed to create base, exiting!" << std::endl;
exit(EXIT_FAILURE);
}

auto currentPose = base->getOdometry();

Waypoint wp1;
Waypoint wp2;
Waypoint wp3;
Waypoint wp4;

wp1.t = 1.0;
wp1.pos = currentPose;

wp2 = wp1;
wp2.t += 1.0;
wp2.pos.x += 0.5;

wp3 = wp2;
wp3.t += 1.0;
wp3.pos.y += 0.5;

wp4 = wp3;
wp4.t += 1.0;
wp4.pos.x -= 0.5;

auto goal = CartesianGoal::createFromWaypoints({wp1, wp2, wp3, wp4}, false);

// send goal to base
base->setGoal(goal);

//////////////////////////
//// Main Control Loop ///
//////////////////////////

std::cout << "Executing Goal" << std::endl;
return -1;

while (base->update())
{
// Send updated command to the base
base->send();

// if the trajectory has been completed, start another square
if (base->goalComplete()) {
base->setGoal(goal);
}
}

return 0;
};
33 changes: 32 additions & 1 deletion projects/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,44 @@ endforeach (EXAMPLE ${KIT_SOURCES})
file(COPY ${ROOT_DIR}/kits/arm/hrdf DESTINATION ${ROOT_DIR}/build/kits/arm)
file(COPY ${ROOT_DIR}/kits/arm/gains DESTINATION ${ROOT_DIR}/build/kits/arm)

SET(BASE_SOURCES

${ROOT_DIR}/kits/base/omni_waypoints.cpp
${ROOT_DIR}/kits/base/omni_mobile_io_control.cpp)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY kits/base)
foreach (EXAMPLE ${BASE_SOURCES})

# The target for the individual example is based on the filename
get_filename_component(EX_NAME ${EXAMPLE} NAME_WE)

if(WIN32)
add_executable(${EX_NAME} ${EXAMPLE} $<TARGET_OBJECTS:_hebic++-obj>)
else()
add_executable(${EX_NAME} ${EXAMPLE})
endif()
add_dependencies(examples ${EX_NAME})
target_include_directories(${EX_NAME} PRIVATE ${ROOT_DIR})

target_include_directories(${EX_NAME} PRIVATE ${PYTHON_INCLUDE_DIRS})
target_link_libraries(${EX_NAME} ${PYTHON_LIBRARIES})
if(WIN32)
target_link_libraries(${EX_NAME} hebi kernel32)
target_include_directories(${EX_NAME} PRIVATE ${HEBI_DIR}/src ${HEBI_DIR}/include ${HEBI_DIR}/Eigen)
# For Windows, we copy the .dll file into the binary directory so that we
# don't have to set the PATH variable.

set(LIBHEBI_LOCATION "lib/win_${LIBHEBI_TARGET_ARCHITECTURE}")
set(HEBI_CPP_LIB_DIRECTORY ${HEBI_DIR}/hebi/${LIBHEBI_LOCATION}/)

add_custom_command(TARGET ${EX_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${HEBI_CPP_LIB_DIRECTORY}/hebi.dll"
$<TARGET_FILE_DIR:${EX_NAME}>)
elseif(UNIX)
target_link_libraries(${EX_NAME} hebi hebic++ m pthread)
endif()


endforeach (EXAMPLE ${BASE_SOURCES})
Comment on lines +318 to +356
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really should add a CMake function here to help clean this and the other content up. I'm adding a issue for this post-merge.



Loading