Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6a561e0
omnibase test
Tupryk Dec 4, 2023
e771095
omnibase kinda moves
Tupryk Dec 5, 2023
e59e601
Updated PD and jacobian parameters
Tupryk May 8, 2024
aebd049
Merge branch 'MarcToussaint:master' into master
Tupryk May 8, 2024
e5f3b14
Update omnibase.cpp
Tupryk May 8, 2024
9ad59ab
Update rai.cfg
Tupryk May 8, 2024
7db32be
Changed Omnibase x sign in jacobian
Tupryk May 8, 2024
f8030a5
new pd controller and adjusted parameters
Tupryk Jun 28, 2024
1478d32
Velocity controller done
Tupryk Jul 5, 2024
a06ccb2
gamepad test scripts
Tupryk Jul 5, 2024
ddf30b1
gamepad module added
Tupryk Jul 5, 2024
5f28f80
adjustable jacobian values
Tupryk Sep 22, 2024
9d08080
bug fix?
Tupryk Sep 22, 2024
794b19d
ranger code init
Tupryk Jan 22, 2025
6da6988
updated ranger init
Tupryk Jan 22, 2025
9f86b7a
added ranger to bot.cpp
Tupryk Jan 28, 2025
7c032cd
Ranger for TransX joint
Tupryk Jan 28, 2025
d334353
oblique and spin mode qorking with odometry
Tupryk Mar 14, 2025
bf2af56
ranger works on oblique and spin mode
Tupryk Mar 18, 2025
45f77f2
Ranger test script
Tupryk Mar 18, 2025
08457e6
Merge branch 'MarcToussaint:master' into master
Tupryk Mar 24, 2025
caf7b21
livox init
Tupryk Mar 24, 2025
be57c25
livox init
Tupryk Mar 24, 2025
66204d4
Livox tests
Tupryk Mar 25, 2025
7650e3c
removed extra functions
Tupryk Mar 25, 2025
7b856bd
fixed stalling issues
Tupryk Mar 26, 2025
28161d4
some bug fixes and added slam
Tupryk Mar 26, 2025
9e666b4
new ranger code
Tupryk Jul 8, 2025
5f76f61
ranger control and data collection
Tupryk Jul 8, 2025
b89c758
updated main
Tupryk Dec 15, 2025
fc4094e
hackathon updates
Tupryk Dec 15, 2025
be60331
more updates from hackathon
Tupryk Dec 15, 2025
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
61 changes: 51 additions & 10 deletions src/BotOp/bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include <Franka/FrankaGripper.h>
#include "simulation.h"
#include <Omnibase/omnibase.h>
#include <Ranger/ranger.h>
#include <Robotiq/RobotiqGripper.h>
#include <OptiTrack/optitrack.h>
#include <Livox/livox.h>
#include <RealSense/RealSenseThread.h>
#ifdef RAI_VIVE
# include <ViveController/vivecontroller.h>
Expand Down Expand Up @@ -42,12 +44,12 @@ BotOp::BotOp(rai::Configuration& C, bool useRealRobot){
if(useRealRobot && useGripper){
LOG(0) <<"CONNECTING TO GRIPPERS";
try{
if(C.getFrame("l_panda_hand", false) && C.getFrame("r_panda_hand", false)){
if(C.getFrame("l_panda_finger_joint1", false) && C.getFrame("r_panda_finger_joint1", false)){
gripperL = make_shared<FrankaGripper>(0);
gripperR = make_shared<FrankaGripper>(1);
}else if(C.getFrame("l_panda_hand", false)){
}else if(C.getFrame("l_panda_finger_joint1", false)){
gripperL = make_shared<FrankaGripper>(0);
}else if(C.getFrame("r_panda_hand", false)){
}else if(C.getFrame("r_panda_finger_joint1", false)){
gripperR = make_shared<FrankaGripper>(1);

}else if(C.getFrame("l_robotiq_base", false) && C.getFrame("r_robotiq_base", false)){
Expand All @@ -61,6 +63,10 @@ BotOp::BotOp(rai::Configuration& C, bool useRealRobot){
} catch(const std::exception& ex) {
LOG(-1) <<"Starting the gripper(s) failed! Error msg: " <<ex.what();
}

if(!gripperL && !gripperR){
LOG(0) <<"WARNING: no grippers created (no frames l_panda_finger_joint1 or l_robotiq_base found in config)";
}
}

if(useRealRobot){
Expand All @@ -71,6 +77,7 @@ BotOp::BotOp(rai::Configuration& C, bool useRealRobot){
robotL = make_shared<FrankaThread>(robotID++, franka_getJointIndices(C,'l'), cmd, state);
robotR = make_shared<FrankaThread>(robotID++, franka_getJointIndices(C,'r'), cmd, state);
} else if(C.getFrame("l_panda_base", false)){
std::cout << franka_getJointIndices(C,'l') << std::endl;
robotL = make_shared<FrankaThread>(robotID++, franka_getJointIndices(C,'l'), cmd, state);
} else if(C.getFrame("r_panda_base", false)){
robotR = make_shared<FrankaThread>(robotID++, franka_getJointIndices(C,'r'), cmd, state);
Expand All @@ -93,6 +100,15 @@ BotOp::BotOp(rai::Configuration& C, bool useRealRobot){
LOG(-1) <<"Starting the omnibase failed! Error msg: " <<ex.what();
}

try{
if(C.getFrame("ranger_base", false)){
LOG(0) <<"CONNECTING TO RANGER";
robotR = make_shared<RangerThread>(robotID++, uintA{0,1,2}, cmd, state);
}
} catch(const std::exception& ex) {
LOG(-1) <<"Starting the ranger failed! Error msg: " <<ex.what();
}

}else{
simthread = make_shared<BotThreadedSim>(C, cmd, state);
robotL = simthread;
Expand All @@ -112,6 +128,13 @@ BotOp::BotOp(rai::Configuration& C, bool useRealRobot){
optitrack->pull(C);
}

if(rai::getParameter<bool>("bot/useLivox", false)){
LOG(0) <<"OPENING LIVOX";
if(!useRealRobot) LOG(-1) <<"useLivox with real:false -- that's usually wrong!";
livox = make_shared<rai::Livox>();
livox->pull(C);
}

#ifdef RAI_VIVE
//-- launch ViveController
if(rai::getParameter<bool>("bot/useViveController", false)){
Expand All @@ -127,8 +150,8 @@ BotOp::BotOp(rai::Configuration& C, bool useRealRobot){
audio = make_shared<rai::Sound>();
}

C.gl().setTitle("BotOp associated Configuration");
C.view(false, STRING("time: 0"));
C.gl().setTitle("BotOp associated Configuration");
}

BotOp::~BotOp(){
Expand Down Expand Up @@ -199,6 +222,7 @@ int BotOp::sync(rai::Configuration& C, double waitTime, rai::String viewMsg){

//update optitrack state
if(optitrack) optitrack->pull(C);
if(livox) livox->pull(C);

#ifdef RAI_VIVE
//update vivecontroller state
Expand All @@ -221,16 +245,17 @@ int BotOp::sync(rai::Configuration& C, double waitTime, rai::String viewMsg){
return keypressed;
}

int BotOp::wait(rai::Configuration& C, bool forKeyPressed, bool forTimeToEnd, bool forGripper){
int BotOp::wait(rai::Configuration& C, bool forKeyPressed, bool forTimeToEnd, bool forGripper, double syncFrequency){
C.get_viewer()->raiseWindow();
C.get_viewer()->_resetPressedKey();
sync(C);
for(;;){
sync(C, .1);
//if(keypressed=='q') return keypressed;
if(forKeyPressed && keypressed) return keypressed;
if(forTimeToEnd && getTimeToEnd()<=0.) return keypressed;
if(forGripper && gripperDone(rai::_left)) return 'g';
if(!rai::getInteractivity() && !forTimeToEnd && forKeyPressed) return ' ';
sync(C, syncFrequency);
}
}

Expand Down Expand Up @@ -298,13 +323,13 @@ void BotOp::move_oldCubic(const arr& path, const arr& times, bool overwrite, dou
arr tauInitial = {};
if(!optTau) tauInitial = differencing(_times);
TimingProblem timingProblem(path, {}, q, qDot, 1., 1., optTau, false, {}, tauInitial);
NLP_Solver solver;
rai::NLP_Solver solver;
solver
.setProblem(timingProblem.ptr())
.setSolver(NLPS_newton);
.setSolver(rai::M_Newton);
solver.opt
.set_stopTolerance(1e-4)
.set_maxStep(1e0)
->set_stopTolerance(1e-4)
.set_stepMax(1e0)
.set_damping(1e-2);
auto ret = solver.solve();
//LOG(1) <<"timing f: " <<ret->f;
Expand Down Expand Up @@ -468,6 +493,22 @@ void BotOp::sound(int noteRelToC, float a, float decay){
}
}

void BotOp::attach(str from, str to) {
if(!simthread){
LOG(-1) <<"attach only works in sim";
}else{
simthread->attach(from, to);
}
}

void BotOp::detach(str from, str to){
if(!simthread){
LOG(-1) <<"attach only works in sim";
}else{
simthread->detach(from, to);
}
}

//===========================================================================

void ZeroReference::getReference(arr& q_ref, arr& qDot_ref, arr& qDDot_ref, const arr& q_real, const arr& qDot_real, double ctrlTime){
Expand Down
10 changes: 8 additions & 2 deletions src/BotOp/bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace rai{
struct GripperAbstraction;
struct OptiTrack;
struct Livox;
struct ViveController;
struct Sound;
}
Expand All @@ -24,6 +25,7 @@ struct BotOp{
std::shared_ptr<rai::GripperAbstraction> gripperR;
std::shared_ptr<rai::ReferenceFeed> ref;
std::shared_ptr<rai::OptiTrack> optitrack;
std::shared_ptr<rai::Livox> livox;
std::shared_ptr<rai::ViveController> vivecontroller;
std::shared_ptr<rai::Sound> audio;
std::shared_ptr<BotThreadedSim> simthread;
Expand Down Expand Up @@ -68,8 +70,8 @@ struct BotOp{
arr getCameraFxycxy(const char* sensor);

//-- sync the user's C with the robot, update the display, return pressed key
int sync(rai::Configuration& C, double waitTime=.1, rai::String viewMsg={});
int wait(rai::Configuration& C, bool forKeyPressed=true, bool forTimeToEnd=true, bool forGripper=false);
int sync(rai::Configuration& C, double waitTime=.05, rai::String viewMsg={});
int wait(rai::Configuration& C, bool forKeyPressed=true, bool forTimeToEnd=true, bool forGripper=false, double syncFrequency=.05);

//-- motion macros
void home(rai::Configuration& C);
Expand All @@ -79,6 +81,10 @@ struct BotOp{
//-- audio
void sound(int noteRelToC=0, float a=.5, float decay=0.0007);

//-- cheating in sim
void attach(str from, str to);
void detach(str from, str to);

private:
std::shared_ptr<rai::CameraAbstraction>& getCamera(const char* sensor);
template<class T> BotOp& setReference();
Expand Down
13 changes: 13 additions & 0 deletions src/Gamepad/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BASE = ../../rai
NAME = $(shell basename `pwd`)
OUTPUT = lib$(NAME).so

PLIB=1

OPTIM = debug
DEPEND = Core

SRCS = $(shell find . -maxdepth 1 -name '*.cpp' )
OBJS = $(SRCS:%.cpp=%.o)

include $(BASE)/makeutils/generic.mk
71 changes: 71 additions & 0 deletions src/Gamepad/gamepad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "gamepad.h"

#ifdef RAI_PLIB

#include <plib/js.h>
#undef min
#undef max

GamepadInterface::GamepadInterface()
: Thread("GamepadInterface", .01) {
threadLoop(true);
}

GamepadInterface::~GamepadInterface(){
threadClose();
}

void GamepadInterface::open(){
jsInit();
for(uint i=0;;i++){
joystick = new jsJoystick(i);
if(joystick->notWorking()) break;
uint n=joystick->getNumAxes();

std::cout << "name = " << joystick->getName()
<< "\n#axis = " << joystick->getNumAxes()
// << " \n#buttons = " <<gamepad->getNumButtons()
<< "\nerror? = " <<joystick->notWorking()
<< std::endl;

if(n>=4 && n<=8) break;
//iterate and try a new one
delete joystick;
}
step(); //clear the buffers...
}

void GamepadInterface::close(){
delete joystick;
gamepadState.set()->clear();
}

void GamepadInterface::step(){
if(joystick->notWorking()) return;
uint n=joystick->getNumAxes();
floatA A(n);
int B;
joystick->rawRead(&B, A.p);
gamepadState.writeAccess();
gamepadState().resize(n+1);
gamepadState()(0)=B;
for(uint i=0; i<n; i++) gamepadState()(i+1)=(double)A(i)/(1<<15);
if(step_count>20 && stopButtons(gamepadState())){
LOG(1) <<"*** STOP button pressed";
// moduleShutdown()->incrementStatus();
quitSignal.set()=true;
}
gamepadState.deAccess();

}

#else //dummy implementations
GamepadInterface::GamepadInterface()
: Thread("GamepadInterfaceINACTIVE") {}
GamepadInterface::~GamepadInterface(){ }
void GamepadInterface::open(){ gamepadState.set()->resize(10); gamepadState.set()->setZero(); RAI_MSG("WARNING: dummy gamepad implementation"); }
void GamepadInterface::step(){ }
void GamepadInterface::close(){ }
#endif


48 changes: 48 additions & 0 deletions src/Gamepad/gamepad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef RAI_gamepad_h
#define RAI_gamepad_h

#include <Core/array.h>
#include <Core/thread.h>

struct GamepadInterface : Thread {
struct jsJoystick *joystick;
Var<arr> gamepadState;
Var<bool> quitSignal;
GamepadInterface();
~GamepadInterface();
void open();
void step();
void close();
};

/// The buttons on gamepad have the following values.
/// Note that you can use the binary operators & and | to check for multiple
/// button presses.
enum BUTTON {
BTN_NONE = 0,
BTN_A = 1,
BTN_B = 2,
BTN_X = 4,
BTN_Y = 8,
BTN_LB = 16,
BTN_RB = 32,
BTN_LT = 64,
BTN_RT = 128,
BTN_BACK = 256,
BTN_START = 512,
BTN_LSTICK = 1024,
BTN_RSTICK = 2048,
};

inline bool stopButtons(const arr& gamepadState){
if(!gamepadState.N) return false;
uint mode = uint(gamepadState(0));
if(mode&BTN_LB || mode&BTN_RB || mode&BTN_LT || mode&BTN_RT) return true;
return false;
}

#ifdef RAI_IMPLEMENTATION
# include "gamepad.cpp"
#endif

#endif
Loading