ROBOTC.net forums
http://robotc.net/forums/

Autonmous Question
http://robotc.net/forums/viewtopic.php?f=1&t=5358
Page 1 of 1

Author:  44tom44 [ Sun Jan 13, 2013 11:09 pm ]
Post subject:  Autonmous Question

Would someone be able to take a look at my code? For some reason in autonomous, it will just keep going straight when I do a forward motion w/encoders and run in a continuous loop. Whenever I do a turning motion, it does fine and stops where needed. Not sure why it "freezes" when it goes straight.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S3,     lightSensor,    sensorLightInactive)
#pragma config(Motor,  motorA,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  motorB,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  mtr_S1_C1_1,     LeftDrive,     tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     RightDrive,    tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C2_1,     Base1,         tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     Base2,         tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     Top,           tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     motorI,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    LWrist,               tServoStandard)
#pragma config(Servo,  srvo_S1_C4_2,    RWrist,               tServoStandard)
#pragma config(Servo,  srvo_S1_C4_3,    Ramp,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C4_4,    Stop,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C4_5,    AutoWrist,            tServoStandard)
#pragma config(Servo,  srvo_S1_C4_6,    AutoArm,              tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

void initializeRobot()
{

  servoTarget[LWrist] = 230;
  servoTarget[RWrist] = 0;
  servoTarget[AutoArm] = 0;
  servoTarget[AutoWrist] = 120;
  servoTarget[Stop] = 0;
  servoTarget[Ramp] = 245;
  wait1Msec(200);
}

task main()
{
   initializeRobot();

waitForStart();
{
 servo[AutoArm] = 140;
 wait1Msec(900);
}{
 servo[AutoArm] = 70;
 wait1Msec(900);
}{
 servo[AutoWrist] = 0;
 wait1Msec(900);
}{
 servo[AutoArm] = 10;
 wait1Msec(500);
}

nMotorEncoder[LeftDrive] = 0;
nMotorEncoder[RightDrive] = 0;

while (true)
{
    if ((nMotorEncoder[LeftDrive] + nMotorEncoder[RightDrive])/2 < 500)
    {
        motor[LeftDrive] = -50;
        motor[RightDrive] = 50;
    }
    else
    {
        motor[LeftDrive] = 0;
        motor[RightDrive] = 0;
    }
}

}

Author:  MHTS [ Sun Jan 13, 2013 11:32 pm ]
Post subject:  Re: Autonmous Question

Is this code supposed to be going straight or turning?
Code:
while (true)
{
    if ((nMotorEncoder[LeftDrive] + nMotorEncoder[RightDrive])/2 < 500)
    {
        motor[LeftDrive] = -50;
        motor[RightDrive] = 50;
    }
    else
    {
        motor[LeftDrive] = 0;
        motor[RightDrive] = 0;
    }
}

If that's supposed to go straight, then you should correct the motor polarity by adding "reversed" to the leftDrive motor pragma and change the -50 value to 50 instead. What happened was that your left motor encoder is decreasing and your right motor encoder is increasing and when you add them together they cancel each other out so the summed value is probably not going up. So the code will run forever.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/