int main(int argc, const char * argv[]) { Node* list=NULL; addNodes(&list, 11,1,2,11,3,4,5,6,7,8,9,10); printf("test delete..\n"); deleteNode(&list, 11); printList(list); printf("\ntest reverse..\n"); printList(reverse(&list)); //reverse back reverse(&list); printf("\nmake ring at 10..\n"); findNode(list, 10)->next=findNode(list, 1); auto ringAt=findCircleStart(list); printf("find ring at %d",findCircleStart(list)?ringAt->data:-1); printf("\nbreak ring..\n"); findCircleStart(list)->next=NULL; printf("is ring? %s",findCircleStart(list)?"yes":"no"); return 0; }
int main() { int N; scanf ("%d",&N); List l1, l2; for (int i = 0; i < N; i++) { int val; scanf ("%d",&val); l1.add (val); } int n1; scanf ("%d",&n1); for (int i = 0; i < n1; i++) { int val; scanf ("%d",&val); l2.add (val); } if (l1.length() < l2.length()) { int k = l2.length() - l1.length(); while (k--) { addNodes (0, 0, l1); l1.incr_size(); } } else { int k = l1.length() - l2.length(); while (k--) { addNodes (0, 0, l2); l2.incr_size (); } } traverse (l1); traverse (l2); cout << "+" << "\n"; Node* l1_head = l1.getHead(); Node* l2_head = l2.getHead(); add (l1_head, l2_head); traverse (l3); return 0; }
//交叉 void crossover() { randomArrangeCDS(); //分组准备交叉,两两一组 for (int i = 0; i < countOfDominatingSets; i++) { randomArrangeNodesOfCDS(i); } printf("分组的结果是:\n"); printDominatingSets();//打印所有支配集 for (int i = 0; i < countOfDominatingSets; i++) { //找出要交叉的两组中支配集节点个数少的那一个 int maxIndex = countOfBlackNodesArr[i]; if (countOfBlackNodesArr[i+1] < countOfBlackNodesArr[i]) { maxIndex = countOfBlackNodesArr[i+1]; } //生成交叉区间 int startIndex = rand() % maxIndex; int endIndex = rand() % maxIndex; if (startIndex > endIndex) { int tmp = startIndex; startIndex = endIndex; endIndex = tmp; } //记录交叉的节点 chiasmatypyItems[i][0] = endIndex - startIndex + 1; chiasmatypyItems[i+1][0] = endIndex - startIndex + 1; for (int j = 0; j < endIndex - startIndex + 1; j++) { chiasmatypyItems[i][j+1] = dominatingSetsArr[i][startIndex + j]; chiasmatypyItems[i+1][j+1] = dominatingSetsArr[i+1][startIndex + j]; } printf("下标为 %2d 和 %2d 的个体交叉了:下标从 %2d 到 %2d 的项\n", i, i + 1, startIndex, endIndex); //开始交叉 for (int j = startIndex; j <= endIndex; j++) { if (dominatingSetsArr[i][j] != dominatingSetsArr[i+1][j]) { int tmp = dominatingSetsArr[i][j]; dominatingSetsArr[i][j] = dominatingSetsArr[i+1][j]; dominatingSetsArr[i+1][j] = tmp; } } i++; } printf("\n"); for (int i = 0; i < countOfDominatingSets; i++) { deleteRepeatedNodes(i);//剔除重复的节点 addNodes(i); //判断交叉后的结果能否构成连通支配集,不是则添加一些点使它构成连通支配集 } printf("交叉的结果是:\n"); printDominatingSets();//打印所有支配集 for (int i = 0; i < countOfDominatingSets; i++) { if (isThisGraphCDS(i) == 0) { printf("下标为%2d的个体不是支配集\n", i); exit(0); } } }
void Escape_T6Model::setup(tgWorld& world) { const tgRod::Config rodConfig(c.radius, c.density, c.friction, c.rollFriction, c.restitution); /// @todo acceleration constraint was removed on 12/10/14 Replace with tgKinematicActuator as appropreate tgBasicActuator::Config activeMuscleConfig(c.stiffness, c.damping, c.hist, c.rotation, c.maxTens, c.targetVelocity); /* tgBasicActuator::Config passiveMuscleConfig(c.stiffness_passive, c.damping, c.hist, c.rotation, c.maxTens, c.targetVelocity, c.maxAcc);*/ // Start creating the structure tgStructure s; addNodes(s); addRods(s); addMuscles(s); s.move(btVector3(0, 10, 0)); // Add a rotation. This is needed if the ground slopes too much, // otherwise glitches put a rod below the ground. btVector3 rotationPoint = btVector3(0, 0, 0); // origin btVector3 rotationAxis = btVector3(0, 1, 0); // y-axis double rotationAngle = M_PI/2; s.addRotation(rotationPoint, rotationAxis, rotationAngle); // Create the build spec that uses tags to turn the structure into a real model tgBuildSpec spec; spec.addBuilder("rod", new tgRodInfo(rodConfig)); #if (0) spec.addBuilder("muscle", new tgBasicActuatorInfo(activeMuscleConfig)); #else spec.addBuilder("muscle", new tgBasicContactCableInfo(activeMuscleConfig)); #endif //spec.addBuilder("active muscle", new tgBasicActuatorInfo(activeMuscleConfig)); //spec.addBuilder("passive muscle", new tgBasicActuatorInfo(passiveMuscleConfig)); // Create your structureInfo tgStructureInfo structureInfo(s, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // We could now use tgCast::filter or similar to pull out the // models (e.g. muscles) that we want to control. allMuscles = tgCast::filter<tgModel, tgBasicActuator> (getDescendants()); // call the onSetup methods of all observed things e.g. controllers notifySetup(); // Actually setup the children tgModel::setup(world); }
void mapQuadTreeAbstraction::buildAbstraction() { //inefficient for the moment abstractions.push_back(getMapGraph(getMap())); while (abstractions.back()->getNumEdges() > 0) { graph *g = new graph(); addNodes(g); addEdges(g); abstractions.push_back(g); } }
void ScarrArmModel::setup(tgWorld& world) { const tgRod::Config rodConfig(cRod.radius, cRod.density, cRod.friction, cRod.rollFriction, cRod.restitution); const tgRod::Config rodConfigMassless(cRod.radius, 0.00/*c.density*/, cRod.friction, cRod.rollFriction, cRod.restitution); /// @todo acceleration constraint was removed on 12/10/14 Replace with tgKinematicActuator as appropreate tgBasicActuator::Config olecranonMuscleConfig(cCable.stiffness, cCable.damping, cCable.pretension_olecranon, cCable.history, cCable.maxTens, cCable.targetVelocity); tgBasicActuator::Config anconeusMuscleConfig(cCable.stiffness, cCable.damping, cCable.pretension_anconeus, cCable.history, cCable.maxTens, cCable.targetVelocity); tgBasicActuator::Config brachioradialisMuscleConfig(cCable.stiffness, cCable.damping, cCable.pretension_brachioradialis, cCable.history, cCable.maxTens, cCable.targetVelocity); tgBasicActuator::Config supportstringMuscleConfig(cCable.stiffness, cCable.damping, cCable.pretension_support, cCable.history, cCable.maxTens, cCable.targetVelocity); // Start creating the structure tgStructure s; addNodes(s); addRods(s); addMuscles(s); // Move the arm out of the ground btVector3 offset(0.0, 50.0, 0.0); s.move(offset); // Create the build spec that uses tags to turn the structure into a real model tgBuildSpec spec; spec.addBuilder("massless", new tgRodInfo(rodConfigMassless)); spec.addBuilder("rod", new tgRodInfo(rodConfig)); spec.addBuilder("olecranon muscle", new tgBasicActuatorInfo(olecranonMuscleConfig)); spec.addBuilder("anconeus muscle", new tgBasicActuatorInfo(anconeusMuscleConfig)); spec.addBuilder("brachioradialis muscle", new tgBasicActuatorInfo(brachioradialisMuscleConfig)); spec.addBuilder("support muscle", new tgBasicActuatorInfo(supportstringMuscleConfig)); // Create your structureInfo tgStructureInfo structureInfo(s, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // We could now use tgCast::filter or similar to pull out the // models (e.g. muscles) that we want to control. allMuscles = tgCast::filter<tgModel, tgBasicActuator> (getDescendants()); // call the onSetup methods of all observed things e.g. controllers notifySetup(); // Actually setup the children tgModel::setup(world); //map the rods and add the markers to them //addMarkers(s); }
void NestedBoxTestModel::setup(tgWorld& world) { const double edge = 30.0; const double height = tgUtil::round(std::sqrt(3.0)/2 * edge); std::cout << "edge: " << edge << "; height: " << height << std::endl; // Create the tetrahedra tgStructure tetra; addNodes(tetra, edge, height); addPairs(tetra); // Move the first one so we can create a longer snake. // Or you could move the snake at the end, up to you. tetra.move(btVector3(0.0, 2.0, 100.0)); // Create our snake segments tgStructure snake; addSegments(snake, tetra, edge, m_segments); addMuscles(snake); // Create the build spec that uses tags to turn the structure into a real model // Note: This needs to be high enough or things fly apart... const double density = 4.2 / 3000.0; // kg / length^3 - see app for length const double radius = 0.5; const double h = 0.5; const tgBox::Config rodConfig(radius, density); tgBuildSpec spec; spec.addBuilder("rod", new tgBoxInfo(rodConfig)); tgSpringCableActuator::Config muscleConfig(1000, 10); //spec.addBuilder("muscle", new tgBasicActuatorInfo(muscleConfig)); const tgSphere::Config sphereConfig(0.5, 0.5); spec.addBuilder("light", new tgSphereInfo(sphereConfig)); const tgSphere::Config sphereConfig2(0.5, 2.5); spec.addBuilder("light", new tgSphereInfo(sphereConfig2)); // Create your structureInfo tgStructureInfo structureInfo(snake, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // We could now use tgCast::filter or similar to pull out the models (e.g. muscles) // that we want to control. allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (getDescendants()); mapMuscles(muscleMap, *this); trace(structureInfo, *this); // Actually setup the children tgModel::setup(world); }
void T12SuperBallPayload::setup(tgWorld& world) { const tgRod::Config rodConfig(c.radius, c.density, c.friction, c.rollFriction, c.restitution); /// @todo acceleration constraint was removed on 12/10/14 Replace with tgKinematicActuator as appropreate tgBasicActuator::Config muscleConfig(c.stiffness, c.damping, c.pretension, c.history, c.maxTens, c.targetVelocity); // Start creating the structure tgStructure s; addNodes(s); addRods(s); addMuscles(s); // // Add a rotation. This is needed if the ground slopes too much, // // otherwise glitches put a rod below the ground. // btVector3 rotationPoint = btVector3(0, 0, 0); // origin // btVector3 rotationAxis = btVector3(0, 1, 0); // y-axis // double rotationAngle = M_PI/2; // s.addRotation(rotationPoint, rotationAxis, rotationAngle); //s.move(btVector3(0,30,0)); // Create the build spec that uses tags to turn the structure into a real model tgBuildSpec spec; spec.addBuilder("rod", new tgRodInfo(rodConfig)); spec.addBuilder("muscle", new tgBasicActuatorInfo(muscleConfig)); // Create your structureInfo tgStructureInfo structureInfo(s, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // We could now use tgCast::filter or similar to pull out the // models (e.g. muscles) that we want to control. allMuscles = tgCast::filter<tgModel, tgBasicActuator> (getDescendants()); // call the onSetup methods of all observed things e.g. controllers notifySetup(); // Actually setup the children tgModel::setup(world); //map the rods and add the markers to them addMarkers(s); btVector3 location(0,10.0,0); btVector3 rotation(0.0,0.6,0.8); btVector3 speed(0,20,100); this->moveModel(location,rotation,speed); }
MutableNodeRefList& MutableNodeRefList::operator=(const XalanNodeList* theRHS) { clear(); if (theRHS != 0) { addNodes(*theRHS); } return *this; }
void TensegrityModel::buildStructure(tgStructure& structure, const std::string& structurePath, tgBuildSpec& spec) { Yam root = YAML::LoadFile(structurePath); // Validate YAML std::string rootKeys[] = {"nodes", "pair_groups", "builders", "substructures", "bond_groups"}; std::vector<std::string> rootKeysVector(rootKeys, rootKeys + sizeof(rootKeys) / sizeof(std::string)); yamlContainsOnly(root, structurePath, rootKeysVector); yamlNoDuplicates(root, structurePath); addChildren(structure, structurePath, spec, root["substructures"]); addBuilders(spec, root["builders"]); addNodes(structure, root["nodes"]); addPairGroups(structure, root["pair_groups"]); addBondGroups(structure, root["bond_groups"], spec); }
void add (Node* n1, Node* n2) { if (n1->getNext() == NULL or n2->getNext() == NULL) { int val = (n1->get() + n2->get() + carry); //cout << val%10 << " "; l3.add (val%10); carry = val/10; return; } add (n1->getNext(), n2->getNext()); int val = (n1->get() + n2->get() + carry); //cout << val%10 << " "; addNodes (val%10, 0, l3); l3.incr_size(); carry = val/10; }
main() { int n; printf("Enter from the following option\n"); while(1) { printf("1.Add Elements to the Linked List \n"); printf("2.Delete Node\n"); printf("3.Display Element \n"); printf("4.Display Reverse\n"); printf("5.Exit\n"); scanf("%d",&n); switch(n) { case 1:{ printf("Enter the Value:\n"); int value; scanf("%d",&value); addNodes(value); break; } case 2:{ printf("Enter the node to delete\n"); int value; scanf("%d",&value); deleteNode(value); break; } case 3:{ display(); break; } case 4:{ displayReverse(); break; } case 5: exit(1); default: printf("Wrong Input\n"); } printf("\n\n"); } }
void runBench(HASH_FUNCTION hash_fn, int numReplicas, int numNodes, int numKeys, int keySize) { char *hash = NULL; if(hash_fn == HASH_FUNCTION_MD5) hash = "MD5"; else if(hash_fn == HASH_FUNCTION_SHA1) hash = "SHA1"; printf("----------------------------------------------------\n"); printf("bench (%s): replicas = %d, nodes = %d, keys: %d, ring size: %d\n", hash, numReplicas, numNodes, numKeys, numReplicas * numNodes); printf("----------------------------------------------------\n"); hash_ring_t *ring = hash_ring_create(numReplicas, hash_fn); addNodes(ring, numNodes); uint8_t *keys = (uint8_t*)malloc(keySize * numKeys); generateKeys(keys, numKeys, keySize); printf("running...\r"); uint64_t min = 0; uint64_t max = 0; uint64_t total = 0; int times = 100; int x, y; for(y = 0; y < times; y++) { startTiming(); for(x = 0; x < numKeys; x++) { assert(hash_ring_find_node(ring, keys + (keySize * x), keySize) != NULL); } uint64_t result = endTiming(); if(result > max) max = result; if(min == 0 || result < min) min = result; total += result; } printf("stats: total = %.5fs, avg/lookup: %.5fus, min: %.5fus, max: %.5fus, ops/sec: %.0f\n", (double)total / 1000000000, (((double)(total / numKeys)) / 1000) / times, (double)min / numKeys / 1000, (double)max / numKeys / 1000, 1000000000 / ((double)(total / (numKeys * times)))); free(keys); hash_ring_free(ring); }
void tgCraterShallow::setup(tgWorld& world) { const tgBox::Config boxConfig(c.width, c.height, c.density, c.friction, c.rollFriction, c.restitution); // Start creating the structure tgStructure s; addNodes(s); // Create the build spec that uses tags to turn the structure into a real model tgBuildSpec spec; spec.addBuilder("box", new tgBoxInfo(boxConfig)); // Create your structureInfo tgStructureInfo structureInfo(s, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // call the onSetup methods of all observed things e.g. controllers notifySetup(); // Actually setup the children tgModel::setup(world); }
void addNodes(Graph& graph, std::map<SoNode*, Vertex>& vertexNodeMap, SoNode* node) { if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) { SoGroup* group = static_cast<SoGroup*>(node); Vertex groupV = vertexNodeMap[group]; for (int i=0; i<group->getNumChildren(); i++) { SoNode* child = group->getChild(i); auto it = vertexNodeMap.find(child); // the child node is not yet added to the map if (it == vertexNodeMap.end()) { Vertex childV = add_vertex(graph); vertexNodeMap[child] = childV; add_edge(groupV, childV, graph); addNodes(graph, vertexNodeMap, child); } // the child is already there, only add the edge then else { add_edge(groupV, it->second, graph); } } } }
// This is basically a manual setup of a model. // There are things that do this for us (@todo: reference the things that do this for us) void TetraSpineGoal::setup(tgWorld& world) { const double edge = 3.8 * scaleFactor; const double height = tgUtil::round(std::sqrt(3.0)/2 * edge); std::cout << "edge: " << edge << "; height: " << height << std::endl; // Create the tetrahedra tgStructure tetra; addNodes(tetra, edge, height, scaleFactor); addPairs(tetra); // Move the first one so we can create a longer snake. // Or you could move the snake at the end, up to you. tetra.move(btVector3(0.0, 8.0, 10.0)); // Create our snake segments tgStructure snake; addSegments(snake, tetra, -2.30 * scaleFactor, m_segments); addMuscles(snake); // Create the build spec that uses tags to turn the structure into a real model // Note: This needs to be high enough or things fly apart... // Params for In Won const double radius = 0.635 * scaleFactor / 10.0; const double sphereRadius = 0.635 * scaleFactor / (10.0); const double density = 2.0 *.0201 / (pow(radius, 2) * M_PI * edge); // Mass divided by volume... should there be a way to set this automatically?? const double friction = 0.5; const tgRod::Config rodConfig(radius, density, friction); tgBuildSpec spec; spec.addBuilder("rod", new tgRodInfo(rodConfig)); // 1000 is so the units below can be in grams const double sphereVolume1 = 1000.0 * 4.0 / 3.0 * M_PI * pow(sphereRadius, 3); const double sphereVolume2 = 1000.0 * 4.0 / 3.0 * M_PI * pow(sphereRadius, 3); const double baseCornerMidD = 180.0 / sphereVolume1; const tgSphere::Config baseCornerMidConfig(sphereRadius, baseCornerMidD, friction); spec.addBuilder("base", new tgSphereInfo(baseCornerMidConfig)); const double tipCornerMidD = 120.0 / sphereVolume1; const tgSphere::Config tipCornerMidConfig(sphereRadius, tipCornerMidD, friction); spec.addBuilder("tip", new tgSphereInfo(tipCornerMidConfig)); const double PCBD = 70.0 / sphereVolume2; const tgSphere::Config PCB_1_Config(radius, PCBD, friction); spec.addBuilder("PCB", new tgSphereInfo(PCB_1_Config)); const double elasticity = 1000.0; const double damping = 10.0; const double pretension = 0.0; const bool history = false; const double maxTens = 7000.0; const double maxSpeed = 12.0; const double mRad = 1.0; const double motorFriction = 10.0; const double motorInertia = 1.0; const bool backDrivable = false; tgKinematicActuator::Config motorConfig(elasticity, damping, pretension, mRad, motorFriction, motorInertia, backDrivable, history, maxTens, maxSpeed); spec.addBuilder("muscle", new tgKinematicContactCableInfo(motorConfig)); // Create your structureInfo tgStructureInfo structureInfo(snake, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // We could now use tgCast::filter or similar to pull out the models (e.g. muscles) // that we want to control. m_allMuscles = this->find<tgSpringCableActuator> ("muscle"); m_allSegments = this->find<tgModel> ("segment"); mapMuscles(m_muscleMap, *this); //addMarkers(snake, *this); #if (0) trace(structureInfo, *this); #endif // Actually setup the children BaseSpineModelGoal::setup(world); }
// This is basically a manual setup of a model. // There are things that do this for us (@todo: reference the things that do this for us) void TetraSpineStaticModel_hf::setup(tgWorld& world) { const double edge = 38; const double height = tgUtil::round(std::sqrt(3.0)/2 * edge); std::cout << "edge: " << edge << "; height: " << height << std::endl; // Create the tetrahedra tgStructure tetra; addNodes(tetra, edge, height); addPairs(tetra); // Move the first one so we can create a longer snake. // Or you could move the snake at the end, up to you. tetra.move(btVector3(0.0, 2.0, 100.0)); // Create our snake segments tgStructure snake; addSegments(snake, tetra, edge, m_segments); addMuscles(snake); // Create the build spec that uses tags to turn the structure into a real model // Note: This needs to be high enough or things fly apart... // Params for In Won const double oldDensity = .00311; const double radius = 0.635 / 2.0; const double density = 0.0201 / (pow(radius, 2) * M_PI * edge); // Mass divided by volume... should there be a way to set this automatically?? const double friction = 0.15; const tgRod::Config rodConfig(radius, density, friction); tgBuildSpec spec; spec.addBuilder("rod", new tgRodInfo(rodConfig)); // 1000 is so the units below can be in grams const double sphereVolume = 1000.0 * 4.0 / 3.0 * M_PI * pow(radius, 3); const double baseCornerFrontD = 140.0 / sphereVolume; const tgSphere::Config baseCornerFrontConfig(radius, baseCornerFrontD, friction); spec.addBuilder("num0 base", new tgSphereInfo(baseCornerFrontConfig)); const double baseCornerMidD = 180.0 / sphereVolume; const tgSphere::Config baseCornerMidConfig(radius, baseCornerMidD, friction); spec.addBuilder("num1 base", new tgSphereInfo(baseCornerMidConfig)); const double baseCornerRearD = 100.0 / sphereVolume; const tgSphere::Config baseCornerRearConfig(radius, baseCornerRearD, friction); spec.addBuilder("num2 base", new tgSphereInfo(baseCornerRearConfig)); const double tipCornerFrontD = 40.0 / sphereVolume; const tgSphere::Config tipCornerFrontConfig(radius, tipCornerFrontD, friction); spec.addBuilder("num0 tip", new tgSphereInfo(tipCornerFrontConfig)); const double tipCornerMidD = 120.0 / sphereVolume; const tgSphere::Config tipCornerMidConfig(radius, tipCornerMidD, friction); spec.addBuilder("num1 tip", new tgSphereInfo(tipCornerMidConfig)); spec.addBuilder("num2 tip", new tgSphereInfo(tipCornerMidConfig)); const double PCBD = 70.0 / sphereVolume; const tgSphere::Config PCB_1_Config(radius, PCBD, friction); spec.addBuilder("PCB num0", new tgSphereInfo(PCB_1_Config)); spec.addBuilder("PCB num1", new tgSphereInfo(PCB_1_Config)); const double PCB2D = 95.0 / sphereVolume; const tgSphere::Config PCB_2_Config(radius, PCB2D, friction); spec.addBuilder("PCB num2", new tgSphereInfo(PCB_2_Config)); // Two different string configs /// @todo acceleration constraint was removed on 12/10/14 Replace with tgKinematicActuator as appropreate tgSpringCableActuator::Config muscleConfig(229.16, 20, 2000.0, true, 5000, 7.0, 1.0, 1.0); tgSpringCableActuator::Config muscleConfig2(229.16, 20, 700.0, true, 5000, 7.0, 1.0, 1.0); spec.addBuilder("top muscle", new tgBasicActuatorInfo(muscleConfig)); spec.addBuilder("left muscle", new tgBasicActuatorInfo(muscleConfig2)); spec.addBuilder("right muscle", new tgBasicActuatorInfo(muscleConfig2)); // Create your structureInfo tgStructureInfo structureInfo(snake, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // We could now use tgCast::filter or similar to pull out the models (e.g. muscles) // that we want to control. m_allMuscles = this->find<tgSpringCableActuator> ("muscle"); m_allSegments = this->find<tgModel> ("segment"); mapMuscles(m_muscleMap, *this); addMarkers(snake, *this); #if (0) trace(structureInfo, *this); #endif // Actually setup the children BaseSpineModelLearning::setup(world); }
/*************************************** * The primary functions., called from other classes. **************************************/ void VerticalSpineModel::setup(tgWorld& world) { // debugging output: edge and height length //std::cout << "edge: " << c.edge << "; height: " << c.height << std::endl; // Create the first fixed snake segment // @todo move these hard-coded parameters into config tgStructure tetraB; addNodes(tetraB, c.edge, c.height); addPairsB(tetraB); tetraB.move(btVector3(0.0, 2, 0)); // Create our snake segments tgStructure snake; // add 1st child to snake tgStructure* const tB = new tgStructure(tetraB); snake.addChild(tB); tB->addTags(tgString("segment", 1)); // Create the first non-fixed tetrahedra tgStructure tetra; addNodes(tetra, c.edge, c.height); addPairs(tetra); // Move the first tetrahedra // @todo move these hard-coded parameters into config tetra.move(btVector3(0.0, -6, 0)); // add rest of segments using original tetra configuration addSegments(snake, tetra, c.edge, m_segments); addMuscles(snake); // Create the build spec that uses tags to turn the structure into a real model // Note: This needs to be high enough or things fly apart... // length of inner strut = 12.25 cm // m = 1 kg // volume of 1 rod = 9.62 cm^3 // total volume = 38.48 cm^3 //const double density = 1/38.48; = 0.026 // kg / length^3 - see app for length const tgRod::Config rodConfigA(c.radius, c.densityA, c.friction, c.rollFriction, c.restitution); const tgRod::Config rodConfigB(c.radius, c.densityB, c.friction, c.rollFriction, c.restitution); //holder const tgRod::Config rodConfigHA(0.1, c.densityA, c.friction, c.rollFriction, c.restitution); const tgRod::Config rodConfigHB(0.1, c.densityB, c.friction, c.rollFriction, c.restitution); tgBuildSpec spec; spec.addBuilder("rod", new tgRodInfo(rodConfigA)); spec.addBuilder("rodB", new tgRodInfo(rodConfigB)); // set muscle (string) parameters // @todo replace acceleration constraint with tgKinematicActuator if needed... tgSpringCableActuator::Config muscleConfig(c.stiffness, c.damping, c.pretension, c.hist, c.maxTens, c.targetVelocity); spec.addBuilder("muscle", new tgBasicActuatorInfo(muscleConfig)); // Create your structureInfo tgStructureInfo structureInfo(snake, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // We could now use tgCast::filter or similar to pull out the models (e.g. muscles) // that we want to control. allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (getDescendants()); mapMuscles(muscleMap, *this, m_segments); //trace(structureInfo, *this); // Actually setup the children notifySetup(); tgModel::setup(world); }
void RibModelMixedContact::setup(tgWorld& world) { double v_size = 3.0; // Create the spinal processes tgStructure vertebrae; addNodes(vertebrae, v_size); addPairs(vertebrae); // Move the first one so we can create a longer snake. // Or you could move the snake at the end, up to you. vertebrae.move(btVector3(0.0, 2 * v_size, v_size * m_segments)); // Create ribs and add them to the vertebrae double majorAxis = 6.0; double minorAxis = 4.0; double startTheta = M_PI / 2.0; double endTheta = 5.0 * M_PI / 4.0; size_t segs = 15; tgStructure ribs; ellipseNodes(ribs, majorAxis, minorAxis, startTheta, endTheta, segs); makePairs(ribs); #if (0) // Attempt at compliant rib attachments ribs.move(btVector3(v_size / 3.0, 2 * v_size - minorAxis, v_size * m_segments)); #else ribs.move(btVector3(0.0, 2 * v_size - minorAxis -.3, v_size * m_segments)); #endif // Create our snake segments tgStructure snake; addSegments(snake, vertebrae, ribs, v_size, m_segments); snake.move(btVector3(0.0, majorAxis, 0.0)); addMuscles(snake); // Create the build spec that uses tags to turn the structure into a real model // Note: This needs to be high enough or things fly apart... const double density = 4.2 / 300.0; const double radius = 0.5; const double friction = 0.5; // Default is 0.5 const double rollFriction = 0.5; // Default is 0.0 const double restitution = 0.0; // Default const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution); tgBuildSpec spec; spec.addBuilder("rod", new tgRodInfo(rodConfig)); const double elasticity = 500.0; const double elasticityAct = 1000.0; const double damping = 5.0; const double dampingAct = 10.0; const double pretension = 0.0; const bool history = true; const double maxTens = 1000.0; const double maxTensAct = 7000.0; const double maxSpeed = 100.0; const double maxSpeedAct = 24.0; const double mRad = 1.0; const double motorFriction = 10.0; const double motorInertia = 1.0; const bool backDrivable = false; #if (0) //Replacing with tgKinematicActuator, leaving option to turn it off. 9/9/15. tgKinematicActuator::Config muscleConfig(elasticity, damping, pretension, mRad, motorFriction, motorInertia, backDrivable, history, maxTens, maxSpeed); spec.addBuilder("muscle", new tgKinematicContactCableInfo(muscleConfig)); tgKinematicActuator::Config muscleConfigAct(elasticityAct, dampingAct, pretension, mRad, motorFriction, motorInertia, backDrivable, history, maxTensAct, maxSpeedAct); spec.addBuilder("muscleAct", new tgKinematicContactCableInfo(muscleConfigAct)); #else tgSpringCableActuator::Config muscleConfig(elasticity, damping, pretension, history); spec.addBuilder("muscle", new tgBasicContactCableInfo(muscleConfig)); /// @todo acceleration constraint was removed on 12/10/14 Replace with tgKinematicActuator as appropreate tgSpringCableActuator::Config muscleConfigAct(elasticityAct, dampingAct, pretension, history, 7000, 24); spec.addBuilder("muscleAct", new tgBasicContactCableInfo(muscleConfigAct)); #endif #if (0) // Compliant Rib Attachments const double stiffness = 1000; const double damping = .01 * stiffness; tgSpringCableActuator::Config muscleConfig1(stiffness, damping, -M_PI / 2.0); tgSpringCableActuator::Config muscleConfig2(stiffness, damping, M_PI / 2.0); tgSpringCableActuator::Config muscleConfig3(stiffness, damping, M_PI); tgSpringCableActuator::Config muscleConfig4(stiffness, damping, 0); spec.addBuilder("multiMuscle", new tgBasicActuatorInfo(muscleConfig1)); spec.addBuilder("multiMuscle", new tgBasicActuatorInfo(muscleConfig2)); spec.addBuilder("multiMuscle", new tgBasicActuatorInfo(muscleConfig3)); spec.addBuilder("multiMuscle", new tgBasicActuatorInfo(muscleConfig4)); #endif // Create your structureInfo tgStructureInfo structureInfo(snake, spec); // Use the structureInfo to build ourselves structureInfo.buildInto(*this, world); // We could now use tgCast::filter or similar to pull out the models (e.g. muscles) // that we want to control. m_allMuscles = find<tgSpringCableActuator> ("muscleAct"); m_allSegments = find<tgModel> ("segment"); #if (0) trace(structureInfo, *this); #endif // Actually setup the children BaseSpineModelLearning::setup(world); }