Browse Source

init structs on declaration is not alowed in c99

master
philipp schoenberger 10 years ago
parent
commit
b207716f96
  1. 66
      lwrserv/include/Trajectroy.h
  2. 18
      lwrserv/src/commands.cpp
  3. 16
      lwrserv/src/main.cpp

66
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[] =
}* trajectoryTypeStr = NULL;
/// END OF TRAJECTORY LIST
static void initTrajectoryType ()
{
if (trajectoryTypeStr == NULL)
{
{ .type = TrajectoryJointLinear , .str="JointLinear" },
{ .type = TrajectoryJointLSPB , .str="JointLSPB" },
{ .type = TrajectoryJointBangBang, .str="JointBangBang" },
{ .type = TrajectoryJointFivePoly, .str="JointFivePoly" },
trajectoryTypeStr = new struct TrajectoryTypeStr[__TrajectoryCount];
{ .type = TrajectoryCartLinear , .str="CartLinear" },
{ .type = TrajectoryCartLSPB , .str="CartLSPB" },
{ .type = TrajectoryCartBangBang, .str="CartBangBang" },
{ .type = TrajectoryCartFivePoly, .str="CartFivePoly" },
};
/// END OF TRAJECTORY LIST
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;
}

18
lwrserv/src/commands.cpp

@ -1,6 +1,6 @@
/**
* @file
* @author John Doe <jdoe@example.com>
* @author Philipp Schoenberger <ph.schoenberger@googlemail.com>
* @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 <stdlib.h>
#include <string>
@ -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<Robot::joints>* 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)
{

16
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 <ph.schoenberger@googlemail.com>
*/
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;
}
Loading…
Cancel
Save