23 TiXmlHandle handle(xml);
24 TiXmlElement* element=handle.FirstChild(tag).Element();
25 sscanf(element->GetText(),
"%lf", value);
30 TiXmlHandle handle(xml);
31 TiXmlElement* element=handle.FirstChild(tag).Element();
53 TiXmlHandle handle(xml);
54 TiXmlElement* element=handle.FirstChild(tag).Element();
66 TiXmlDocument doc(filename);
67 if (graspTableObject ==
NULL)
69 printf(
"GraspTable::ReadFromFile:Error, argument error%s\n",filename);
74 printf(
"GraspTable::ReadFromFile:Error, could not read %s\n",filename);
78 TiXmlHandle root_handle(&doc);
79 TiXmlHandle grasp_list_handle=root_handle.FirstChild(
"GraspList");
80 TiXmlElement* number_element=grasp_list_handle.FirstChildElement(
"Number").Element();
83 sscanf(number_element->GetText(),
"%d", &number);
85 if (graspTableObject->
Init(number) != 0)
87 printf(
"GraspTable::ReadFromFile:Error, could not allocate GraspTableObject\n");
90 for (
int i=0; i<number; i++)
92 TiXmlHandle grasp_handle=grasp_list_handle.ChildElement(
"Grasp", i);
93 TiXmlElement* grasp_element=grasp_handle.Element();
95 grasp_element->QueryDoubleAttribute(
"Quality", &quality);
100 std::vector<double>
values;
102 ReadPose(grasp_element,
"ApproachPose", values);
105 ReadPose(grasp_element,
"GraspPose", values);
108 ReadJoint(grasp_element,
"ApproachJoint", values);
111 ReadJoint(grasp_element,
"GraspJoint", values);
114 ReadJoint(grasp_element,
"GraspOptimalJoint", values);
117 graspTableObject->
AddGrasp(newGrasp);
126 FILE*
f = fopen(object_table_file,
"r");
127 int numberOfObjects = 0;
131 printf(
"GraspTable::Error, Object Table File not found :%s\n",object_table_file);
134 fscanf(f,
"%d\n",&numberOfObjects);
136 for (
unsigned int i=0;i < table_size;i++)
140 for (
int obj=0; obj <numberOfObjects; obj++)
142 char GraspTableFileName[500];
143 int objectClassId = 0;
144 fscanf(f,
"%d, %s\n",&objectClassId,GraspTableFileName);
146 std::string object_table_file_str=object_table_file;
147 unsigned found = object_table_file_str.find_last_of(
"/");
148 std::string filepath = object_table_file_str.substr(0, found);
149 std::string grasp_table_file_str = filepath +
'/' + GraspTableFileName;
150 strncpy(GraspTableFileName, grasp_table_file_str.c_str(),
sizeof(GraspTableFileName));
151 GraspTableFileName[
sizeof(GraspTableFileName) - 1] = 0;
153 printf(
"GraspTable::Init: Trying to read grasp table for object %d from file %s ...\n",objectClassId,GraspTableFileName);
156 if (
ReadFromFile(GraspTableFileName,graspTableObject)==0)
158 printf(
"successful\n");
171 unsigned int objectClassId =
object->GetObjectClassId();
178 printf(
"GraspTable::AddGraspTableObject: Error, class id larger than table size!\n");
Grasp * GetGrasp(unsigned int object_class_id, unsigned int &grasp_id)
int ReadFromFile(const char *filename, GraspTableObject *tableObject)
std::vector< GraspTableObject * > m_GraspTable
unsigned int m_lastObjectClassId
void SetObjectClassId(unsigned int ObjectClassId)
std::vector< double > values
Grasp * GetNextGrasp(unsigned int object_class_id)
void SetHandOptimalGraspConfig(std::vector< double > HandOptimalGraspConfig)
void SetTCPPreGraspPose(std::vector< double > TCPPreGraspPose)
void ReadJoint(TiXmlElement *xml, const char *tag, std::vector< double > &values)
void SetGraspId(int graspId)
void SetTCPGraspPose(std::vector< double > TCPGraspPose)
void AddGraspTableObject(GraspTableObject *graspTableObject)
void SetHandGraspConfig(std::vector< double > HandGraspConfig)
int Init(char *iniFile, unsigned int table_size=MAX_NO_OF_OBJECTS)
void ReadPose(TiXmlElement *xml, const char *tag, std::vector< double > &values)
void ReadDoubleValue(TiXmlElement *xml, const char *tag, double *value)
void SetHandPreGraspConfig(std::vector< double > HandPreGraspConfig)
void AddGrasp(Grasp *grasp)
void ResetReadPtr(unsigned int object_class_id)