Exemplo n.º 1
0
int main()
{
	int baudnum = 1;
	int deviceIndex = 0;
	int PresentPos;
	int CommStatus;

	printf( "\n\nRead/Write example for Linux\n\n" );
	///////// Open USB2Dynamixel ////////////
	if( dxl_initialize(deviceIndex, baudnum) == 0 )
	{
		printf( "Failed to open USB2Dynamixel!\n" );
		printf( "Press Enter key to terminate...\n" );
		getchar();
		return 0;
	}
	else
		printf( "Succeed to open USB2Dynamixel!\n" );
	
	
	dxl_write_byte( DEFAULT_ID, P_TORQUE_ENABLE, 0 );
	while(1)
	{
		printf( "Press Enter key to continue!(press ESC and Enter to quit)\n" );
		if(getchar() == 0x1b)
			break;

		do
		{
			// Read present position
			PresentPos = dxl_read_word( DEFAULT_ID, P_PRESENT_POSITION_L );
			CommStatus = dxl_get_result();

			if( CommStatus == COMM_RXSUCCESS )
			{
				printf( "Position:   %d\n", PresentPos );
				PrintErrorCode();
			}
			else
			{
				PrintCommStatus(CommStatus);
				break;
			}

		} while(1);
	}

	// Close device
	dxl_terminate();
	printf( "Press Enter key to terminate...\n" );
	getchar();
	return 0;
}
Exemplo n.º 2
0
Arquivo: ReadWrite.c Projeto: fjp/ba
int main()
{
	int baudnum = 34;
	int GoalPos[2] = {0, 7095};
	//int GoalPos[2] = {0, 4095}; // for Ex series
	int index = 1;
	int deviceIndex = 0;
	int Moving, PresentPos;
	int CommStatus;

	printf( "\n\nRead/Write example for Linux\n\n" );
	///////// Open USB2Dynamixel ////////////
	if( dxl_initialize(deviceIndex, baudnum) == 0 )
	{
		printf( "Failed to open USB2Dynamixel!\n" );
		printf( "Press Enter key to terminate...\n" );
		getchar();
		return 0;
	}
	else
		printf( "Succeed to open USB2Dynamixel!\n" );

	while(1)
	{
		printf( "Press Enter key to continue!(press ESC and Enter to quit)\n" );
		if(getchar() == 0x1b)
			break;

		// Write goal position
		dxl_write_word( DEFAULT_ID, P_GOAL_POSITION_L, GoalPos[index] );
		do
		{
			// Read present position
			PresentPos = dxl_read_word( DEFAULT_ID, P_PRESENT_POSITION_L );
			CommStatus = dxl_get_result();

			if( CommStatus == COMM_RXSUCCESS )
			{
				printf( "%d   %d\n",GoalPos[index], PresentPos );
				PrintErrorCode();
			}
			else
			{
				PrintCommStatus(CommStatus);
				break;
			}

			// Check moving done
			Moving = dxl_read_byte( DEFAULT_ID, P_MOVING );
			CommStatus = dxl_get_result();
			if( CommStatus == COMM_RXSUCCESS )
			{
				if( Moving == 0 )
				{
					// Change goal position
					if( index == 0 )
						index = 1;
					else
						index = 0;					
				}

				PrintErrorCode();
			}
			else
			{
				PrintCommStatus(CommStatus);
				break;
			}
		}while(Moving == 1);
	}

	// Close device
	dxl_terminate();
	printf( "Press Enter key to terminate...\n" );
	getchar();
	return 0;
}
Exemplo n.º 3
0
void Dynamixel::end(void){

	dxl_terminate();
}
void close_USB2Dyn(){
  dxl_terminate();
}
Exemplo n.º 5
0
int main()
{
    int i;
	int baudnum = DEFAULT_BAUDNUM;
	int GoalPos[2] = {0, 1023};
	//int GoalPos[2] = {0, 4095}; // for Ex series
	int index = 0;
	int deviceIndex = 0;
	int Moving, PresentPos;
	int CommStatus;

	system("/home/humanoid/Documents/visao/bin/Debug/visao");
system("echo 123456 | sudo -S chmod 777 /dev/ttyUSB*");//USB
//system("./home/humanoidfei/Documents/visao/bin/Debug/visao");


    //id_t PID = getpid();
    char string[50];
    sprintf(string,"echo 123456 | sudo -S renice -20 -p %d", getpid());
    system(string);

  //  char command[50];
  //  sprintf(command, "echo 123456 | sudo -S renice 0 -p %d", getProcIdByName("pulseaudio"));
  //  system(command);
    //int PID = popen("pidof pulseaudio","r");
    //system("echo 123456 | sudo -S renice 0 1533");
	//setpriority(PRIO_PROCESS, getpid(), -20);

	printf( "\n\nRx-28 example for Linux\n\n" );
	///////// Open USB2Dynamixel ////////////
	if( dxl_initialize(deviceIndex, baudnum) == 0 )
	{
		printf( "Failed to open USB2Dynamixel!\n" );
		printf( "Press Enter key to terminate...\n" );
		getchar();
		return 0;
	}
	else
		printf( "Succeed to open USB2Dynamixel!\n" );

	while(1)
	{
		printf( "Press Enter key to continue!(press ESC and Enter to quit)\n" );
		if(getchar() == 0x1b)
			break;

	//	// Write goal position
		for(i = 1;i<21;i++)
        dxl_write_word( i, P_GOAL_POSITION_L, GoalPos[index] );
       dxl_write_word( 3, 32, 0);//usleep(1000000);
					if( index == 0 )
						index = 1;
					else
						index = 0;










	/*	do
		{
			// Read present position
			//for(i=1;i<11;i++)
			PresentPos = dxl_read_word( i, P_PRESENT_POSITION_L ); //usleep(1000000);
			CommStatus = dxl_get_result();

			if( CommStatus == COMM_RXSUCCESS )
			{
				printf( "%d   %d\n",GoalPos[index], PresentPos );
				PrintErrorCode();
			}
			else
			{
				PrintCommStatus(CommStatus);
				break;
			}
			// Check moving done
			//for(i=1;i<11;i++)
			Moving = dxl_read_byte( i, P_MOVING );
			CommStatus = dxl_get_result();

			if( CommStatus == COMM_RXSUCCESS )
			{
				if( Moving == 0 )
				{
					// Change goal position
					if( index == 0 )
						index = 1;
					else
						index = 0;
				}

				PrintErrorCode();
			}
			else
			{
				PrintCommStatus(CommStatus);
				break;
			}
		}while(Moving == 1);*/
		}
	//}
	// Close device
	dxl_terminate();
	printf( "Press Enter key to terminate...\n" );
	getchar();
	return 0;
}
Exemplo n.º 6
0
Dxl::~Dxl()
{
    dxl_terminate();
}
Exemplo n.º 7
0
void signal_callback_handler(int signum)
{
  printf("Caught signal %d\n", signum);
  dxl_terminate();
  exit(signum);
}
int main(int argc, char **argv) 
{ 
  std::string dash_m = "-m";
  std::string dash_tty = "-tty";
  std::string dash_baud = "-baud";
  
  if (argc<2) {
   ROS_INFO("using default motor_id %d, baud code %d, via /dev/ttyUSB%d",motor_id,baudnum,ttynum);
   ROS_INFO("may run with command args, e.g.: -m 2 -tty 1 for motor_id=2 on /dev/ttyUSB1");
  }
  else {
   std::vector <std::string> sources;
    for (int i = 1; i < argc; ++i) { // argv[0] is the path to the program, we want from argv[1] onwards
            sources.push_back(argv[i]); 
    }
    for (int i=0;i<argc-2;i++) {  // if have a -m or -tty, MUST have at least 2 args
       std::cout<<sources[i]<<std::endl;
       if (sources[i]==dash_m) {
        std::cout<<"found dash_m"<<std::endl;
        motor_id = atoi(sources[i+1].c_str()); 
 
        }
       if (sources[i]==dash_tty) {
        std::cout<<"found dash_tty"<<std::endl;
        ttynum = atoi(sources[i+1].c_str()); 
        }
       if (sources[i]==dash_baud) {
        std::cout<<"found dash_baud"<<std::endl;
        baudnum = atoi(sources[i+1].c_str()); 
        }
    }
    ROS_INFO("using motor_id %d at baud code %d via /dev/ttyUSB%d",motor_id,baudnum,ttynum);
  }
        

  char node_name[50];
  char in_topic_name[50];
  char out_topic_name[50];
  sprintf(node_name,"dynamixel_motor%d",motor_id);
  ROS_INFO("node name: %s",node_name);
  sprintf(in_topic_name,"dynamixel_motor%d_cmd",motor_id);
  ROS_INFO("input command topic: %s",in_topic_name);
  sprintf(out_topic_name,"dynamixel_motor%d_ang",motor_id);
  ROS_INFO("output topic: %s",out_topic_name);

  char in_topic_toggle[50];
  sprintf(in_topic_toggle,"dynamixel_motor%d_mode",motor_id);


  ros::init(argc,argv,node_name); //name this node 

  ros::NodeHandle n; // need this to establish communications with our new node 
  ros::Publisher pub_jnt = n.advertise<std_msgs::Int16>(out_topic_name, 1);
  
  double dt= 0.01; // 100Hz

  ROS_INFO("attempting to open /dev/ttyUSB%d",ttynum);
  bool open_success = open_dxl(ttynum,baudnum);

  if (!open_success) {
    ROS_WARN("could not open /dev/ttyUSB%d; check permissions?",ttynum);
    return 0;
  }

  ROS_INFO("attempting communication with motor_id %d at baudrate code %d",motor_id,baudnum);

  ros::Subscriber subscriber = n.subscribe(in_topic_name,1,dynamixelCB); 
  ros::Subscriber toggle_subscriber = n.subscribe(in_topic_toggle,1,toggleCB); 
  std_msgs::Int16 motor_ang_msg;
  short int sensed_motor_ang=0;

  torque_control_toggle(motor_id,0); // set motor to torque mode during initialization

  // set position/torque limits during initialization
  set_torque_max(motor_id,torque_max);
  set_dynamixel_CW_limit(motor_id,CW_limit);
  set_dynamixel_CCW_limit(motor_id,CCW_limit);


  while(ros::ok()) {
   sensed_motor_ang = read_position(motor_id);
   if (sensed_motor_ang>4096) {
      ROS_WARN("read error from Dynamixel: ang value %d at cmd %d",sensed_motor_ang-4096,g_goal_cmd);
    }
    motor_ang_msg.data = sensed_motor_ang;
   pub_jnt.publish(motor_ang_msg);
   ros::Duration(dt).sleep();
   ros::spinOnce();
   }
  dxl_terminate();
  ROS_INFO("goodbye");
  return 0; // should never get here, unless roscore dies 
} 
void dynamixelApi_terminate() {
	dxl_terminate();
}
Exemplo n.º 10
0
int main()
{
	int id[NUM_ACTUATOR];
	int baudnum = 1;
	int deviceIndex = 0;
	float phase[NUM_ACTUATOR];
	float theta = 0;
	int AmpPos = 512;
	//int AmpPos = 2048; // for EX series
	int GoalPos;
	int i;
	int CommStatus;
	printf( "\n\nSyncWrite example for Linux\n\n" );

	// Initialize id and phase
	for( i=0; i<NUM_ACTUATOR; i++ )
	{
		id[i] = i+1;
		phase[i] = 2*PI * (float)i / (float)NUM_ACTUATOR;
	}

	///////// Open USB2Dynamixel ////////////
	if( dxl_initialize(deviceIndex, baudnum) == 0 )
	{
		printf( "Failed to open USB2Dynamixel!\n" );
		printf( "Press Enter key to terminate...\n" );
		getchar();
		return 0;
	}
	else
		printf( "Succeed to open USB2Dynamixel!\n" );
	
	// Set goal speed
	dxl_write_word( BROADCAST_ID, P_GOAL_SPEED_L, 0 );
	// Set goal position
	dxl_write_word( BROADCAST_ID, P_GOAL_POSITION_L, AmpPos );

	while(1)
	{
		printf( "Press Enter key to continue!(press ESC and Enter to quit)\n" );
		if(getchar() == 0x1b)
			break;

		theta = 0;
		do
		{
			// Make syncwrite packet
			dxl_set_txpacket_id(BROADCAST_ID);
			dxl_set_txpacket_instruction(INST_SYNC_WRITE);
			dxl_set_txpacket_parameter(0, P_GOAL_POSITION_L);
			dxl_set_txpacket_parameter(1, 2);
			for( i=0; i<NUM_ACTUATOR; i++ )
			{
				dxl_set_txpacket_parameter(2+3*i, id[i]);
				GoalPos = (int)((sin(theta+phase[i]) + 1.0) * (double)AmpPos);
				printf( "%d:%d  ", id[i], GoalPos );
				dxl_set_txpacket_parameter(2+3*i+1, dxl_get_lowbyte(GoalPos));
				dxl_set_txpacket_parameter(2+3*i+2, dxl_get_highbyte(GoalPos));
			}
			dxl_set_txpacket_length((2+1)*NUM_ACTUATOR+4);
			

			printf( "\n" );
			
			dxl_txrx_packet();
			CommStatus = dxl_get_result();
			if( CommStatus == COMM_RXSUCCESS )
			{
				PrintErrorCode();
			}
			else
			{
				PrintCommStatus(CommStatus);
				break;
			}
			
			theta += STEP_THETA;
			usleep(CONTROL_PERIOD);

		}while(theta < 2*PI);
	}

	dxl_terminate();
	printf( "Press Enter key to terminate...\n" );
	getchar();

	return 0;
}
Exemplo n.º 11
0
int main(){

	int devNumber = 0;
	int baudNumber = 1;	//For 1 Mbps baud

	printf("Running StandSit. Press ESC to terminate.\n");

	if(!(dxl_initialize(devNumber, baudNumber))){

		printf("Failed to open USB Interface. :(\n");
		return 0;
	}
	else{

		printf("USB Interfaced Opened! :D\n");
	}

//	if(SITTING_POS != dxl_read_byte(BROADCAST_ID, P_PRESENT_POSITION_L)){
//
//		printf("Going to initial sitting position.\n");
//		dxl_write_word(BROADCAST_ID, P_PRESENT_POSITION_L, SITTING_POS);
//		while(1 == dxl_read_byte(BROADCAST_ID, P_MOVING));
//	}

	int loopCount = 0;	

	printf("Going into main loop...\n");
	while(1){

		printf("Loop time! Round %d\n", loopCount++);

	//	if(getchar() == 0x1b)
	//		break;

		if(STANDING_POS == dxl_read_byte(BROADCAST_ID, P_PRESENT_POSITION_L)){

			printf("Sitting down...\n");
			dxl_write_word(BROADCAST_ID, P_PRESENT_POSITION_L, SITTING_POS);
		}

		else if(SITTING_POS == dxl_read_byte(BROADCAST_ID, P_PRESENT_POSITION_L)){

			printf("Standing up...\n");
			dxl_write_word(BROADCAST_ID, P_PRESENT_POSITION_L, STANDING_POS);
		}

		else{

			int CommStatus = dxl_get_result();

			switch(CommStatus)
			{
			case COMM_TXFAIL:
				printf("COMM_TXFAIL: Failed transmit instruction packet!\n");
				break;

			case COMM_TXERROR:
				printf("COMM_TXERROR: Incorrect instruction packet!\n");
				break;

			case COMM_RXFAIL:
				printf("COMM_RXFAIL: Failed get status packet from device!\n");
				break;

			case COMM_RXWAITING:
				printf("COMM_RXWAITING: Now recieving status packet!\n");
				break;

			case COMM_RXTIMEOUT:
				printf("COMM_RXTIMEOUT: There is no status packet!\n");
				break;

			case COMM_RXCORRUPT:
				printf("COMM_RXCORRUPT: Incorrect status packet!\n");
				break;

			default:
				printf("This is unknown error code!\n");
				break;
			}
		}

		//while(1 == dxl_read_byte(BROADCAST_ID, P_MOVING));

		sleep(1);
	}

	dxl_terminate();
	printf("Shutting down...\n");
	return 0;
}
Exemplo n.º 12
0
ControlUtils::~ControlUtils()
{
	dxl_terminate();
}
Exemplo n.º 13
0
// High level initialization - specific robot settings for Bioloid
void dxl_init(int baudnum)
{
	int commStatus = 0, errorStatus = 0;
	
	// now prepare the Dynamixel servos
	// first initialize the bus
	dxl_initialize( 0, baudnum ); 
	// wait 0.1s
	_delay_ms(100);
	
	// Next check the hardware configuration is valid
	for (int i=0; i<NUM_AX12_SERVOS; i++)
	{
		// ping each servo in turn
		errorStatus = dxl_ping(AX12_IDS[i]);
		if (errorStatus == -1)
		{
			printf("\nHardware Configuration Failure at Dynamixel ID %i.\n", AX12_IDS[i]);
			dxl_terminate();
			return;
		}
	}
	
	// set alarm LED and shutdown to prevent overheat/overload
	commStatus = dxl_write_byte(BROADCAST_ID, DXL_ALARM_LED, 36);
	if(commStatus != COMM_RXSUCCESS) {
		printf("\nDXL_ALARM_LED Broadcast - ");
		dxl_printCommStatus(dxl_get_result());
	}	
	commStatus = dxl_write_byte(BROADCAST_ID, DXL_ALARM_SHUTDOWN, 36);
	if(commStatus != COMM_RXSUCCESS) {
		printf("\nDXL_ALARM_LED Broadcast - ");
		dxl_printCommStatus(dxl_get_result());
	}	
	// now set temperature and voltage limits
	commStatus = dxl_write_byte(BROADCAST_ID, DXL_TEMPERATURE_LIMIT, 70);
	if(commStatus != COMM_RXSUCCESS) {
		printf("\nDXL_TEMPERATURE_LIMIT Broadcast - ");
		dxl_printCommStatus(dxl_get_result());
	}	
	commStatus = dxl_write_byte(BROADCAST_ID, DXL_LOW_VOLTAGE_LIMIT, 70);
	if(commStatus != COMM_RXSUCCESS) {
		printf("\nDXL_LOW_VOLTAGE_LIMIT Broadcast - ");
		dxl_printCommStatus(dxl_get_result());
	}	
	// set a 2-point compliance margin (equals 0.58 deg)
	commStatus = dxl_write_byte(BROADCAST_ID, DXL_CW_COMPLIANCE_MARGIN, 2);
	if(commStatus != COMM_RXSUCCESS) {
		printf("\nDXL_CW_COMPLIANCE_MARGIN Broadcast - ");
		dxl_printCommStatus(dxl_get_result());
	}	
	commStatus = dxl_write_byte(BROADCAST_ID, DXL_CCW_COMPLIANCE_MARGIN, 2);
	if(commStatus != COMM_RXSUCCESS) {
		printf("\nDXL_CCW_COMPLIANCE_MARGIN Broadcast - ");
		dxl_printCommStatus(dxl_get_result());
	}	
	_delay_ms(100);
	// and enable torque to keep positions
	commStatus = dxl_write_byte(BROADCAST_ID, DXL_TORQUE_ENABLE, 1);
	if(commStatus != COMM_RXSUCCESS) {
		printf("\nDXL_TORQUE_ENABLE Broadcast - ");
		dxl_printCommStatus(dxl_get_result());
	}	
	_delay_ms(50);
}
Exemplo n.º 14
0
Arquivo: Scan.c Projeto: wmacevoy/grit
int main()
{
	int baudnum = 34;
	int deviceIndex = 0;

	printf( "\n\nRead/Write example for Linux\n\n" );
	///////// Open USB2Dynamixel ////////////
	if( dxl_initialize(deviceIndex, baudnum) == 0 )
	{
		printf( "Failed to open USB2Dynamixel!\n" );
		printf( "Press Enter key to terminate...\n" );
		getchar();
		return 0;
	}
	else
		printf( "Succeed to open USB2Dynamixel!\n" );
	while(1)
	{
		printf( "Press Enter key to continue!(press ESC and Enter to quit)\n" );
		if(getchar() == 0x1b)
			break;
		  jointMode(4,180);
		  jointMode(5,180);

/*                int i;
                for (i=4;i<=5;i++)  {
                  dxl_ping(i);
                  printf("%i",i);
                  int result = dxl_get_result( );
                  if( result == COMM_TXSUCCESS )
		  {
                    printf("TX+");
		  }
		  else if( result == COMM_RXSUCCESS )
		  {
                    printf("RX+");
                    int j;
                    for (j=0;j<=8;j++) {
                      int value;
                      result=dxl_get_result( );
                      if (result == COMM_RXSUCCESS) {
                        value=dxl_read_byte(i,j);
                        printf("%i->%i\n",j,value);
                      } else 
                        printf("Error reading byte\n");
                    }
		  }
		  else if( result == COMM_TXFAIL )
		  {
                    printf("TX-");
		  }
		  else if( result == COMM_RXFAIL)
		  {
                    printf("RX-");
		  }
		  else if( result == COMM_TXERROR )
		  {
                    printf("TX-");
		  }
		  else if( result == COMM_RXWAITING )
		  {
                    printf("W?");
		  }
                  printf("\n");
                } */
	}

	// Close device
	dxl_terminate();
	printf( "Press Enter key to terminate...\n" );
	getchar();
	return 0;
}
Exemplo n.º 15
0
int main() {
	double CoMavg;
	double sumns = 0;
        unsigned char dc1[2];
        unsigned char dc2[2];
        double arrayX[] =  { -31.6190, -31.9288, -32.0040, -32.3204, -32.5042, -16.5338, -16.5530, -16.7062, -16.7277, -16.7474, 0.2290,0.1433,-0.1915,-0.4104,-0.6338,16.3727,16.4583,16.5425,16.6221,16.7002,32.8839,32.6383,32.3759,32.1024, 31.8116};

//{-20.0480,-22.4280,-20.0480,-22.4280,-20.0480,-14.0480,-16.4280,-14.0480,-16.4280,-14.0480,-8.0480,-10.4280,-8.0480,-10.4280,-8.0480,-2.0480,-4.4280,-2.0480,-4.4280,-2.0480,3.9520,1.5720,3.9520,1.5720,3.9520,9.9520,7.5720,9.9520,7.5720,9.9520,15.9520,13.5720,15.9520,13.5720,15.9520,21.9520,19.5720,21.9520, 19.5720, 21.9520};

// {4.76, 2.38, 4.76, 2.38, 4.76, 10.76, 8.38, 10.76, 8.38, 10.76, 16.76, 14.38, 16.76, 14.38, 16.76, 22.76,20.38,22.76, 20.38, 22.76,28.76, 26.38,28.76, 26.38, 28.76, 34.76, 32.38, 34.76, 32.38, 34.76, 40.76, 38.38, 40.76, 38.38, 40.76, 46.76, 44.38, 46.76, 44.38, 46.76};
	//double arrayY[] = { 12,6,0,-6,-12,12,6,0,-6,-12,12,6,0,-6,-12,12,6,0,-6,-12,12,6,0,-6,-12,12,6,0,-6,-12,12,6,0,-6,-12,12,6,0,-6,-12};

//{27, 21, 15, 9, 3, 27, 21, 15, 9, 3, 27, 21, 15, 9, 3, 27, 21, 15, 9, 3, 27, 21, 15, 9, 3, 27, 21, 15, 9, 3, 27, 21, 15, 9, 3, 27, 21, 15, 9, 3};
	double weight[] = {0.5241, 2.2774, 0, 0.3845, 1.4690, 0.0059, 0,3.7938, 0,2.6875,323.1828,238.0930,0,0,0,7.7829,0,1.6664,0,0,0.8394,0.8289,0,1.2467,0.5905};
	//dynamixel initialization stuff
	int baudnum = 1;
	int limits[2] = {0, 1024};
        int index = 0;
        int deviceIndex = 0;
        int Moving, PresentPos;
        int CommStatus;
	int ns = 20;
	double CoMhist[ns];
	if( dxl_initialize(deviceIndex, baudnum) == 0 ) {
                printf( "Failed to open USB2Dynamixel!\n" );
	} 
	int turnValue = 512;
        dxl_write_word( MOTOR, 32, 75); //sets the speed for turning
        dxl_write_word( MOTOR, P_GOAL_POSITION_L, turnValue );


        TakkTile takktile = TakkTile();
        takktile.startSampling(200,dc2);
        
	double baseline[40];
	std::cout<< "calibrating..." <<std::endl;
	if(takktile.calibrate(baseline,10)==0) { 
		std::cout<< "error!" <<std::endl;
		goto exit;
	}

	std::cout<<"done calibrating"<<std::endl;
	for (int i=0; i<100000; i++) { //args instead of 5
        	if (i > ns) sumns = sumns - CoMhist[i%ns];
		Data data;
		if(takktile.getData(data)==0){ std::cout<< "error :(" <<std::endl; }
		
		double sumx=0;
//		double sumy=0;
		double sum=0;
      		for (int j = 0; j < 25; j++) {//change to 40 for array
               		sumx += (double)(data.pressures[j]-baseline[j])*arrayX[j]*weight[j];
  //              	sumy += (double)(data.pressures[i]-baseline[i])*arrayY[i]*weight[i];
                	sum += (double)(data.pressures[j]-baseline[j])*weight[j];
        	}
        
		double CoMx = (double)(sumx)/(double)(sum);
//		double CoMy = (double)(sumy)/(double)(sum);
		CoMhist[i % ns] = CoMx;
		sumns = sumns + CoMhist[i%ns];
		CoMavg = (sumns / ns) + 1;
		if (i > 500){
		Moving = dxl_read_byte( DEFAULT_ID, P_MOVING );
		std::cout<<CoMx<<","<<CoMavg<<","<<turnValue<<"; ";

		//if (Moving){}
		//else{
		if(turnValue > 700) {
			turnValue = 700;}
		else if (turnValue < 350) { turnValue = 350;}
		else turnValue = turnValue - (int)(CoMavg/2);//plus for arry
		//std::cout<<turnValue<<std::endl;
		}

		dxl_write_word( MOTOR, P_GOAL_POSITION_L, turnValue ); 
		//}
	//	do {
                        // Read present position
                        //PresentPos = dxl_read_word( MOTOR, P_PRESENT_POSITION_L );
                        //CommStatus = dxl_get_result();

                        //if( CommStatus == COMM_RXSUCCESS ) { // printf( "%d   %d\n",turnValue, PresentPos );
                                //PrintErrorCode();
                       // } else {
                                //PrintCommStatus(CommStatus);
                         //       std::cout<< "comm error" <<std::endl;
			//	break;
                        //}

                        // Check moving done
          //              Moving = dxl_read_byte( MOTOR, P_MOVING );
                        //CommStatus = dxl_get_result();
                        //if( CommStatus == COMM_RXSUCCESS ) {
                        //        //PrintErrorCode();
                        //} else {
                        //        std::cout<< "comm error 2" <<std::endl;
				//PrintCommStatus(CommStatus);
                        //        break;
                        //}
        //        } while(Moving == 1);
	//	PresentPos = dxl_read_word( MOTOR, P_PRESENT_POSITION_L );



//		std::cout<< CoMx << " " << CoMy <<std::endl;
	}//time how long this takes
//	/for (int i = 0; i<100000000;i++); 
	
	exit: //note: doesn't quit very well
        takktile.stopSampling(dc1);
        takktile.TakkClose();
	dxl_terminate();
        return 0;
};
Exemplo n.º 16
0
DynamixelInterface::~DynamixelInterface() {
		  dxl_terminate();
	  }