View unanswered posts | View active topics It is currently Sat Nov 01, 2014 8:37 am






Reply to topic  [ 2 posts ] 
Autonmous Question 
Author Message
Rookie

Joined: Sun Jan 13, 2013 11:04 pm
Posts: 1
Post 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;
    }
}

}


Sun Jan 13, 2013 11:09 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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.


Sun Jan 13, 2013 11:32 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.