int main(int argc, char* argv[]) { #if defined(WIN32) || defined(__WIN32__) MASTER_FD master; init(argc, argv); { char buff[1024]; if (WSAStartup(0x0202,(WSADATA *) &buff[0])) { if(verbose){ handle_error(__FILE__, __LINE__); } return -1; } } init_master(&master); InitializeCriticalSection(&master.lock); logging_name = "FWT Server"; server_loop( &client_handler, &get_client_data, &get_addr, buf, sock_data, listen_port, &hello, &master, NULL ); return 0; #endif #if !defined(WIN32) && !defined(__WIN32__) MASTER_FD master; init(argc, argv); init_master(&master); master.lock = semget(get_key(), 1, 0666 | IPC_CREAT | IPC_EXCL); if(master.lock == -1){ if(verbose){ handle_error(__FILE__, __LINE__); } exit(0); } logging_name = "FWT Server"; server_loop( &client_handler, &get_client_data, &get_addr, buf, sock_data, listen_port, &hello, &master, NULL ); return 0; #endif }
int main() { int slave_number = 0; /* Initialize EtherCAT Master */ init_master(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); printf("starting Master application\n"); while(1) { /* Update the process data (EtherCAT packets) sent/received from the node */ pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); if(master_setup.op_flag) /*Check if the master is active*/ { /* Write Process data */ slv_handles[slave_number].motorctrl_out = 12; slv_handles[slave_number].torque_setpoint = 200; slv_handles[slave_number].speed_setpoint = 4000; slv_handles[slave_number].position_setpoint = 10000; slv_handles[slave_number].operation_mode = 125; /* Read Process data */ printf("Status: %d\n", slv_handles[slave_number].motorctrl_status_in); printf("Position: %d \n", slv_handles[slave_number].position_in); printf("Speed: %d\n", slv_handles[slave_number].speed_in); printf("Torque: %d\n", slv_handles[slave_number].torque_in); printf("Operation Mode disp: %d\n", slv_handles[slave_number].operation_mode_disp); } } return 0; }
void init() { const int id(get_thread_num()); if (id == 0) init_master(); else init_worker(id); }
void main(void) { EA = 1; init_timer(); init_master(MASTER_HOST_ID, COMM_SPEED_9600_H); operate_master(); }
int main(int argc, char* argv[]) { #if defined(WIN32) || defined(__WIN32__) { char buff[1024]; if (WSAStartup(0x0202,(WSADATA *) &buff[0])){ if(verbose){ handle_error(__FILE__, __LINE__); } return -1; } } init(argc, argv); init_master(&master); InitializeCriticalSection(&master.lock); logging_name = "FWT Proxy"; server_loop( &client_handler, &get_client_data, &get_addr, buf, sock_data, listen_port, &hello, &master, &timer_event ); return 0; #endif #if !defined(WIN32) && !defined(__WIN32__) init(argc, argv); init_master(&master); logging_name = "FWT Proxy"; server_loop( &client_handler, &get_client_data, &get_addr, buf, sock_data, listen_port, &hello, &master, &timer_event ); return 0; #endif }
int main (int argc, char *argv[]) { int left, right, rc; /* Initialize MPI */ MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&taskid); MPI_Comm_size(MPI_COMM_WORLD,&numtasks); if (numtasks < 2) { printf("ERROR: Number of MPI tasks set to %d\n",numtasks); printf("Need at least 2 tasks! Quitting...\n"); rc = 999; MPI_Abort(MPI_COMM_WORLD, rc); exit(0); } /* Determine left and right neighbors */ if (taskid == numtasks-1) right = 0; else right = taskid + 1; if (taskid == 0) left = numtasks - 1; else left = taskid - 1; /* Get program parameters and initialize wave values */ if (taskid == MASTER) { printf ("Starting mpi_wave using %d tasks.\n", numtasks); printf ("Using %d points on the vibrating string.\n", TPOINTS); init_master(); } else init_workers(); init_line(); /* Update values along the line for nstep time steps */ update(left, right); /* Master collects results from workers and prints */ if (taskid == MASTER) output_master(); else output_workers(); MPI_Finalize(); return 0; }
// switch to master mode and send something, return to slave mode when done. extern void i2c_tx(u8 chip, u32 addr, u8 addr_len, u32 data_len, void* data) { while( twi_is_busy() ) {;;} status = init_master(); print_dbg("\r\nI2C init (master) : "); if(status==TWI_SUCCESS) { print_dbg("SUCCESS"); } else { print_dbg("FAIL: "); print_dbg_hex(status); } print_dbg("\r\n chip addr: "); print_dbg_hex(chip); print_dbg(", mem addr: "); print_dbg_hex(addr); print_dbg(", addr len: "); print_dbg_hex(addr_len); print_dbg(", data len: "); print_dbg_hex(data_len); print_dbg(", data (1st 4 bytes): "); print_dbg_hex(*((u32*)(data))); status = send_master(chip, addr, addr_len, data_len, data); print_dbg("\r\nI2C tx (master) : "); if(status==TWI_SUCCESS) { print_dbg("SUCCESS"); } else { print_dbg("FAIL: "); print_dbg_hex(status); } while( twi_is_busy() ) {;;} status = init_slave(); print_dbg("\r\nI2C init (slave) : "); if(status==TWI_SUCCESS) { print_dbg("SUCCESS"); } else { print_dbg("FAIL: "); print_dbg_hex(status);} }
int main P2(int, argc, char **, argv) { time_t tm; int i, new_mudlib = 0, got_defaults = 0; int no_ip_demon = 0; char *p; char version_buf[80]; #if 0 int dtablesize; #endif error_context_t econ; #if !defined(LATTICE) && !defined(OLD_ULTRIX) && !defined(sequent) && \ !defined(sgi) void tzset(); #endif struct lpc_predef_s predefs; #if !defined(__SASC) && (defined(AMITCP) || defined(AS225)) amiga_sockinit(); atexit(amiga_sockexit); #endif #ifdef WRAPPEDMALLOC wrappedmalloc_init(); #endif /* WRAPPEDMALLOC */ #ifdef DEBUGMALLOC MDinit(); #endif #if (defined(PROFILING) && !defined(PROFILE_ON) && defined(HAS_MONCONTROL)) moncontrol(0); #endif #if !defined(OLD_ULTRIX) && !defined(LATTICE) && !defined(sequent) tzset(); #endif boot_time = get_current_time(); const0.type = T_NUMBER; const0.u.number = 0; const1.type = T_NUMBER; const1.u.number = 1; /* const0u used by undefinedp() */ const0u.type = T_NUMBER; const0u.subtype = T_UNDEFINED; const0u.u.number = 0; /* const0n used by nullp() */ const0n.type = T_NUMBER; const0n.subtype = T_NULLVALUE; const0n.u.number = 0; fake_prog.program_size = 0; /* * Check that the definition of EXTRACT_UCHAR() is correct. */ p = (char *) &i; *p = -10; if (EXTRACT_UCHAR(p) != 0x100 - 10) { fprintf(stderr, "Bad definition of EXTRACT_UCHAR() in interpret.h.\n"); exit(-1); } /* * An added test: can we do EXTRACT_UCHAR(x++)? * (read_number, etc uses it) */ p = (char *) &i; (void) EXTRACT_UCHAR(p++); if ((p - (char *) &i) != 1) { fprintf(stderr, "EXTRACT_UCHAR() in interpret.h evaluates its argument more than once.\n"); exit(-1); } /* * Check the living hash table size */ if (CFG_LIVING_HASH_SIZE != 4 && CFG_LIVING_HASH_SIZE != 16 && CFG_LIVING_HASH_SIZE != 64 && CFG_LIVING_HASH_SIZE != 256 && CFG_LIVING_HASH_SIZE != 1024 && CFG_LIVING_HASH_SIZE != 4096) { fprintf(stderr, "CFG_LIVING_HASH_SIZE in options.h must be one of 4, 16, 64, 256, 1024, 4096, ...\n"); exit(-1); } #ifdef RAND srand(get_current_time()); #else # ifdef DRAND48 srand48(get_current_time()); # else # ifdef RANDOM srandom(get_current_time()); # else fprintf(stderr, "Warning: no random number generator specified!\n"); # endif # endif #endif current_time = get_current_time(); /* * Initialize the microsecond clock. */ init_usec_clock(); /* read in the configuration file */ got_defaults = 0; for (i = 1; (i < argc) && !got_defaults; i++) { if (argv[i][0] != '-') { set_defaults(argv[i]); got_defaults = 1; } } if (!got_defaults) { fprintf(stderr, "You must specify the configuration filename as an argument.\n"); exit(-1); } printf("Initializing internal tables....\n"); init_strings(); /* in stralloc.c */ init_otable(); /* in otable.c */ init_identifiers(); /* in lex.c */ init_locals(); /* in compiler.c */ /* disable this for now */ #if 0 /* * We estimate that we will need MAX_USERS + MAX_EFUN_SOCKS + 10 file * descriptors if the maximum number of users were to log in and all LPC * sockets were in use. This is a pretty close estimate. */ #ifndef LATTICE dtablesize = MAX_USERS + MAX_EFUN_SOCKS + 10; #else /* * Amiga sockets separate from file descriptors */ dtablesize = MAX_USERS + MAX_EFUN_SOCKS; #endif /* * If our estimate is larger than FD_SETSIZE, then we need more file * descriptors than the operating system can handle. This is a problem * that can be resolved by decreasing MAX_USERS, MAX_EFUN_SOCKS, or both. */ if (dtablesize > FD_SETSIZE) { fprintf(stderr, "Warning: File descriptor requirements exceed system capacity!\n"); fprintf(stderr, " Configuration exceeds system capacity by %d descriptor(s).\n", dtablesize - FD_SETSIZE); } #ifdef HAS_SETDTABLESIZE /* * If the operating system supports setdtablesize() then we can request * the number of file descriptors we really need. First check to see if * wee already have enough. If so dont bother the OS. If not, attempt to * allocate the number we estimated above. There are system imposed * limits on file descriptors, so we may not get as many as we asked for. * Check to make sure we get enough. */ if (getdtablesize() < dtablesize) if (setdtablesize(dtablesize) < dtablesize) { fprintf(stderr, "Warning: Could not allocate enough file descriptors!\n"); fprintf(stderr, " setdtablesize() could not allocate %d descriptor(s).\n", getdtablesize() - dtablesize); } /* * Just be polite and tell the administrator how many he has. */ fprintf(stderr, "%d file descriptors were allocated, (%d were requested).\n", getdtablesize(), dtablesize); #endif #endif time_to_clean_up = TIME_TO_CLEAN_UP; time_to_swap = TIME_TO_SWAP; max_cost = MAX_COST; reserved_size = RESERVED_SIZE; max_array_size = MAX_ARRAY_SIZE; max_buffer_size = MAX_BUFFER_SIZE; max_string_length = MAX_STRING_LENGTH; master_file_name = (char *) MASTER_FILE; /* fix the filename */ while (*master_file_name == '/') master_file_name++; p = master_file_name; while (*p++); if (p[-2]=='c' && p[-3]=='.') p[-3]=0; mud_lib = (char *) MUD_LIB; set_inc_list(INCLUDE_DIRS); if (reserved_size > 0) reserved_area = (char *) DMALLOC(reserved_size, TAG_RESERVED, "main.c: reserved_area"); for (i = 0; i < sizeof consts / sizeof consts[0]; i++) consts[i] = exp(-i / 900.0); init_num_args(); reset_machine(1); /* * The flags are parsed twice ! The first time, we only search for the -m * flag, which specifies another mudlib, and the D-flags, so that they * will be available when compiling master.c. */ for (i = 1; i < argc; i++) { if (argv[i][0] != '-') continue; switch (argv[i][1]) { case 'D': if (argv[i][2]) { /* Amylaar : allow flags to be passed down to * the LPC preprocessor */ struct lpc_predef_s *tmp; tmp = &predefs; tmp->flag = argv[i] + 2; tmp->next = lpc_predefs; lpc_predefs = tmp; continue; } fprintf(stderr, "Illegal flag syntax: %s\n", argv[i]); exit(-1); case 'N': no_ip_demon++; continue; #ifdef YYDEBUG case 'y': yydebug = 1; continue; #endif /* YYDEBUG */ case 'm': mud_lib = alloc_cstring(argv[i] + 2, "mudlib dir"); if (chdir(mud_lib) == -1) { fprintf(stderr, "Bad mudlib directory: %s\n", mud_lib); exit(-1); } new_mudlib = 1; break; } } if (!new_mudlib && chdir(mud_lib) == -1) { fprintf(stderr, "Bad mudlib directory: %s\n", mud_lib); exit(-1); } get_version(version_buf); time(&tm); debug_message("----------------------------------------------------------------------------\n%s (%s) starting up on %s - %s\n\n", MUD_NAME, version_buf, ARCH, ctime(&tm)); #ifdef BINARIES init_binaries(argc, argv); #endif #ifdef LPC_TO_C init_lpc_to_c(); #endif add_predefines(); #ifndef NO_IP_DEMON if (!no_ip_demon && ADDR_SERVER_IP) init_addr_server(ADDR_SERVER_IP, ADDR_SERVER_PORT); #endif /* NO_IP_DEMON */ eval_cost = max_cost; /* needed for create() functions */ save_context(&econ); if (SETJMP(econ.context)) { debug_message("The simul_efun (%s) and master (%s) objects must be loadable.\n", SIMUL_EFUN, MASTER_FILE); exit(-1); } else { init_simul_efun(SIMUL_EFUN); init_master(MASTER_FILE); } pop_context(&econ); for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; } else { /* * Look at flags. -m and -o has already been tested. */ switch (argv[i][1]) { case 'D': case 'N': case 'm': case 'y': continue; case 'f': save_context(&econ); if (SETJMP(econ.context)) { debug_message("Error while calling master::flag(\"%s\"), aborting ...", argv[i] + 2); exit(-1); } push_constant_string(argv[i] + 2); (void) apply_master_ob(APPLY_FLAG, 1); if (MudOS_is_being_shut_down) { debug_message("Shutdown by master object.\n"); exit(0); } pop_context(&econ); continue; case 'e': e_flag++; continue; case 'p': external_port[0].port = atoi(argv[i] + 2); continue; case 'd': #ifdef DEBUG d_flag++; #else debug_message("Driver must be compiled with DEBUG on to use -d.\n"); #endif case 'c': comp_flag++; continue; case 't': t_flag++; continue; default: debug_message("Unknown flag: %s\n", argv[i]); exit(-1); } } } if (MudOS_is_being_shut_down) exit(1); if (strlen(DEFAULT_FAIL_MESSAGE)) default_fail_message = DEFAULT_FAIL_MESSAGE; else default_fail_message = "What?"; #ifdef PACKAGE_MUDLIB_STATS restore_stat_files(); #endif #ifdef PACKAGE_SOCKETS init_sockets(); /* initialize efun sockets */ #endif preload_objects(e_flag); #ifdef SIGFPE signal(SIGFPE, sig_fpe); #endif #ifdef TRAP_CRASHES #ifdef SIGUSR1 signal(SIGUSR1, sig_usr1); #endif signal(SIGTERM, sig_term); signal(SIGINT, sig_int); #ifndef DEBUG #if defined(SIGABRT) && !defined(LATTICE) signal(SIGABRT, sig_abrt); #endif #ifdef SIGIOT signal(SIGIOT, sig_iot); #endif #ifdef SIGHUP signal(SIGHUP, sig_hup); #endif #ifdef SIGBUS signal(SIGBUS, sig_bus); #endif #ifndef LATTICE signal(SIGSEGV, sig_segv); signal(SIGILL, sig_ill); #endif #endif /* DEBUG */ #endif backend(); return 0; }
int main() { float target_torque = -25.0; // mNm float actual_torque = 0; // mNm float tolerance = 0.76; // mNm int actual_position = 0; // ticks int actual_velocity = 0; // rpm int ack = 0; int sdo_update = 1; // 1- yes / 0 - no int slave_number = 0; /* Initialize Ethercat Master */ init_master(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Initialize all connected nodes with Mandatory Motor Configurations (specified under config/motor/)*/ init_nodes(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Initialize torque parameters */ initialize_torque(slave_number, slv_handles); /* Initialize the node specified with slave_number with Profile Torque(TQ) configurations (specified under config/motor/)*/ set_operation_mode(TQ, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Enable operation of node in TQ mode */ enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); while(1) { /* Update the process data (EtherCat packets) sent/received from the node */ pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); if(master_setup.op_flag) /*Check if the master is active*/ { /* Send target torque for the node specified by slave_number */ set_torque_mNm(target_torque, slave_number, slv_handles); /* Check if target torque is reached with specified tolerance */ ack = target_torque_reached(slave_number, target_torque, tolerance, slv_handles); /* Read actual node sensor values */ actual_torque= get_torque_actual_mNm(slave_number, slv_handles); actual_position = get_position_actual_ticks(slave_number, slv_handles); actual_velocity = get_velocity_actual_rpm(slave_number, slv_handles); printf("target_torque %f \n",target_torque); printf("actual_torque %f position %d velocity %d ack %d\n", actual_torque, actual_position, actual_velocity, ack); } if(ack == 1) { break; } } printf("reached \n"); ack = 0; while(!ack) { pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); if(master_setup.op_flag) /*Check if the master is active*/ { actual_torque = get_torque_actual_mNm(slave_number, slv_handles); actual_position = get_position_actual_ticks(slave_number, slv_handles); actual_velocity = get_velocity_actual_rpm(slave_number, slv_handles); if(actual_torque > tolerance || actual_torque < -tolerance) { /* Quick stop Profile Torque mode (for emergency) */ quick_stop_torque(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); ack = 1; } printf("actual_torque %f position %d velocity %d ack %d\n", actual_torque, actual_position, actual_velocity, ack); } } printf("reached \n"); /* Regain control of node to continue after quick stop */ renable_ctrl_quick_stop(TQ, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); set_operation_mode(TQ, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /*target_torque = 15.0; // mNm while(1) { pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); if(master_setup.op_flag) // Check if the master is active { set_torque_mNm(target_torque, slave_number, slv_handles); ack = target_torque_reached(slave_number, target_torque, tolerance, slv_handles); actual_torque = get_torque_actual_mNm(slave_number, slv_handles); printf("target_torque %f \n",target_torque); printf("actual_torque %f ack %d\n", actual_torque, ack); } if(ack == 1) { break; } } */ /*printf("reached \n"); while(1) { pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); if(master_setup.op_flag)//Check if we are up { actual_torque = get_torque_actual_mNm(slave_number, slv_handles); printf("actual_torque %f \n",actual_torque); } }*/ /* Shutdown node operations */ shutdown_operation(TQ, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); return 0; }
int main() { int target_velocity = 2000; //rpm int acceleration = 1000; //rpm/s int deceleration = 1000; //rpm/s int actual_velocity = 0; // rpm int actual_position; // ticks float actual_torque; // mNm int steps = 0; int velocity_ramp = 0; // rpm /* Initialize Ethercat Master */ init_master(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Initialize all connected nodes with Mandatory Motor Configurations (specified in config/motor/)*/ init_nodes(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Initialize the node specified with ECAT_SLAVE_0 with CSV configurations (specified in config/motor/)*/ set_operation_mode(CSV, ECAT_SLAVE_0, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Enable operation of node in CSV mode */ enable_operation(ECAT_SLAVE_0, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Initialize velocity profile parameters */ steps = init_velocity_profile_params(target_velocity, actual_velocity, acceleration, deceleration, ECAT_SLAVE_0, slv_handles); /* catch interrupt signal */ signal(SIGINT, INThandler); /* Just for better printing result */ printf("\n"); system("setterm -cursor off"); while(1) { if (master_setup.op_flag && actual_velocity == 0) /*Check if the master is active and we haven't started moving yet*/ { for (int step = 1; step < steps + 1; step++) { /* Update the process data (EtherCat packets) sent/received from the node */ pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Generate target velocity steps */ velocity_ramp = generate_profile_velocity(step, ECAT_SLAVE_0, slv_handles); /* Send target velocity for the node specified by ECAT_SLAVE_0 */ set_velocity_rpm(velocity_ramp, ECAT_SLAVE_0, slv_handles); /* Read actual node sensor values */ actual_velocity = get_velocity_actual_rpm(ECAT_SLAVE_0, slv_handles); actual_position = get_position_actual_ticks(ECAT_SLAVE_0, slv_handles); actual_torque = get_torque_actual_mNm(ECAT_SLAVE_0, slv_handles); printf("\r Velocity: %d Position: %d Torque: %f ", actual_velocity, actual_position, actual_torque); } } else if (break_loop){ break; } else { /* Update the process data (EtherCat packets) sent/received from the node */ pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Read actual node sensor values */ actual_velocity = get_velocity_actual_rpm(ECAT_SLAVE_0, slv_handles); actual_position = get_position_actual_ticks(ECAT_SLAVE_0, slv_handles); actual_torque = get_torque_actual_mNm(ECAT_SLAVE_0, slv_handles); printf("\r Velocity: %d Position: %d Torque: %f ", actual_velocity, actual_position, actual_torque); } } printf("\n"); /* Quick stop velocity mode (for emergency) */ quick_stop_velocity(ECAT_SLAVE_0, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Regain control of node to continue after quick stop */ renable_ctrl_quick_stop(CSV, ECAT_SLAVE_0, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); set_operation_mode(CSV, ECAT_SLAVE_0, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); enable_operation(ECAT_SLAVE_0, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Shutdown node operations */ shutdown_operation(CSV, ECAT_SLAVE_0, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Just for better printing result */ system("setterm -cursor on"); return 0; }
int main() { int flag = 0; int acceleration = 350; // rpm/s int deceleration = 350; // rpm/s int velocity = 350; // rpm int actual_position = 0; // ticks int target_position = 0; // ticks int actual_velocity; // rpm float actual_torque; // mNm int steps = 0; int i = 1; int position_ramp = 0; int ack; int home_velocity = 250; // rpm int home_acceleration = 250; // rpm/s int sdo_update = 1; // 1- yes / 0 - no int slave_number = 0; /* Initialize Ethercat Master */ init_master(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Initialize torque parameters */ initialize_torque(slave_number, slv_handles); /* Initialize all connected nodes with Mandatory Motor Configurations (specified under config/motor/)*/ init_nodes(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Initialize the node specified with slave_number with Homing configurations (specified under config/motor/)*/ set_operation_mode(HM, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Enable operation of node in Homing mode */ enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); start_homing(&master_setup, slv_handles, home_velocity, home_acceleration, slave_number, TOTAL_NUM_OF_SLAVES); /* Shutdown Homing Operation */ shutdown_operation(HM, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* * Acquire actual position from the node a few times after homing and * set it as target position. (wait for controller to settle) */ i = 0; int difference = 1500; int previous=0; while(1) { pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); if(master_setup.op_flag) //Check if the master is active { actual_position = get_position_actual_ticks(slave_number, slv_handles); target_position = actual_position; set_profile_position_ticks(target_position, slave_number, slv_handles); i = i+1; difference = actual_position - previous; if(difference <1 && difference >-1) { //printf(" difference %d act %d\n",difference, actual_position); break; } previous = actual_position; //printf(" difference %d act %d\n",difference, actual_position); } } /* Now initialize the node specified with slave_number with CSP configurations (specified under config/motor/)*/ set_operation_mode(CSP, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Enable operation of node in CSP mode */ enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Initialize position profile parameters */ initialize_position_profile_limits(slave_number, slv_handles);//*/ /* Now setting a new target position after homing */ target_position = get_position_actual_ticks(slave_number, slv_handles) + 5000; if(target_position > 35000) target_position = 35000; printf(" target_position %d\n", target_position); /*calculate the no. of steps for the profile*/ steps = init_position_profile_params(target_position, actual_position, velocity, acceleration, \ deceleration, slave_number, slv_handles); /* Execute the position profile steps in a loop */ i = 1; while(1) { /* Update the process data (EtherCat packets) sent/received from the node */ pdo_handle_ecat(&master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); if(master_setup.op_flag) /*Check if the master is active*/ { if(i<steps) { /* Generate target position steps */ position_ramp = generate_profile_position(i, slave_number, slv_handles); /* Send target position for the node specified by slave_number */ set_position_ticks(position_ramp, slave_number, slv_handles); i = i+1; } if(i >= steps) { printf("ack received"); break; } //printf("actual position %d \n", get_position_actual_ticks(slave_number, slv_handles)); /* Read actual node sensor values */ actual_position = get_position_actual_ticks(slave_number, slv_handles); actual_velocity = get_velocity_actual_rpm(slave_number, slv_handles); actual_torque = get_torque_actual_mNm(slave_number, slv_handles); printf("actual position %d actual velocity %d actual_torque %f\n", actual_position, actual_velocity, actual_torque); } } /* Quick stop position mode (for emergency) */ quick_stop_position(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); /* Regain control of node to continue after quick stop */ renable_ctrl_quick_stop(CSP, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); set_operation_mode(CSP, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); // set operation mode to CSP enable_operation(slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); // enable operation /* Shutdown node operations */ shutdown_operation(CSP, slave_number, &master_setup, slv_handles, TOTAL_NUM_OF_SLAVES); // stop the node operation. or can continue with new position profile return 0; }
int main (int argc, char ** argv) { time_t tm; int i, new_mudlib = 0, got_defaults = 0; char *p; char version_buf[80]; #if 0 int dtablesize; #endif error_context_t econ; #ifdef PROTO_TZSET void tzset(); #endif #ifdef INCL_LOCALE_H setlocale(LC_ALL, "C"); #endif #if !defined(__SASC) && (defined(AMITCP) || defined(AS225)) amiga_sockinit(); atexit(amiga_sockexit); #endif #ifdef WRAPPEDMALLOC wrappedmalloc_init(); #endif /* WRAPPEDMALLOC */ #ifdef DEBUGMALLOC MDinit(); #endif #if (defined(PROFILING) && !defined(PROFILE_ON) && defined(HAS_MONCONTROL)) moncontrol(0); #endif #ifdef USE_TZSET tzset(); #endif boot_time = get_current_time(); const0.type = T_NUMBER; const0.u.number = 0; const1.type = T_NUMBER; const1.u.number = 1; /* const0u used by undefinedp() */ const0u.type = T_NUMBER; const0u.subtype = T_UNDEFINED; const0u.u.number = 0; //fake_prog.program_size = 0; //0 anyway /* * Check that the definition of EXTRACT_UCHAR() is correct. */ p = (char *) &i; *p = -10; if (EXTRACT_UCHAR(p) != 0x100 - 10) { fprintf(stderr, "Bad definition of EXTRACT_UCHAR() in interpret.h.\n"); exit(-1); } /* * An added test: can we do EXTRACT_UCHAR(x++)? * (read_number, etc uses it) */ p = (char *) &i; (void) EXTRACT_UCHAR(p++); if ((p - (char *) &i) != 1) { fprintf(stderr, "EXTRACT_UCHAR() in interpret.h evaluates its argument more than once.\n"); exit(-1); } /* * Check the living hash table size */ if (CFG_LIVING_HASH_SIZE != 4 && CFG_LIVING_HASH_SIZE != 16 && CFG_LIVING_HASH_SIZE != 64 && CFG_LIVING_HASH_SIZE != 256 && CFG_LIVING_HASH_SIZE != 1024 && CFG_LIVING_HASH_SIZE != 4096) { fprintf(stderr, "CFG_LIVING_HASH_SIZE in options.h must be one of 4, 16, 64, 256, 1024, 4096, ...\n"); exit(-1); } #ifdef RAND srand(get_current_time()); #else # ifdef DRAND48 srand48(get_current_time()); # else # ifdef RANDOM srandom(get_current_time()); # else fprintf(stderr, "Warning: no random number generator specified!\n"); # endif # endif #endif current_time = get_current_time(); /* * Initialize the microsecond clock. */ init_usec_clock(); /* read in the configuration file */ got_defaults = 0; for (i = 1; (i < argc) && !got_defaults; i++) { if (argv[i][0] != '-') { set_defaults(argv[i]); got_defaults = 1; } } get_version(version_buf); if (!got_defaults) { fprintf(stderr, "%s for %s.\n", version_buf, ARCH); fprintf(stderr, "You must specify the configuration filename as an argument.\n"); exit(-1); } printf("Initializing internal tables....\n"); init_strings(); /* in stralloc.c */ init_otable(); /* in otable.c */ init_identifiers(); /* in lex.c */ init_locals(); /* in compiler.c */ /* * If our estimate is larger than FD_SETSIZE, then we need more file * descriptors than the operating system can handle. This is a problem * that can be resolved by decreasing MAX_USERS, MAX_EFUN_SOCKS, or both. * * Unfortunately, since neither MAX_USERS or MAX_EFUN_SOCKS exist any more, * we have no clue how many we will need. This code really should be * moved to places where ENFILE/EMFILE is returned. */ #if 0 if (dtablesize > FD_SETSIZE) { fprintf(stderr, "Warning: File descriptor requirements exceed system capacity!\n"); fprintf(stderr, " Configuration exceeds system capacity by %d descriptor(s).\n", dtablesize - FD_SETSIZE); } #ifdef HAS_SETDTABLESIZE /* * If the operating system supports setdtablesize() then we can request * the number of file descriptors we really need. First check to see if * wee already have enough. If so dont bother the OS. If not, attempt to * allocate the number we estimated above. There are system imposed * limits on file descriptors, so we may not get as many as we asked for. * Check to make sure we get enough. */ if (getdtablesize() < dtablesize) if (setdtablesize(dtablesize) < dtablesize) { fprintf(stderr, "Warning: Could not allocate enough file descriptors!\n"); fprintf(stderr, " setdtablesize() could not allocate %d descriptor(s).\n", getdtablesize() - dtablesize); } /* * Just be polite and tell the administrator how many he has. */ fprintf(stderr, "%d file descriptors were allocated, (%d were requested).\n", getdtablesize(), dtablesize); #endif #endif time_to_clean_up = TIME_TO_CLEAN_UP; max_cost = MAX_COST; reserved_size = RESERVED_SIZE; max_array_size = MAX_ARRAY_SIZE; if(max_array_size > 65535){ fprintf(stderr, "Maximum array size can not exceed 65535"); max_array_size = 65535; } max_buffer_size = MAX_BUFFER_SIZE; max_string_length = MAX_STRING_LENGTH; mud_lib = (char *) MUD_LIB; set_inc_list(INCLUDE_DIRS); if (reserved_size > 0) reserved_area = (char *) DMALLOC(reserved_size, TAG_RESERVED, "main.c: reserved_area"); for (i = 0; i < sizeof consts / sizeof consts[0]; i++) consts[i] = exp(-i / 900.0); reset_machine(1); /* * The flags are parsed twice ! The first time, we only search for the -m * flag, which specifies another mudlib, and the D-flags, so that they * will be available when compiling master.c. */ for (i = 1; i < argc; i++) { if (argv[i][0] != '-') continue; switch (argv[i][1]) { case 'D': if (argv[i][2]) { lpc_predef_t *tmp = ALLOCATE(lpc_predef_t, TAG_PREDEFINES, "predef"); tmp->flag = argv[i] + 2; tmp->next = lpc_predefs; lpc_predefs = tmp; continue; } fprintf(stderr, "Illegal flag syntax: %s\n", argv[i]); exit(-1); case 'N': no_ip_demon++; continue; #ifdef HAS_CONSOLE case 'C': has_console = 1; continue; #endif #ifdef YYDEBUG case 'y': yydebug = 1; continue; #endif /* YYDEBUG */ case 'm': mud_lib = alloc_cstring(argv[i] + 2, "mudlib dir"); if (chdir(mud_lib) == -1) { fprintf(stderr, "Bad mudlib directory: %s\n", mud_lib); exit(-1); } new_mudlib = 1; break; } } if (!new_mudlib && chdir(mud_lib) == -1) { fprintf(stderr, "Bad mudlib directory: %s\n", mud_lib); exit(-1); } time(&tm); debug_message("----------------------------------------------------------------------------\n%s (%s) starting up on %s - %s\n\n", MUD_NAME, version_buf, ARCH, ctime(&tm)); add_predefines(); #ifdef WIN32 _tzset(); #endif #ifndef NO_IP_DEMON if (!no_ip_demon && ADDR_SERVER_IP) init_addr_server(ADDR_SERVER_IP, ADDR_SERVER_PORT); #endif /* NO_IP_DEMON */ set_eval(max_cost); save_context(&econ); if (SETJMP(econ.context)) { debug_message("The simul_efun (%s) and master (%s) objects must be loadable.\n", SIMUL_EFUN, MASTER_FILE); exit(-1); } else { init_simul_efun(SIMUL_EFUN); init_master(); } pop_context(&econ); for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; } else { /* * Look at flags. -m and -o has already been tested. */ switch (argv[i][1]) { case 'D': case 'N': case 'm': case 'y': case 'C': continue; case 'f': save_context(&econ); if (SETJMP(econ.context)) { debug_message("Error while calling master::flag(\"%s\"), aborting ...\n", argv[i] + 2); exit(-1); } push_constant_string(argv[i] + 2); apply_master_ob(APPLY_FLAG, 1); if (MudOS_is_being_shut_down) { debug_message("Shutdown by master object.\n"); exit(0); } pop_context(&econ); continue; case 'e': e_flag++; continue; case 'p': external_port[0].port = atoi(argv[i] + 2); continue; case 'd': #ifdef DEBUG_MACRO if (argv[i][2]) debug_level_set(&argv[i][2]); else debug_level |= DBG_d_flag; #else debug_message("Driver must be compiled with DEBUG_MACRO on to use -d.\n"); #endif break; case 'c': comp_flag++; continue; case 't': t_flag++; continue; default: debug_message("Unknown flag: %s\n", argv[i]); exit(-1); } } } if (MudOS_is_being_shut_down) exit(1); if (*(DEFAULT_FAIL_MESSAGE)) { char buf[8192]; strcpy(buf, DEFAULT_FAIL_MESSAGE); strcat(buf, "\n"); default_fail_message = make_shared_string(buf); } else default_fail_message = "What?\n"; #ifdef PACKAGE_MUDLIB_STATS restore_stat_files(); #endif preload_objects(e_flag); #ifdef SIGFPE signal(SIGFPE, sig_fpe); #endif #ifdef TRAP_CRASHES #ifdef SIGUSR1 signal(SIGUSR1, sig_usr1); #endif #ifdef SIGUSR2 signal(SIGUSR2, sig_usr2); #endif signal(SIGTERM, sig_term); signal(SIGINT, sig_int); #ifndef DEBUG #if defined(SIGABRT) signal(SIGABRT, sig_abrt); #endif #ifdef SIGIOT signal(SIGIOT, sig_iot); #endif #ifdef SIGHUP signal(SIGHUP, sig_hup); #endif #ifdef SIGBUS signal(SIGBUS, sig_bus); #endif signal(SIGSEGV, sig_segv); signal(SIGILL, sig_ill); #endif /* DEBUG */ #endif #ifndef WIN32 #ifdef USE_BSD_SIGNALS signal(SIGCHLD, sig_cld); #else signal(SIGCLD, sig_cld); #endif #endif #ifdef HAS_CONSOLE if(has_console >= 0) signal(SIGTTIN, sig_ttin); signal(SIGTTOU, SIG_IGN); #endif backend(); return 0; }
int main(int argc, char** argv) { /* Variable declaration */ unsigned char* buffer; int free_size = 0, count = 0, i, j; /* Variable initialization */ srand(time(NULL)); buffer = (unsigned char*) malloc(HDA_SECTORSIZE * sizeof(unsigned char)); /* Check the usage of the main program */ cmdname = argv[0]; processtype = argv[1]; if (argc == 1) { usage(); return EXIT_FAILURE; } /* Only disk creation */ if(strcmp(processtype, "mkhd") == 0) { /* Delete the old disks */ remove("vdiskA.bin"); remove("vdiskB.bin"); /* New disk initialization */ init_master(); printf("The disks have been successfully created.\n"); return EXIT_SUCCESS; } /* Disk initialization */ init_master(); /* Load master boot record and partition information */ load_mbr(); init_volume(); /* Get the status of the disk (free space) */ if (strcmp(processtype, "status") == 0) { if (!load_super(CURRENT_VOL)) { fprintf(stderr, "No file system on the chosen partition\n"); return EXIT_FAILURE; } printf("Space status of the volume : %s \n", current_super.super_name); free_size = mbr.mbr_vol[CURRENT_VOL].vol_n_sector - 1; double percent = (current_super.super_nb_free / (double) free_size) * 100; printf("Free space : %f %\n", percent); printf("Free blocs : %d\n", current_super.super_nb_free); return EXIT_SUCCESS; } /* Fill the partition */ if (strcmp(processtype, "debug_fill") == 0) { printf("Filling the current partition\n"); if (!load_super(CURRENT_VOL)) { fprintf(stderr, "No file system on the chosen partition\n"); return EXIT_FAILURE; } int b; do { b = new_bloc(); if(b != BLOC_NULL) { count++; printf("."); fflush(stdout); } } while (b != 0); printf("\n"); printf("Number of allocated blocs : %d\n", count); return EXIT_SUCCESS; } /* Random free of the partition */ if (strcmp(processtype, "debug_free") == 0) { unsigned size = mbr.mbr_vol[CURRENT_VOL].vol_n_sector - 1; unsigned begin = mbr.mbr_vol[CURRENT_VOL].vol_first_sector; int it = begin + size; int n; count = 0; if (!load_super(CURRENT_VOL)) { fprintf(stderr, "No file system on the chosen partition\n"); return EXIT_FAILURE; } /* Check if the partition is empty */ if(current_super.super_nb_free == size) { fprintf(stderr, "No bloc to free, the current partition is empty.\n"); return EXIT_FAILURE; } /* Random free of the partition blocs */ for (n = begin; n < it / 10; n++) { int random = rand() % it; if(random == 0) continue; free_bloc(random); printf("%d\n", random); count++; } printf("Number of desallocated blocs : %d\n", count); return EXIT_SUCCESS; } /* Make a new filesystem */ if (strcmp(processtype, "mknfs") == 0) { init_super(CURRENT_VOL); printf("A new file system has been successfully installed on the current partition N°%d.\n", CURRENT_VOL); return EXIT_SUCCESS; } /* Process to format the entire disk */ if (strcmp(processtype, "frmt") == 0) { for (i = 0; i < HDA_MAXCYLINDER; i++) { for (j = 0; j < HDA_MAXSECTOR; j++) { format_sector(i, j, HDA_SECTORSIZE, 0); } } printf("The entire disk has been successfully formated.\n"); return EXIT_SUCCESS; } /* Process to dump the content of the first sector */ if (strcmp(processtype, "dmps") == 0) { read_sector_n(0, 0, HDA_SECTORSIZE, buffer); dump(buffer, HDA_SECTORSIZE, 0, 1); return EXIT_SUCCESS; } /* Process type unknown */ usage(); return EXIT_FAILURE; }