diff --git a/lwrserv/include/Trajectroy.h b/lwrserv/include/Trajectroy.h index 6c70a7a..fdd2aa6 100644 --- a/lwrserv/include/Trajectroy.h +++ b/lwrserv/include/Trajectroy.h @@ -31,42 +31,70 @@ enum TrajectoryType { TrajectoryCartFivePoly, TrajectoryJointLSPB, - TrajectoryCartLSPB + TrajectoryCartLSPB, + __TrajectoryCount }; -static struct { +static struct TrajectoryTypeStr{ enum TrajectoryType type; std::string str; -} TrajectoryTypeStr[] = -{ - { .type = TrajectoryJointLinear , .str="JointLinear" }, - { .type = TrajectoryJointLSPB , .str="JointLSPB" }, - { .type = TrajectoryJointBangBang, .str="JointBangBang" }, - { .type = TrajectoryJointFivePoly, .str="JointFivePoly" }, - - { .type = TrajectoryCartLinear , .str="CartLinear" }, - { .type = TrajectoryCartLSPB , .str="CartLSPB" }, - { .type = TrajectoryCartBangBang, .str="CartBangBang" }, - { .type = TrajectoryCartFivePoly, .str="CartFivePoly" }, -}; +}* trajectoryTypeStr = NULL; /// END OF TRAJECTORY LIST +static void initTrajectoryType () +{ + if (trajectoryTypeStr == NULL) + { + trajectoryTypeStr = new struct TrajectoryTypeStr[__TrajectoryCount]; + + int i = 0; + + trajectoryTypeStr[i].type = TrajectoryJointLinear; + trajectoryTypeStr[i].str = "JointLinear"; + ++i; + trajectoryTypeStr[i].type = TrajectoryJointLSPB; + trajectoryTypeStr[i].str = "JointLSPB"; + ++i; + trajectoryTypeStr[i].type = TrajectoryJointBangBang; + trajectoryTypeStr[i].str = "JointBangBang"; + ++i; + trajectoryTypeStr[i].type = TrajectoryJointFivePoly; + trajectoryTypeStr[i].str = "JointFivePoly"; + ++i; + + trajectoryTypeStr[i].type = TrajectoryCartLinear; + trajectoryTypeStr[i].str = "CartLinear"; + ++i; + trajectoryTypeStr[i].type = TrajectoryCartLSPB; + trajectoryTypeStr[i].str = "CartLSPB"; + ++i; + trajectoryTypeStr[i].type = TrajectoryCartBangBang; + trajectoryTypeStr[i].str = "CartBangBang"; + ++i; + trajectoryTypeStr[i].type = TrajectoryCartFivePoly; + trajectoryTypeStr[i].str = "CartFivePoly"; + ++i; + } +} + static std::string toString(enum TrajectoryType type) { - int items = sizeof(TrajectoryTypeStr) / sizeof(TrajectoryTypeStr[0]); + initTrajectoryType(); + int items = __TrajectoryCount; for (int i = 0 ; i < items ; ++i) { - if (TrajectoryTypeStr[i].type == type) - return ""+ TrajectoryTypeStr[i].str; + if (trajectoryTypeStr[i].type == type) + return ""+ trajectoryTypeStr[i].str; } return "default"; } static enum TrajectoryType toEnum(std::string name) { - int items = sizeof(TrajectoryTypeStr) / sizeof(TrajectoryTypeStr[0]); + initTrajectoryType(); + int items = __TrajectoryCount; for (int i = 0 ; i < items ; ++i) { - if (TrajectoryTypeStr[i].str == name) - return TrajectoryTypeStr[i].type; + if (trajectoryTypeStr[i].str == name) + return trajectoryTypeStr[i].type; } return TrajectoryDefault; } diff --git a/lwrserv/src/commands.cpp b/lwrserv/src/commands.cpp index 4d5327e..3932185 100644 --- a/lwrserv/src/commands.cpp +++ b/lwrserv/src/commands.cpp @@ -1,6 +1,6 @@ /** * @file - * @author John Doe + * @author Philipp Schoenberger * @version 1.0 * * @section LICENSE @@ -18,7 +18,7 @@ * * @section DESCRIPTION * - * The time class represents a moment of time. + * This file contains the commands for the client interface */ #include #include @@ -41,15 +41,25 @@ #include "StringTool.h" +/** + * Creates a trajectory form last commanded position. + * After this the trajectory is added to the queue for the + * robot interface thread which is processing the trajectory + * The function will wait until the trajectory is executed + * + * @param newJointPos the Joint values for the new position + */ void moveRobotTo(Robot::VecJoint newJointPos) { + /// create a trajectory with the current set trajectory type by the helper function Trajectory* newTrajectory = SvrData::getInstance()->createTrajectory(newJointPos); - // add trajectory to queue for sender thread + /// add trajectory to queue for robot interface thread SvrData::getInstance()->pushTrajectory(newTrajectory); + /// save new joint position for the next trajectory SvrData::getInstance()->setCommandedJointPos(newJointPos); - //Wait to end of movement + ///wait to end of processing/movement float sampleTimeMs = SvrData::getInstance()->getSampleTimeMs(); while (true) { diff --git a/lwrserv/src/main.cpp b/lwrserv/src/main.cpp index c2c6c01..dc5b4f6 100644 --- a/lwrserv/src/main.cpp +++ b/lwrserv/src/main.cpp @@ -12,13 +12,22 @@ #include "Mat.h" #include "Vec.h" +/** + * starts the Interface for the robot interface fri and also the client interface. + * Each one is running in a spearate threadwise + * + * @retval 0 if no error is occuring otherwise the negative errno code + * + * @author philipp schoenberger + */ int main() { int err = 0; - //Setting pthread for FRI interface + + ///Setting pthread for FRI interface pthread_t fri_t; - //Start the thread for the robot movement + ///Start the thread for the robot movement err = pthread_create(&fri_t,NULL,&SvrHandling::threadRobotMovement,NULL); if (err > 0 ) { @@ -26,7 +35,7 @@ int main() return err; } - //Start client handling + ///Start client handling with main thread SvrHandling *svr = new SvrHandling(); if (svr == NULL) { @@ -35,5 +44,6 @@ int main() } svr->run(); + /// return ok should never happen cause the programm runs as a deamon return 0; }