• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ set_motors函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中set_motors函数的典型用法代码示例。如果您正苦于以下问题:C++ set_motors函数的具体用法?C++ set_motors怎么用?C++ set_motors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了set_motors函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: wallFollowingL

// Basic Left wall following code
void wallFollowingL()
{
	int rightSideIR, leftSideIR, rightFrontIR, leftFrontIR, distAhead, i;
	while (1)
	{
		get_front_ir_dists(&leftFrontIR, &rightFrontIR);
		get_side_ir_dists(&leftSideIR, &rightSideIR);
		distAhead = get_us_dist();

		if (distAhead < 40){		
			if (leftFrontIR - rightFrontIR > 0){
				set_motors(-SPEED, SPEED);
			}

			else {
				set_motors(SPEED, -SPEED);
			}
		}


		if (leftFrontIR > 30 )
			{	set_motors(SPEED-10, SPEED+10); } //turn left

		else if (leftFrontIR < 15 )
			{	set_motors (SPEED+10, SPEED-10); } //turn right

		else
			{set_motors(SPEED, SPEED); } // Straight

	}
}
开发者ID:quarbby,项目名称:race2lynnette,代码行数:32,代码来源:race2wall.c


示例2: wallFollowingR

// Basic Right wall following code
void wallFollowingR()
{
	int rightSideIR, leftSideIR, rightFrontIR, leftFrontIR, distAhead, i;
	while (1)
	{

		get_front_ir_dists(&leftFrontIR, &rightFrontIR);
		get_side_ir_dists(&leftSideIR, &rightSideIR);
		distAhead = get_us_dist();

		if (distAhead < 45){	
			if (leftFrontIR - rightFrontIR > 0){
				set_motors(-SPEED, SPEED);
			}

			else {
				set_motors(20, -20);
			}
		}

		else if (rightFrontIR > 30 && rightSideIR > 25)
			{	set_motors(SPEED+30, SPEED-8); } //turn right

		else if (rightFrontIR < 20 )
			{	set_motors (SPEED-10, SPEED+25); } //turn left

		else
			{set_motors(SPEED+8, SPEED+8); } // Straight

	}


}
开发者ID:quarbby,项目名称:race2lynnette,代码行数:34,代码来源:race2wall.c


示例3: goToAngle

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//					go to stuff   
	//
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	bool goToAngle(int toGoAngle, float* locationData) {
		//spin in place until facing angle. motors will turn at same speed, but at opposite directions

		int motorDiffkp  = 10;
		int motorDiffMax = 200;
		int maxAngle = 35;

		//get psi so it is between 180 and -180, 0 being at one goal

		int psi = (int)(locationData[0] *  RAD_DEG_RATIO) - 90; 
		if (psi<-180) { psi +=360; }
		if (psi>180) { psi -=360; }

		//error in angle, factoring in rotational velocity should be taken care of by kalman filter
		int theta_angle = (psi-toGoAngle);

		int atAngleError = 10;

		if (theta_angle > 180 ) { theta_angle -= 360; } 
		if (theta_angle < -180) { theta_angle += 360; }

		//motorDiff is the difference in PWM between the two motors
		int motorDiff = (int)((float)(motorDiffkp)*(float)(abs(theta_angle))/(float)maxAngle+minPWM-20);

		if (abs(theta_angle) > maxAngle) { motorDiff = motorDiffMax; }

		if (theta_angle >0) {  set_motors( motorDiff, -motorDiff ); }
		else {			set_motors( -motorDiff, motorDiff ); }

		if ( abs(theta_angle) < atAngleError) { atAngle = true; return true;}
		else {atAngle = false; return false;}

	}
开发者ID:mlautman,项目名称:ROBOCKEY,代码行数:40,代码来源:main.c


示例4: motor_drive

static void motor_drive() {
  if (g_motor_state.enabled) {
    set_motors(0, g_motor_state.direction * g_motor_state.speed);
  } else {
    set_motors(0, 0);
  }
}
开发者ID:posborne,项目名称:msse-embedded-systems,代码行数:7,代码来源:motor.c


示例5: calibrate

//Calibrates the sensor
void calibrate(unsigned int *sensors, unsigned int *minv, unsigned int *maxv) {
	//say something to the user
	clear();
	lcd_goto_xy(0, 0);
	print(" Fluffy");
	lcd_goto_xy(0, 1);
	print("A=Go!");
	
	//wait on the calibration button
	wait_for_button_press(BUTTON_A);
	
	//wait for the user to move his hand
	delay_ms(500);

	//activate the motors
	set_motors(40, -40);
	
	//take 165 readings from the sensors...why not?
	int i;
	for (i = 0; i < 165; i++) {
		read_line_sensors(sensors, IR_EMITTERS_ON);
		update_bounds(sensors, minv, maxv);
		delay_ms(10);
	}

	//and turn the motors off, we're done
	set_motors(0, 0);
	
	delay_ms(750);
}
开发者ID:thatguystone,项目名称:nyu-robotics-2010-3pi,代码行数:31,代码来源:test.c


示例6: turnToDirection

void turnToDirection(int turnDirection) {
	adjustAngle();
	int currentDir;
	currentDir = currentDirection();
	double target = (currentDir + turnDirection) * M_PI / 2;

	while(fabs(currentHeading() - target) > turnThreshold) {
		if(fabs(currentHeading() - target) < slowThreshold) {
			if(currentHeading() > target) {
				set_motors(-5,5);
			}
			if(currentHeading() < target) {
				set_motors(5,-5);
			}
		} else {
			if(currentHeading() > target) {
				set_motors(-15,15);
			}
			if(currentHeading() < target) {
				set_motors(15,-15);
			}
		}
		calcPos();
	}
	set_motors(0,0);
	adjustAngle();
	usleep(10000);
}
开发者ID:HappiApi,项目名称:Pair22,代码行数:28,代码来源:turn.c


示例7: main

int main(void) {
	m_clockdivide(0);
	setup_pins();
	if ( RF_debug) {setupUSB();}
	setup_timer_1();
	setup_timer_3();
	m_bus_init();
	m_rf_open(chan,RX_add,p_length);

	int timer_3_cnt = 0;

	//sei();
	set_motors(0,0);
	while (1){
		if (check(TIFR3,OCF3A)){
			set(TIFR3, OCF3A);
			timer_3_cnt++;
			if ( timer_3_cnt % 10 ==0 ) {
				timer_3_cnt=0;
				m_green(TOGGLE);
			}
			if ( timer_3_cnt == 1000){ timer_3_cnt=0;}
		}
		if(new){
			switch ( receive_buffer[11] ) {
				case Single_Joy: single_joystick(); break;
				case Double_Joy: double_joystick(); break;
				case Tank_Mode: tank_driving(); break;
				case Mario_Kart: Mario_Drive(); break;
				default : set_motors(0,0); m_green(2);
			}
			if(RF_debug){ debug_rf(); }
		}
	}
}
开发者ID:ezakoch,项目名称:VITAL-1,代码行数:35,代码来源:remoteRX.c


示例8: turn

// Turns according to the parameter dir, which should be 'L', 'R', 'S'
// (straight), or 'B' (back).
void turn(char dir, int angle)
{
   int time = (long)((float)(angle*MSPER90/9.0));

	switch(dir)
	{
	case 'L':
		// Turn left.
		set_motors(-40,40);
		delay_ms(time);
		break;
	case 'R':
		// Turn right.
		set_motors(40,-40);
		delay_ms(time);
		break;
	case 'B':
		// Turn around.
		set_motors(40,-40);
		delay_ms(time*2);
		break;
	case 'S':
		// Don't do anything!
		break;
	}
}
开发者ID:martina-if,项目名称:3pi,代码行数:28,代码来源:turn.c


示例9: turnLeft

void turnLeft(int maxspd, int minspd, int degrees) 
{
	//causes robot to spin left to a certain angle.

	int left1, left2, right1, right2, drotated = 0;
	get_motor_encoders(&left1, &right1);
	int turnLength = RIGHT_ANGLE_TURN_ENC * degrees / 90;
	
	while(drotated < turnLength) 
	{
		get_motor_encoders(&left2, &right2);
		drotated = ((left1 - left2) + (right2 - right1)) / 2;

		if(drotated < (maxspd - minspd) * 2)
		{
			//accelerate phase
			set_motors(-(minspd + drotated / 2), minspd + drotated / 2);
		} 
		else if(drotated < turnLength - (maxspd - minspd) * 2) 
		{
			//max speed phase
			set_motors(-maxspd, maxspd);
		} 
		else
		{
			//decelerate phase
			set_motors(-(minspd + (turnLength - drotated) / 2), minspd + (turnLength - drotated) / 2);
		}
		positioncalc();
	}
	set_motors(0, 0);
}
开发者ID:bmaulana,项目名称:uclcs-robot-race-bmvc,代码行数:32,代码来源:final.c


示例10: wallFollowingL

// Basic Left wall following code
void wallFollowingL()
{
	int rightSideIR, leftSideIR, rightFrontIR, leftFrontIR, distAhead, i;
	while (1)
	//for(i = 0; i < 250; i++)
	{
		get_front_ir_dists(&leftFrontIR, &rightFrontIR);
		get_side_ir_dists(&leftSideIR, &rightSideIR);
		distAhead = get_us_dist(); 
		
		printf("i = %i\n", i);
		
		if ( rightFrontIR < 30 )
		{ turnRight (90.0, 5);} // super turn right
		
		else if (leftFrontIR > 30 && leftSideIR > 25)
		{ set_motors(SPEED-15, SPEED+50);} // super turn left
		
		else if (leftFrontIR > 38)
		{ set_motors(SPEED, 30);} // too far, turn left
		
		else if ( leftFrontIR < 18 )
		{ set_motors(SPEED*1.5, SPEED);}  // turn right
		
		else
		{set_motors(SPEED+5, SPEED+5); } // Straight
	}
}
开发者ID:quarbby,项目名称:race2lynnette,代码行数:29,代码来源:race2brian.c


示例11: update_circle_velocities

void update_circle_velocities(float error){
    int pwr_change = format_velocity(fabs(error));
    int dir = field_state.drive_direction;
    if(field_state.substage == DRIVE_SUBSTAGE){
        /*if(fabs(mod_f(field_state.target_angle - mod_f(gyro_get_degrees(), 180), 180)) < ROTATION_THRESHOLD){
         if(current_vel == 0)
         current_vel = target_vel;
         }*/
        if(error*dir > 0){
            set_motors(dir*current_vel, dir*current_vel - dir*pwr_change);
            //printf("Left Vel: %d, Right Vel: %d\n", current_vel, current_vel - pwr_change);
        }
        else{
            set_motors(dir*current_vel - dir*pwr_change, dir*current_vel);
            //printf("Left Vel: %d, Right Vel: %d\n", current_vel - pwr_change, current_vel);
        }
    }
    else if(field_state.substage == TERRITORY_APPROACH_SUBSTAGE || field_state.substage == LEVER_APPROACH_SUBSTAGE || field_state.substage == DUMPING_SUBSTAGE || field_state.substage == PIVOT_SUBSTAGE || field_state.substage == LEVER_RETREAT_SUBSTAGE || field_state.substage == TERRITORY_RETREAT_SUBSTAGE){
        if(fabs(mod_f(field_state.target_angle - mod_f(gyro_get_degrees(), 180), 180)) < ROTATION_THRESHOLD){
            if(current_vel == 0){
                //used to know when we started moving toward the lever/territory
                field_state.stored_time = field_state.curr_time;
                current_vel = target_vel;
            }
        }
        if(error*dir > 0){
            set_motors(dir*current_vel + dir*pwr_change, dir*current_vel - dir*pwr_change);
            //printf("Left Vel: %d, Right Vel: %d\n", current_vel, current_vel - pwr_change);
        }
        else{
            set_motors(dir*current_vel - dir*pwr_change, dir*current_vel + dir*pwr_change);
            //printf("Left Vel: %d, Right Vel: %d\n", current_vel - pwr_change, current_vel);
        }
    }
}
开发者ID:alec-heif,项目名称:6.270-team1-repo,代码行数:35,代码来源:circle_drive_working_2.c


示例12: race_to

// ### Experimental racing function
double race_to(double curr_coord[2], double x, double y){
    double steering = 1.8;                 // Ratio between the speed of each wheels.
    double error_margin_angle = 3;      // Degrees
    double speed = 70;
    double dx = x - curr_coord[0];
    double dy = y - curr_coord[1];
    
    double targetA = atan2(dx, dy);
    double dangle = targetA - face_angle;
    dangle += (dangle > to_rad(180)) ? -to_rad(360) : (dangle < -to_rad(180)) ? to_rad(360) : 0;

    double distance = fabs(sqrt(dx*dx + dy*dy));
    // If we need to turn, perform steering maneuver
    if(fabs(dangle) >= to_rad(error_margin_angle)){
        if (to_degree(dangle) > 0){
            set_motors( speed*steering, speed/steering);
        }
        else {
            set_motors(speed/steering, speed*steering);
        }
        printf("Steering: %f \n", to_degree(dangle));
    }
    else { // Otherwise just go straight;
        set_motors(speed, speed);
    }
    position_tracker(curr_coord);
    return distance;
}
开发者ID:k-i-k-ichi,项目名称:robo,代码行数:29,代码来源:movelib.c


示例13: turn90

void turn90()
{
	while( fabs(currentHeading() - (M_PI/2.0)) > turnThreshold)
	{
		if(fabs(currentHeading() - (M_PI/2.0)) < slowThreshold)
		{
			if(currentHeading() > (M_PI/2.0))
			{
				set_motors(-1,1);
			}

			if(currentHeading() < (M_PI/2.0))
			{
				set_motors(1,-1);
			}
		}

		else
		{
			if(currentHeading() > (M_PI/2.0))
			{
				set_motors(-15,15);
			}

			if(currentHeading() < (M_PI/2.0))
			{
				set_motors(15,-15);
			}
		}
		
		calcPos();
	}
	set_motors(0,0);
	printf("Target : %f\n", M_PI/2.0);
}
开发者ID:HappiApi,项目名称:Pair22,代码行数:35,代码来源:turn.c


示例14: loop

void loop()
{
    // Set LED green.
    set_color(RGB(0, 1, 0));
    // Spinup motors to overcome friction.
    spinup_motors();
    // Move straight for 2 seconds (2000 ms).
    set_motors(kilo_straight_left, kilo_straight_right);
    delay(2000);
    
    // Set LED red.
    set_color(RGB(1, 0, 0));
    // Spinup motors to overcome friction.
    spinup_motors();
    // Turn left for 2 seconds (2000 ms).
    set_motors(kilo_turn_left, 0);
    delay(2000);
    
    // Set LED blue.
    set_color(RGB(0, 0, 1));
    // Spinup motors to overcome friction.
    spinup_motors();
    // Turn right for 2 seconds (2000 ms).
    set_motors(0, kilo_turn_right);
    delay(2000);
    
    // Set LED off.
    set_color(RGB(0, 0, 0));
    // Stop for half a second (500 ms).
    set_motors(0, 0);
    delay(500);
}
开发者ID:mgauci,项目名称:kilobotics-labs,代码行数:32,代码来源:simple_movement.c


示例15: moveBackwards

void moveBackwards(int maxspd, int minspd, int dist) 
{
	//speeds up, moves the robot backwards a certain distance, and slows down.

	int left1, left2, right1, right2;
	get_motor_encoders(&left1, &right1);
	
	while(1)
	{
		get_motor_encoders(&left2, &right2);
		int dtravelled = ((left1 - left2) + (right1 - right2)) / 2;

		if(dtravelled < (maxspd - minspd) * 2)
		{
			//accelerate phase
			set_motors(-(minspd + dtravelled / 2), -(minspd + dtravelled / 2));
		} 
		else if(dtravelled < dist - (maxspd - minspd) * 2) 
		{
			//max speed phase
			set_motors(-maxspd, -maxspd);
		} 
		else if(dtravelled < dist)
		{
			//decelerate phase
			set_motors(-(minspd + (dist - dtravelled) / 2), -(minspd + (dist - dtravelled) / 2));
		}
		else
		{
			break;
		}
		positioncalc();
	}
	set_motors(0, 0);
}
开发者ID:bmaulana,项目名称:uclcs-robot-race-bmvc,代码行数:35,代码来源:final.c


示例16: Mario_Drive

void Mario_Drive(){
	int HLeft =  ((*(int*)(&receive_buffer[6])) * 3 )/ 2;
	if (receive_buffer[1]==1) // right
		{ left = -MK_reverse ; right = -MK_reverse;}
	else if (receive_buffer[0]==1 ) // left
		{ left = MK_drive ; right = MK_drive;}
	else {left = 0; right =0; set_motors(0,0); return;}


	if ( left > -60 ){ 	// going forward
		if (HLeft > 0){ 	// joystic is to the right
			right -= HLeft;
		}else {			// joystic is to the left
			left  += HLeft;
		}
	}else {		 	// going backword  ( left < 0)
		if (HLeft > 0){		// joystic is to the right
			right += HLeft;
		}else {			// joystic is to the left
			left  -= HLeft;
		}
	}
	set_motors(left,right);

}
开发者ID:ezakoch,项目名称:VITAL-1,代码行数:25,代码来源:remoteRX.c


示例17: driveAhead

/** driveAhead ************************************************************
 * Drive Ahead to the specified distance given in inches
 * @params distance -- the distance in inches
 * ***********************************************************************/
void driveAhead(double distance) {
	// motors forward for some time
	set_motors(SPEED, SPEED);
	delay_ms(WAIT_PER_INCH * distance);
	set_motors(0,0);
	// pause for a fraction of a second before continuing to smooth out the run
	delay_ms(250);
}
开发者ID:MitMaro,项目名称:MUN-School-Work,代码行数:12,代码来源:assign2.cpp


示例18: turn_right

void turn_right(int power, int angle)
{
	int delay = (DELAY_PER_ANGLE_PER_POWER * angle)/power;

	set_motors(power,-power);
	delay_ms(delay);
	set_motors(0,0);
}
开发者ID:SauvikRay,项目名称:pi-robot,代码行数:8,代码来源:bomb-squad.c


示例19: correctToStraight

void correctToStraight(int motorSpeed) {
	if (get_side_ir_dist(LEFT) < 15) {
		set_motors(motorSpeed + 3, motorSpeed);
	}
	if (get_side_ir_dist(RIGHT) < 15) {
		set_motors(motorSpeed, motorSpeed + 3);
	}
}
开发者ID:HappiApi,项目名称:Pair22,代码行数:8,代码来源:turn.c


示例20: main

// This is the main function, where the code starts.  All C programs
// must have a main() function defined somewhere.
int main()
{
	unsigned int sensors[5]; // an array to hold sensor values

	// set up the 3pi
	initialize();

	// This is the "main loop" - it will run forever.
	while(1)
	{
		// Get the position of the line.  Note that we *must* provide
		// the "sensors" argument to read_line() here, even though we
		// are not interested in the individual sensor readings.
		unsigned int position = read_line(sensors,IR_EMITTERS_ON);

		if(position < 1000)
		{
			// We are far to the right of the line: turn left.

			// Set the right motor to 100 and the left motor to zero,
			// to do a sharp turn to the left.  Note that the maximum
			// value of either motor speed is 255, so we are driving
			// it at just about 40% of the max.
			set_motors(0,100);

			// Just for fun, indicate the direction we are turning on
			// the LEDs.
			left_led(1);
			right_led(0);
		}
		else if(position < 3000)
		{
			// We are somewhat close to being centered on the line:
			// drive straight.
			set_motors(100,100);
			left_led(1);
			right_led(1);
		}
		else
		{
			// We are far to the left of the line: turn right.
			set_motors(100,0);
			left_led(0);
			right_led(1);
		}
	}

	// This part of the code is never reached.  A robot should
	// never reach the end of its program, or unpredictable behavior
	// will result as random code starts getting executed.  If you
	// really want to stop all actions at some point, set your motors
	// to 0,0 and run the following command to loop forever:
	//
	// while(1);
}
开发者ID:Chen-Zhe,项目名称:MDP-Grp2,代码行数:57,代码来源:test.c



注:本文中的set_motors函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ set_name函数代码示例发布时间:2022-05-30
下一篇:
C++ set_mode函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap