int stage2() { if(E == 0) { return P; } return stage3(); }
void f_stage3(const char *NAME, sc_clock& CLK, const sc_signal<double>& PROD, const sc_signal<double>& QUOT, sc_signal<double>& POWR) { SC_NEW(stage3(NAME, CLK, PROD, QUOT, POWR)); }
void MaintenanceMngr::slotToolCompleted(ProgressItem* tool) { // At each stage, relevant tool instance is set to zero to prevent redondant call to this slot // from ProgressManager. This will disable multiple triggering in this method. // There is no memory leak. Each tool instance are delete later by ProgressManager. if (tool == dynamic_cast<ProgressItem*>(d->newItemsFinder)) { d->newItemsFinder = 0; stage2(); } else if (tool == dynamic_cast<ProgressItem*>(d->thumbsGenerator)) { d->thumbsGenerator = 0; stage3(); } else if (tool == dynamic_cast<ProgressItem*>(d->fingerPrintsGenerator)) { d->fingerPrintsGenerator = 0; stage4(); } else if (tool == dynamic_cast<ProgressItem*>(d->duplicatesFinder)) { d->duplicatesFinder = 0; stage5(); } #ifdef HAVE_KFACE else if (tool == dynamic_cast<ProgressItem*>(d->faceDetector)) { d->faceDetector = 0; stage6(); } #endif /* HAVE_KFACE */ else if (tool == dynamic_cast<ProgressItem*>(d->imageQualitySorter)) { d->imageQualitySorter = 0; stage7(); } else if (tool == dynamic_cast<ProgressItem*>(d->metadataSynchronizer)) { d->metadataSynchronizer = 0; done(); } }
int main( int argc, char* argv[] ) { if ( !strcmp( argv[ 1 ], "stage1" ) ) { stage1( argv[ 2 ], atoi( argv[ 3 ] ), atoi( argv[ 4 ] ) ); } else if( !strcmp( argv[ 1 ], "stage2" ) ) { stage2( argv[ 2 ], argv[ 3 ] ); } else if( !strcmp( argv[ 1 ], "stage3" ) ) { stage3( argv[ 2 ], argv[ 3 ], argv[ 4 ] ); } else if( !strcmp( argv[ 1 ], "stage4" ) ) { stage4( argv[ 2 ], argv[ 3 ], argv[ 4 ] ); } else if( !strcmp( argv[ 1 ], "stage5" ) ) { stage5( argv[ 2 ], argv + 3, argc - 3 ); } return 0; }
bool execute() { schifra::utils::timer timer; timer.start(); bool result = stage1() && stage2() && stage3() && stage4() && stage5() && stage6() && stage7() && stage8() && stage9() && stage10() && stage11() && stage12(); timer.stop(); double time = timer.time(); print_codec_properties(); std::cout << "Blocks decoded: " << blocks_processed_ << "\tDecoding Failures: " << block_failures_ << "\tRate: " << ((blocks_processed_ * data_length) * 8.0) / (1048576.0 * time) << "Mbps" << std::endl; /* Note: The throughput rate is not only the throughput of reed solomon encoding and decoding, but also that of the steps needed to add simulated transmission errors to the reed solomon block such as the calculation of the positions and additions of errors and erasures to the reed solomon block, which normally in a true data transmission medium would not be taken into consideration. */ return result; }
int main (int argc, char *argv[]) { double *A,*A2,*L,*U, temp2; int i,j,k; int temp=0; int offset = 0; double t1,t2; if( argc > 1 ) N = atoi(argv[1]); if( argc > 2 ) //Block = atoi(argv[2]); M = atoi(argv[2]); A = (double *)malloc (N*N*sizeof(double)); A2 = (double *)malloc (N*N*sizeof(double)); L = (double *)malloc (N*N*sizeof(double)); U = (double *)malloc (N*N*sizeof(double)); if( A==NULL || A2==NULL || L==NULL || U==NULL) { printf("Can't allocate memory\n"); exit(1); } /* INITIALIZATION */ //InitMatrix(A,N); InitMatrix3(A,N); for(i=0; i<N*N; i++) { A2[i] = A[i]; // Copy of A for verification of correctness L[i] = 0; U[i] = 0; } /* /\* LU DECOMPOSITION *\/ */ /* for (k=0;k<N-1;k++){ */ /* for (i=k+1;i<N;i++){ */ /* A[i*N+k] = A[i*N+k]/A[k*N+k]; */ /* /\* for (i=k+1;i<N;i++) *\/ */ /* for (j=k+1;j<N;j++) */ /* A[i*N+j] = A[i*N+j] - A[i*N+k]*A[k*N+j]; */ /* } */ /* } */ int *sizedim; int *start; int R; //Remain int itr = 0; sizedim = (int*)malloc(M*sizeof(int)); start = (int*)malloc(M*sizeof(int)); R = N; t1 = GetTickCount(); #pragma omp parallel { //printf("The number of thread: %d\n", omp_get_num_threads()); #pragma omp master { while (N-offset>M){ // printf(" Iteration: %d\n", itr++); for (i=0;i<M;i++){ if (i<R%M){ sizedim[i]=R/M+1; start[i]=(R/M+1)*i; } else{ sizedim[i]=R/M; start[i]=(R/M+1)*(R%M)+(R/M)*(i-R%M); } //printf("%i,%i \n",sizedim[i],start[i]); } //Print_Matrix(sizedim,1,M); stage1(A, offset, sizedim, start, N, M); //Print_Matrix(A,N,N); stage2(A, offset, sizedim, start, N, M); //Print_Matrix(A,N,N); stage3(A, offset, sizedim, start, N, M); offset+=sizedim[0]; R=R-sizedim[0]; //Print_Matrix(A,N,N); } //while } //master } //omp parallel ProcessDiagonalBlock(&A[offset*N+offset], N-offset, N); t2 = GetTickCount(); printf("Time for LU-decomposition in secs: %f \n", (t2-t1)/1000000); //Print_Matrix(A,N,N); /* while (N-offset>Block){ */ /* stepLU(A,Block,offset,N); */ /* offset+=Block; */ /* } */ /* ProcessDiagonalBlock(&A[offset*N+offset], N-offset, N); */ //Print_Matrix(A,N,N); #ifdef CHECK /* PROOF OF CORRECTNESS */ for (i=0;i<N;i++) for (j=0;j<N;j++) if (i>j) L[i*N+j] = A[i*N+j]; else U[i*N+j] = A[i*N+j]; for (i=0;i<N;i++) L[i*N+i] = 1; //printf("L=\n"); //Print_Matrix(L,N,N); //printf("U=\n"); //Print_Matrix(U,N,N); for (i=0;i<N;i++) for (j=0;j<N;j++){ temp2=0; for (k=0;k<N;k++) temp2+=L[i*N+k]*U[k*N+j]; if ((A2[i*N+j]-temp2)/A2[i*N+j] >0.1 || (A2[i*N+j]-temp2)/A2[i*N+j] <-0.1) { temp++; printf("Error at: [%d, %d\n]",i,j); } } printf("Errors = %d \n", temp); #endif return 0; }
int main (int argc, char *argv[]) { double *A,*A2,*L,*U, temp2; int i,j,k; int temp=0; int offset = 0; double t1,t2; if (argc < 3) { printf("Usage: ./lu <Matrix size> <number of blocks per dimension>\n"); exit(1); } if( argc > 1 ) N = atoi(argv[1]); if( argc > 2 ) M = atoi(argv[2]); A = (double *)malloc (N*N*sizeof(double)); A2 = (double *)malloc (N*N*sizeof(double)); L = (double *)malloc (N*N*sizeof(double)); U = (double *)malloc (N*N*sizeof(double)); if( A==NULL || A2==NULL || L==NULL || U==NULL) { printf("Can't allocate memory\n"); exit(1); } /* INITIALIZATION */ InitMatrix3(A,N); for(i=0; i<N*N; i++) { A2[i] = A[i]; // Copy of A for verification of correctness L[i] = 0; U[i] = 0; } int *sizedim; int *start; int R; //Remain sizedim = (int*)malloc(M*sizeof(int)); start = (int*)malloc(M*sizeof(int)); R = N; t1 = GetTickCount(); #pragma omp parallel { #pragma omp master { while (N-offset>M){ for (i=0;i<M;i++){ if (i<R%M){ sizedim[i]=R/M+1; start[i]=(R/M+1)*i; } else{ sizedim[i]=R/M; start[i]=(R/M+1)*(R%M)+(R/M)*(i-R%M); } } stage1(A, offset, sizedim, start, N, M); stage2(A, offset, sizedim, start, N, M); stage3(A, offset, sizedim, start, N, M); offset+=sizedim[0]; R=R-sizedim[0]; } //end of while } //end of master } //end of parallel region ProcessDiagonalBlock(&A[offset*N+offset], N-offset, N); t2 = GetTickCount(); printf("Time for LU-decomposition in secs: %f \n", (t2-t1)/1000000); #ifdef CHECK /* PROOF OF CORRECTNESS */ for (i=0;i<N;i++) for (j=0;j<N;j++) if (i>j) L[i*N+j] = A[i*N+j]; else U[i*N+j] = A[i*N+j]; for (i=0;i<N;i++) L[i*N+i] = 1; for (i=0;i<N;i++) for (j=0;j<N;j++){ temp2=0; for (k=0;k<N;k++) temp2+=L[i*N+k]*U[k*N+j]; if ((A2[i*N+j]-temp2)/A2[i*N+j] >0.1 || (A2[i*N+j]-temp2)/A2[i*N+j] <-0.1) temp++; } printf("Errors = %d \n", temp); #endif return; }
bool PlacePlan::plan(const planning_scene::PlanningSceneConstPtr &planning_scene, const moveit_msgs::PlaceGoal &goal) { double timeout = goal.allowed_planning_time; ros::WallTime endtime = ros::WallTime::now() + ros::WallDuration(timeout); std::string attached_object_name = goal.attached_object_name; const robot_model::JointModelGroup *jmg = NULL; const robot_model::JointModelGroup *eef = NULL; // if the group specified is actually an end-effector, we use it as such if (planning_scene->getRobotModel()->hasEndEffector(goal.group_name)) { eef = planning_scene->getRobotModel()->getEndEffector(goal.group_name); if (eef) { // if we correctly found the eef, then we try to find out what the planning group is const std::string &eef_parent = eef->getEndEffectorParentGroup().first; if (eef_parent.empty()) { ROS_ERROR_STREAM_NAMED("manipulation", "No parent group to plan in was identified based on end-effector '" << goal.group_name << "'. Please define a parent group in the SRDF."); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } else jmg = planning_scene->getRobotModel()->getJointModelGroup(eef_parent); } } else { // if a group name was specified, try to use it jmg = goal.group_name.empty() ? NULL : planning_scene->getRobotModel()->getJointModelGroup(goal.group_name); if (jmg) { // we also try to find the corresponding eef const std::vector<std::string> &eef_names = jmg->getAttachedEndEffectorNames(); if (eef_names.empty()) { ROS_ERROR_STREAM_NAMED("manipulation", "There are no end-effectors specified for group '" << goal.group_name << "'"); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } else // check to see if there is an end effector that has attached objects associaded, so we can complete the place for (std::size_t i = 0 ; i < eef_names.size() ; ++i) { std::vector<const robot_state::AttachedBody*> attached_bodies; const robot_model::JointModelGroup *eg = planning_scene->getRobotModel()->getEndEffector(eef_names[i]); if (eg) { // see if there are objects attached to links in the eef planning_scene->getCurrentState().getAttachedBodies(attached_bodies, eg); // is is often possible that the objects are attached to the same link that the eef itself is attached, // so we check for attached bodies there as well const robot_model::LinkModel *attached_link_model = planning_scene->getRobotModel()->getLinkModel(eg->getEndEffectorParentGroup().second); if (attached_link_model) { std::vector<const robot_state::AttachedBody*> attached_bodies2; planning_scene->getCurrentState().getAttachedBodies(attached_bodies2, attached_link_model); attached_bodies.insert(attached_bodies.end(), attached_bodies2.begin(), attached_bodies2.end()); } } // if this end effector has attached objects, we go on if (!attached_bodies.empty()) { // if the user specified the name of the attached object to place, we check that indeed // the group contains this attachd body if (!attached_object_name.empty()) { bool found = false; for (std::size_t j = 0 ; j < attached_bodies.size() ; ++j) if (attached_bodies[j]->getName() == attached_object_name) { found = true; break; } // if the attached body this group has is not the same as the one specified, // we cannot use this eef if (!found) continue; } // if we previoulsy have set the eef it means we have more options we could use, so things are ambiguous if (eef) { ROS_ERROR_STREAM_NAMED("manipulation", "There are multiple end-effectors for group '" << goal.group_name << "' that are currently holding objects. It is ambiguous which end-effector to use. Please specify it explicitly."); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } // set the end effector (this was initialized to NULL above) eef = planning_scene->getRobotModel()->getEndEffector(eef_names[i]); } } } } // if we know the attached object, but not the eef, we can try to identify that if (!attached_object_name.empty() && !eef) { const robot_state::AttachedBody *attached_body = planning_scene->getCurrentState().getAttachedBody(attached_object_name); if (attached_body) { // get the robot model link this attached body is associated to const robot_model::LinkModel *link = attached_body->getAttachedLink(); // check to see if there is a unique end effector containing the link const std::vector<const robot_model::JointModelGroup*> &eefs = planning_scene->getRobotModel()->getEndEffectors(); for (std::size_t i = 0 ; i < eefs.size() ; ++i) if (eefs[i]->hasLinkModel(link->getName())) { if (eef) { ROS_ERROR_STREAM_NAMED("manipulation", "There are multiple end-effectors that include the link '" << link->getName() << "' which is where the body '" << attached_object_name << "' is attached. It is unclear which end-effector to use."); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } eef = eefs[i]; } } // if the group is also unknown, but we just found out the eef if (!jmg && eef) { const std::string &eef_parent = eef->getEndEffectorParentGroup().first; if (eef_parent.empty()) { ROS_ERROR_STREAM_NAMED("manipulation", "No parent group to plan in was identified based on end-effector '" << goal.group_name << "'. Please define a parent group in the SRDF."); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } else jmg = planning_scene->getRobotModel()->getJointModelGroup(eef_parent); } } if (!jmg || !eef) { error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } // try to infer attached body name if possible int loop_count = 0; while (attached_object_name.empty() && loop_count < 2) { // in the first try, look for objects attached to the eef, if the eef is known; // otherwise, look for attached bodies in the planning group itself std::vector<const robot_state::AttachedBody*> attached_bodies; planning_scene->getCurrentState().getAttachedBodies(attached_bodies, loop_count == 0 ? eef : jmg); loop_count++; if (attached_bodies.size() > 1) { ROS_ERROR_NAMED("manipulation", "Multiple attached bodies for group '%s' but no explicit attached object to place was specified", goal.group_name.c_str()); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_OBJECT_NAME; return false; } else attached_object_name = attached_bodies[0]->getName(); } const robot_state::AttachedBody *attached_body = planning_scene->getCurrentState().getAttachedBody(attached_object_name); if (!attached_body) { ROS_ERROR_NAMED("manipulation", "There is no object to detach for place action"); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_OBJECT_NAME; return false; } ros::WallTime start_time = ros::WallTime::now(); // construct common data for possible manipulation plans ManipulationPlanSharedDataPtr plan_data(new ManipulationPlanSharedData()); ManipulationPlanSharedDataConstPtr const_plan_data = plan_data; plan_data->planning_group_ = jmg; plan_data->end_effector_group_ = eef; plan_data->ik_link_ = planning_scene->getRobotModel()->getLinkModel(eef->getEndEffectorParentGroup().second); plan_data->timeout_ = endtime; plan_data->path_constraints_ = goal.path_constraints; plan_data->planner_id_ = goal.planner_id; plan_data->minimize_object_distance_ = false; plan_data->max_goal_sampling_attempts_ = std::max(2u, jmg->getDefaultIKAttempts()); moveit_msgs::AttachedCollisionObject &detach_object_msg = plan_data->diff_attached_object_; // construct the attached object message that will change the world to what it would become after a placement detach_object_msg.link_name = attached_body->getAttachedLinkName(); detach_object_msg.object.id = attached_object_name; detach_object_msg.object.operation = moveit_msgs::CollisionObject::REMOVE; collision_detection::AllowedCollisionMatrixPtr approach_place_acm(new collision_detection::AllowedCollisionMatrix(planning_scene->getAllowedCollisionMatrix())); // we are allowed to touch certain other objects with the gripper approach_place_acm->setEntry(eef->getLinkModelNames(), goal.allowed_touch_objects, true); // we are allowed to touch the target object slightly while retreating the end effector std::vector<std::string> touch_links(attached_body->getTouchLinks().begin(), attached_body->getTouchLinks().end()); approach_place_acm->setEntry(attached_object_name, touch_links, true); if (!goal.support_surface_name.empty()) { // we are allowed to have contact between the target object and the support surface before the place approach_place_acm->setEntry(goal.support_surface_name, attached_object_name, true); // optionally, it may be allowed to touch the support surface with the gripper if (goal.allow_gripper_support_collision) approach_place_acm->setEntry(goal.support_surface_name, eef->getLinkModelNames(), true); } // configure the manipulation pipeline pipeline_.reset(); ManipulationStagePtr stage1(new ReachableAndValidPoseFilter(planning_scene, approach_place_acm, pick_place_->getConstraintsSamplerManager())); ManipulationStagePtr stage2(new ApproachAndTranslateStage(planning_scene, approach_place_acm)); ManipulationStagePtr stage3(new PlanStage(planning_scene, pick_place_->getPlanningPipeline())); pipeline_.addStage(stage1).addStage(stage2).addStage(stage3); initialize(); pipeline_.start(); // add possible place locations for (std::size_t i = 0 ; i < goal.place_locations.size() ; ++i) { ManipulationPlanPtr p(new ManipulationPlan(const_plan_data)); const moveit_msgs::PlaceLocation &pl = goal.place_locations[i]; if (goal.place_eef) p->goal_pose_ = pl.place_pose; else // The goals are specified for the attached body // but we want to transform them into goals for the end-effector instead if (!transformToEndEffectorGoal(pl.place_pose, attached_body, p->goal_pose_)) { p->goal_pose_ = pl.place_pose; ROS_ERROR_NAMED("manipulation", "Unable to transform the desired pose of the object to the pose of the end-effector"); } p->approach_ = pl.pre_place_approach; p->retreat_ = pl.post_place_retreat; p->retreat_posture_ = pl.post_place_posture; p->id_ = i; if (p->retreat_posture_.joint_names.empty()) p->retreat_posture_ = attached_body->getDetachPosture(); pipeline_.push(p); } ROS_INFO_NAMED("manipulation", "Added %d place locations", (int) goal.place_locations.size()); // wait till we're done waitForPipeline(endtime); pipeline_.stop(); last_plan_time_ = (ros::WallTime::now() - start_time).toSec(); if (!getSuccessfulManipulationPlans().empty()) error_code_.val = moveit_msgs::MoveItErrorCodes::SUCCESS; else { if (last_plan_time_ > timeout) error_code_.val = moveit_msgs::MoveItErrorCodes::TIMED_OUT; else { error_code_.val = moveit_msgs::MoveItErrorCodes::PLANNING_FAILED; if (goal.place_locations.size() > 0) { ROS_WARN_NAMED("manipulation", "All supplied place locations failed. Retrying last location in verbose mode."); // everything failed. we now start the pipeline again in verbose mode for one grasp initialize(); pipeline_.setVerbose(true); pipeline_.start(); pipeline_.reprocessLastFailure(); waitForPipeline(ros::WallTime::now() + ros::WallDuration(1.0)); pipeline_.stop(); pipeline_.setVerbose(false); } } } ROS_INFO_NAMED("manipulation", "Place planning completed after %lf seconds", last_plan_time_); return error_code_.val == moveit_msgs::MoveItErrorCodes::SUCCESS; }
xmlNode * do_calculations(pe_working_set_t * data_set, xmlNode * xml_input, crm_time_t * now) { GListPtr gIter = NULL; int rsc_log_level = LOG_INFO; /* pe_debug_on(); */ CRM_ASSERT(xml_input || is_set(data_set->flags, pe_flag_have_status)); if (is_set(data_set->flags, pe_flag_have_status) == FALSE) { set_working_set_defaults(data_set); data_set->input = xml_input; data_set->now = now; } else { crm_trace("Already have status - reusing"); } if (data_set->now == NULL) { data_set->now = crm_time_new(NULL); } crm_trace("Calculate cluster status"); stage0(data_set); if(is_not_set(data_set->flags, pe_flag_quick_location)) { gIter = data_set->resources; for (; gIter != NULL; gIter = gIter->next) { resource_t *rsc = (resource_t *) gIter->data; if (is_set(rsc->flags, pe_rsc_orphan) && rsc->role == RSC_ROLE_STOPPED) { continue; } rsc->fns->print(rsc, NULL, pe_print_log, &rsc_log_level); } } crm_trace("Applying placement constraints"); stage2(data_set); if(is_set(data_set->flags, pe_flag_quick_location)){ return NULL; } crm_trace("Create internal constraints"); stage3(data_set); crm_trace("Check actions"); stage4(data_set); crm_trace("Allocate resources"); stage5(data_set); crm_trace("Processing fencing and shutdown cases"); stage6(data_set); crm_trace("Applying ordering constraints"); stage7(data_set); crm_trace("Create transition graph"); stage8(data_set); crm_trace("=#=#=#=#= Summary =#=#=#=#="); crm_trace("\t========= Set %d (Un-runnable) =========", -1); if (get_crm_log_level() >= LOG_TRACE) { gIter = data_set->actions; for (; gIter != NULL; gIter = gIter->next) { action_t *action = (action_t *) gIter->data; if (is_set(action->flags, pe_action_optional) == FALSE && is_set(action->flags, pe_action_runnable) == FALSE && is_set(action->flags, pe_action_pseudo) == FALSE) { log_action(LOG_TRACE, "\t", action, TRUE); } } } return data_set->graph; }
int main() { // initialize IRQ (interrupts) // this must come before everything else IRQ_INIT(); // Initialize global pointers GameStateManager gameStateMan; OamManager oamMan; AudioManager audioMan; PlayState playState(&gameStateMan); TitleScreenState titleState(&gameStateMan); PauseState pauseState(&gameStateMan); GameOverState gameOverState(&gameStateMan); StoreState storeState(&gameStateMan); StageEndState stageEndState(&gameStateMan); g_gameStateMan = &gameStateMan; g_oamMan = &oamMan; g_playState = &playState; g_titleState = &titleState; g_pauseState = &pauseState; g_gameOverState = &gameOverState; g_storeState = &storeState; g_stageEndState = &stageEndState; g_audioMan = &audioMan; // create stage events StageEvent endEvent; StageEvent event1; StageEvent event2; StageEvent event3; StageEvent event4; StageEvent event5; StageEvent event6; StageEvent firePowerPowerUpEvent; StageEvent invinciblePowerUpEvent; StageEvent bombPowerUpEvent; g_endEvent = &endEvent; g_event1 = &event1; g_event2 = &event2; g_event3 = &event3; g_event4 = &event4; g_event5 = &event5; g_event6 = &event6; g_firePowerPowerUpEvent = &firePowerPowerUpEvent; g_invinciblePowerUpEvent = &invinciblePowerUpEvent; g_bombPowerUpEvent = &bombPowerUpEvent; initializeEvents(); StageEvent * stage1Events[24]; int stage1Timing[24]; int stage1yOffset[24]; fillEventsStage1(stage1Events, stage1Timing, stage1yOffset); Stage stage1(&playState, stage1Events, stage1Timing, stage1yOffset, 24); g_stage1 = &stage1; StageEvent * stage2Events[20]; int stage2Timing[20]; int stage2yOffset[20]; fillEventsStage2(stage2Events, stage2Timing, stage2yOffset); Stage stage2(&playState, stage2Events, stage2Timing, stage2yOffset, 20); g_stage2 = &stage2; StageEvent * stage3Events[20]; int stage3Timing[20]; int stage3yOffset[20]; fillEventsStage3(stage3Events, stage3Timing, stage3yOffset); Stage stage3(&playState, stage3Events, stage3Timing, stage3yOffset, 20); g_stage3 = &stage3; videoInit(); g_gameStateMan->pushState(g_titleState); #ifdef DEBUG // timers used for debug display REG_TM1D = 0x10000 - 2808; // overflow into timer 2 every 2808 cycles, approx. 1% of a screen refresh REG_TM2D = 0; REG_TM2CNT = TM_CASCADE | TM_ENABLE; REG_TM1CNT = TM_FREQ_1 | TM_ENABLE; int oldPercent, diffPercent, oldFrac, diffFrac; char buf[15]; #endif // DEBUG while(true) { // wait until next VBlank // prefer this over vid_vsync() - it's // better for power consumption VBlankIntrWait(); #ifdef DEBUG // grab current percentage oldPercent = REG_TM2D; oldFrac = REG_TM1D; #endif // DEBUG // update shadow OAM to real OAM g_oamMan->update(); // mix the next frame's audio g_audioMan->sndMix(); // poll keys - do not do this in other places key_poll(); // update the game state g_gameStateMan->update(); #ifdef DEBUG // grab current percentage, and write it out diffPercent = REG_TM2D - oldPercent; diffFrac = REG_TM1D - oldFrac; // round the percent based on the fractional amount if (diffFrac > 1404) { diffPercent++; } else if (diffFrac < -1404) { diffPercent--; } gba_itoa(diffPercent, buf); // clear out characters from the last write write(" ", Vec2(0, 0)); write(buf, Vec2(0, 0)); // reset timer 2 to 0 REG_TM2CNT = 0; // disable timer REG_TM2D = 0; // set new value to 0 REG_TM2CNT = TM_CASCADE | TM_ENABLE; // reenable timer #endif // DEBUG } }
bool CascadeTest() { int input_value_count = 0; const int kValuesPerTest = 1000; // stage1 and stage2 will feed into stage3 Merge<QuadtreePath> *stage1 = new Merge<QuadtreePath>("Stage1"); stage1->AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage1A", "1031", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage1->AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage1B", "10313", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage1->AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage1C", "1031", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage1->Start(); Merge<QuadtreePath> *stage2 = new Merge<QuadtreePath>("Stage2"); stage2->AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage2A", "10313", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage2->AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage2B", "1031", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage2->AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage2C", "1031", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage2->AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage2D", "10313", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage2->Start(); // stage3 has two native sources, plus stage1 and stage2 Merge<QuadtreePath> stage3("Stage3"); stage3.AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage3A", "1031", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage3.AddSource( TransferOwnership( new MergeSourceRandomWalk("Stage3B", "1031", kValuesPerTest, 4))); input_value_count += kValuesPerTest; stage3.AddSource(TransferOwnership(stage1)); stage1 = NULL; // owned by stage3 now stage3.AddSource(TransferOwnership(stage2)); stage2 = NULL; // owned by stage3 now stage3.Start(); QuadtreePath prev; int output_value_count = 0; while (stage3.Active()) { const QuadtreePath &cur = stage3.Current(); if (prev > cur) { throw khSimpleException("CascadeTest: Current() out of order, ") << prev.AsString() << " > " << cur.AsString() << ", source " << stage3.CurrentName(); } else { prev = cur; } if (verbose_) { std::cout << "< " << cur.AsString() << std::endl; } stage3.Advance(); ++output_value_count; } stage3.Close(); if (input_value_count != output_value_count) { std::cerr << "Error: Input value count: " << input_value_count << " != Output value count: " << output_value_count << std::endl; return false; } return true; }
void stage2(void* ba, void* bb) { shared_buf(ba, bb, sz); stage3(ba, bb); }
int main (int argc, char *argv[]) { double *A,*A2,*L,*U, temp2; int i,j,k; int temp=0; int offset = 0; double t1,t2,t3,t4; int N = 100; int Block = 1; int M=1; //number of blocks per dimension if( argc > 1 ) N = atoi(argv[1]); if( argc > 2 ) M = atoi(argv[2]); A = (double *)malloc (N*N*sizeof(double)); A2 = (double *)malloc (N*N*sizeof(double)); L = (double *)malloc (N*N*sizeof(double)); U = (double *)malloc (N*N*sizeof(double)); if( A==NULL || A2==NULL || L==NULL || U==NULL ) { printf("Can't allocate memory\n"); exit(1); } int *sizedim; int *start; int R; //Remain sizedim = (int*)malloc(M*sizeof(int)); start = (int*)malloc(M*sizeof(int)); R = N; t1 = GetTickCount(); #pragma omp parallel { #pragma omp master { while (N-offset>M){ for (i=0;i<M;i++){ if (i<R%M){ sizedim[i]=R/M+1; start[i]=(R/M+1)*i; } else { sizedim[i]=R/M; start[i]=(R/M+1)*(R%M)+(R/M)*(i-R%M); } } stage1(A, offset, sizedim, start, N, M); t3 = GetTickCount(); stage2(A, offset, sizedim, start, N, M); stage3(A, offset, sizedim, start, N, M); t4 = GetTickCount(); total += (t4-t3); offset+=sizedim[0]; R=R-sizedim[0]; } } } ProcessDiagonalBlock(&A[offset*N+offset], N-offset, N); t2 = GetTickCount(); printf("Time for LU-decomposition in secs: %f \n", (t2-t1)/1000000); printf("Time for the task region in secs: %f \n", (total)/1000000); printf("Time for inside tasks in secs: %f \n", (task_total)/1000000); printf("Time spent in taskwait in secs: %f \n", (wait_total)/1000000); #ifdef CHECK for (i=0;i<N;i++) for (j=0;j<N;j++) if (i>j) L[i*N+j] = A[i*N+j]; else U[i*N+j] = A[i*N+j]; for (i=0;i<N;i++) L[i*N+i] = 1; for (i=0;i<N;i++) for (j=0;j<N;j++){ temp2=0; for (k=0;k<N;k++) temp2+=L[i*N+k]*U[k*N+j]; if ((A2[i*N+j]-temp2)/A2[i*N+j] >0.1 || (A2[i*N+j]-temp2)/A2[i*N+j] <-0.1) temp++; } printf("Errors = %d \n", temp); #endif return 0; }
bool PickPlan::plan(const planning_scene::PlanningSceneConstPtr &planning_scene, const moveit_msgs::PickupGoal &goal) { double timeout = goal.allowed_planning_time; ros::WallTime endtime = ros::WallTime::now() + ros::WallDuration(timeout); std::string planning_group = goal.group_name; std::string end_effector = goal.end_effector; if (end_effector.empty() && !planning_group.empty()) { const robot_model::JointModelGroup *jmg = planning_scene->getRobotModel()->getJointModelGroup(planning_group); if (!jmg) { error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } const std::vector<std::string> &eefs = jmg->getAttachedEndEffectorNames(); if (!eefs.empty()) { end_effector = eefs.front(); if (eefs.size() > 1) ROS_WARN_STREAM_NAMED("manipulation", "Choice of end-effector for group '" << planning_group << "' is ambiguous. Assuming '" << end_effector << "'"); } } else if (!end_effector.empty() && planning_group.empty()) { const robot_model::JointModelGroup *jmg = planning_scene->getRobotModel()->getEndEffector(end_effector); if (!jmg) { error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } planning_group = jmg->getEndEffectorParentGroup().first; if (planning_group.empty()) { ROS_ERROR_STREAM_NAMED("manipulation", "No parent group to plan in was identified based on end-effector '" << end_effector << "'. Please define a parent group in the SRDF."); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } else ROS_INFO_STREAM_NAMED("manipulation", "Assuming the planning group for end effector '" << end_effector << "' is '" << planning_group << "'"); } const robot_model::JointModelGroup *eef = end_effector.empty() ? NULL : planning_scene->getRobotModel()->getEndEffector(end_effector); if (!eef) { ROS_ERROR_NAMED("manipulation", "No end-effector specified for pick action"); error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GROUP_NAME; return false; } const std::string &ik_link = eef->getEndEffectorParentGroup().second; ros::WallTime start_time = ros::WallTime::now(); // construct common data for possible manipulation plans ManipulationPlanSharedDataPtr plan_data(new ManipulationPlanSharedData()); ManipulationPlanSharedDataConstPtr const_plan_data = plan_data; plan_data->planning_group_ = planning_scene->getRobotModel()->getJointModelGroup(planning_group); plan_data->end_effector_group_ = eef; plan_data->ik_link_ = planning_scene->getRobotModel()->getLinkModel(ik_link); plan_data->timeout_ = endtime; plan_data->path_constraints_ = goal.path_constraints; plan_data->planner_id_ = goal.planner_id; plan_data->minimize_object_distance_ = goal.minimize_object_distance; plan_data->max_goal_sampling_attempts_ = std::max(2u, plan_data->planning_group_->getDefaultIKAttempts()); moveit_msgs::AttachedCollisionObject &attach_object_msg = plan_data->diff_attached_object_; // construct the attached object message that will change the world to what it would become after a pick attach_object_msg.link_name = ik_link; attach_object_msg.object.id = goal.target_name; attach_object_msg.object.operation = moveit_msgs::CollisionObject::ADD; attach_object_msg.touch_links = goal.attached_object_touch_links.empty() ? eef->getLinkModelNames() : goal.attached_object_touch_links; collision_detection::AllowedCollisionMatrixPtr approach_grasp_acm(new collision_detection::AllowedCollisionMatrix(planning_scene->getAllowedCollisionMatrix())); // we are allowed to touch the target object approach_grasp_acm->setEntry(goal.target_name, attach_object_msg.touch_links, true); // we are allowed to touch certain other objects with the gripper approach_grasp_acm->setEntry(eef->getLinkModelNames(), goal.allowed_touch_objects, true); if (!goal.support_surface_name.empty()) { // we are allowed to have contact between the target object and the support surface before the grasp approach_grasp_acm->setEntry(goal.support_surface_name, goal.target_name, true); // optionally, it may be allowed to touch the support surface with the gripper if (goal.allow_gripper_support_collision) approach_grasp_acm->setEntry(goal.support_surface_name, eef->getLinkModelNames(), true); } // configure the manipulation pipeline pipeline_.reset(); ManipulationStagePtr stage1(new ReachableAndValidPoseFilter(planning_scene, approach_grasp_acm, pick_place_->getConstraintsSamplerManager())); ManipulationStagePtr stage2(new ApproachAndTranslateStage(planning_scene, approach_grasp_acm)); ManipulationStagePtr stage3(new PlanStage(planning_scene, pick_place_->getPlanningPipeline())); pipeline_.addStage(stage1).addStage(stage2).addStage(stage3); initialize(); pipeline_.start(); // order the grasps by quality std::vector<std::size_t> grasp_order(goal.possible_grasps.size()); for (std::size_t i = 0 ; i < goal.possible_grasps.size() ; ++i) grasp_order[i] = i; OrderGraspQuality oq(goal.possible_grasps); std::sort(grasp_order.begin(), grasp_order.end(), oq); // feed the available grasps to the stages we set up for (std::size_t i = 0 ; i < goal.possible_grasps.size() ; ++i) { ManipulationPlanPtr p(new ManipulationPlan(const_plan_data)); const moveit_msgs::Grasp &g = goal.possible_grasps[grasp_order[i]]; p->approach_ = g.pre_grasp_approach; p->retreat_ = g.post_grasp_retreat; p->goal_pose_ = g.grasp_pose; p->id_ = grasp_order[i]; // if no frame of reference was specified, assume the transform to be in the reference frame of the object if (p->goal_pose_.header.frame_id.empty()) p->goal_pose_.header.frame_id = goal.target_name; p->approach_posture_ = g.pre_grasp_posture; p->retreat_posture_ = g.grasp_posture; pipeline_.push(p); } // wait till we're done waitForPipeline(endtime); pipeline_.stop(); last_plan_time_ = (ros::WallTime::now() - start_time).toSec(); if (!getSuccessfulManipulationPlans().empty()) error_code_.val = moveit_msgs::MoveItErrorCodes::SUCCESS; else { if (last_plan_time_ > timeout) error_code_.val = moveit_msgs::MoveItErrorCodes::TIMED_OUT; else { error_code_.val = moveit_msgs::MoveItErrorCodes::PLANNING_FAILED; if (goal.possible_grasps.size() > 0) { ROS_WARN_NAMED("manipulation", "All supplied grasps failed. Retrying last grasp in verbose mode."); // everything failed. we now start the pipeline again in verbose mode for one grasp initialize(); pipeline_.setVerbose(true); pipeline_.start(); pipeline_.reprocessLastFailure(); waitForPipeline(ros::WallTime::now() + ros::WallDuration(1.0)); pipeline_.stop(); pipeline_.setVerbose(false); } } } ROS_INFO_NAMED("manipulation", "Pickup planning completed after %lf seconds", last_plan_time_); return error_code_.val == moveit_msgs::MoveItErrorCodes::SUCCESS; }