View unanswered posts | View active topics It is currently Tue Sep 23, 2014 7:13 am






Reply to topic  [ 4 posts ] 
Autonomous turning problem 
Author Message
Rookie

Joined: Wed Nov 16, 2011 11:34 pm
Posts: 4
Post Autonomous turning problem
Hello! I've been programming our robot's autonomous today and I've found a weird problem. The robot goes down the ramp, but when it tries to turn, it slows to a stop and makes a buzzing noise; argh, not good! So, I was wondering, does there seem to be anything wrong with this code?

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  none)
#pragma config(Motor,  mtr_S1_C1_1,     motor_belt,    tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     motor_left,    tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     motor_right,   tmotorNormal, PIDControl, reversed, encoder)
#pragma config(Servo,  srvo_S1_C3_1,    right_arm_x,          tServoStandard)
#pragma config(Servo,  srvo_S1_C3_2,    right_arm_y,          tServoStandard)
#pragma config(Servo,  srvo_S1_C3_5,    left_arm_y,           tServoStandard)
#pragma config(Servo,  srvo_S1_C3_6,    left_arm_x,           tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// TURNING
// 90 degree turn = 1720
// 180 degree turn = 3450... yeah, I don't know either.

// SERVOS
// Servo 1: right_arm_x
// Servo 2: right_arm_y
// Servo 5: left_arm_y
// Servo 6: left_arm_x


task main()

{


 
//Go down ramp.

  nMotorEncoder[motor_left] = 0;
  nMotorEncoder[motor_right] = 0;

  wait1Msec(100);
 
  nMotorEncoderTarget[motor_left] = 5600;
  nMotorEncoderTarget[motor_right] = 5600;


  motor[motor_left] = -75;
  motor[motor_right] = -75;

  while(nMotorRunState[motor_right] != runStateIdle)
   {

   }

  motor[motor_left] = 0;
  motor[motor_right] = 0;


// Turn right.

  nMotorEncoder[motor_left] = 0;
  nMotorEncoder[motor_right] = 0;

  wait1Msec(100);
 
  nMotorEncoderTarget[motor_left] = 2150;
  nMotorEncoderTarget[motor_right] = 2150;


  motor[motor_left] = 75;
  motor[motor_right] = -75;

  while(nMotorRunState[motor_right] != runStateIdle)
   {

   }

  motor[motor_left] = 0;
  motor[motor_right] = 0;

 
   
// Push bowling ball.
 
  nMotorEncoder[motor_left] = 0;
  nMotorEncoder[motor_right] = 0;

  wait1Msec(100);
 
  nMotorEncoderTarget[motor_left] = 8000;
  nMotorEncoderTarget[motor_right] = 8000;


  motor[motor_left] = -25;
  motor[motor_right] = -25;

  while(nMotorRunState[motor_right] != runStateIdle)
   {

   }

  motor[motor_left] = 0;
  motor[motor_right] = 0;


}


Thu Nov 17, 2011 12:11 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Autonomous turning problem
Lets take a look at this part of your code here:
Code:
// Turn right.

  nMotorEncoder[motor_left] = 0;
  nMotorEncoder[motor_right] = 0;

  wait1Msec(100);
 
  nMotorEncoderTarget[motor_left] = 2150;
  nMotorEncoderTarget[motor_right] = 2150;


  motor[motor_left] = 75;
  motor[motor_right] = -75;

  while(nMotorRunState[motor_right] != runStateIdle)
   {

   }

  motor[motor_left] = 0;
  motor[motor_right] = 0;


When a motor spins backwards, the encoder will count backwards. You have told both motors to go to the encoder value 2150, but one of them is running backwards away from the encoder value. I'm guessing that the PID algorithm isn't too happy with this.

_________________
sudo rm -rf /


Thu Nov 17, 2011 12:33 am
Profile
Rookie

Joined: Wed Nov 16, 2011 11:34 pm
Posts: 4
Post Re: Autonomous turning problem
Oh, wow, that makes perfect sense! Thank you very much! :D


Thu Nov 17, 2011 12:47 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Autonomous turning problem
You're very welcome.

_________________
sudo rm -rf /


Thu Nov 17, 2011 1:15 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.