Go to Post still emotion conveyed through text is really strange. - Blackphantom91 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 05-02-2011, 14:34
will_1359 will_1359 is offline
Registered User
FRC #1359
 
Join Date: Jan 2010
Location: lebanon
Posts: 15
will_1359 is an unknown quantity at this point
Robot going left during autonomous

I'm working on line sensing in autonomous. I've inputted the example code and no matter which sensor is activated when autonomous is running, the robot always spins left, going in circles. When the sensors are not activated, the robot does nothing.

Does anyone have any ideas as to why my robot is spinning left?
Reply With Quote
  #2   Spotlight this post!  
Unread 05-02-2011, 14:36
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: Robot going left during autonomous

are you using an arcade drive or a tank drive.

do you have example code?
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
  #3   Spotlight this post!  
Unread 05-02-2011, 14:42
will_1359 will_1359 is offline
Registered User
FRC #1359
 
Join Date: Jan 2010
Location: lebanon
Posts: 15
will_1359 is an unknown quantity at this point
Re: Robot going left during autonomous

class LineTracker {

RobotDrive drive; // robot drive base object
DigitalInput left; // digital inputs for line tracking sensors
DigitalInput middle;
DigitalInput right;
DriverStation ds; // driver station object for getting selections
double defaultSteeringGain = 0.65; // the default value for the steering gain

public LineTracker(RobotDrive d) {
// create the robot drive and correct for the wheel direction.
//drive = new RobotDrive(1, 2); because having two of these screws everything up
drive = d;


drive.setInvertedMotor(RobotDrive.MotorType.kRearL eft, false);
//drive.setInvertedMotor(RobotDrive.MotorType.kFront Left, true);
//drive.setInvertedMotor(RobotDrive.MotorType.kFront Right, true);
//we have only rear motors
drive.setInvertedMotor(RobotDrive.MotorType.kRearR ight, false);

// set the MotorSafety expiration timer
drive.setExpiration(15);

// create the digital input objects to read from the sensors
left = new DigitalInput(1);
middle = new DigitalInput(2);
right = new DigitalInput(3);

// get the driver station instance to read the digital I/O pins
ds = DriverStation.getInstance();
}

/**
* This function is called once each time the robot enters autonomous mode.
*/
public void run() {
int binaryValue; // a single binary value of the three line tracking
// sensors
int previousValue = 0; // the binary value from the previous loop
double steeringGain; // the amount of steering correction to apply

// the power profiles for the straight and forked robot path. They are
// different to let the robot drive more slowly as the robot approaches
// the fork on the forked line case.


double forkProfile[] = {0.70, 0.70, 0.55, 0.60, 0.60, 0.50, 0.40, 0.00};
double straightProfile[] = {0.7, 0.7, 0.6, 0.6, 0.35, 0.35, 0.35, 0.0};
double powerProfile[]; // the selected power profile

// set the straightLine and left-right variables depending on chosen path
boolean straightLine = ds.getDigitalIn(1);
powerProfile = (straightLine) ? straightProfile : forkProfile;
double stopTime = (straightLine) ? 2.0 : 4.0; // when the robot should look for end
boolean goLeft = !ds.getDigitalIn(2) && !straightLine;
System.out.println("StraightLine: " + straightLine);
System.out.println("GoingLeft: " + goLeft);


boolean atCross = false; // if robot has arrived at end

// time the path over the line
Timer timer = new Timer();
timer.start();
timer.reset();

//int oldTimeInSeconds = -1;
double time;
double speed, turn;

// loop until robot reaches "T" at end or 8 seconds has past
while ((time = timer.get()) < 8.0 && !atCross) {
int timeInSeconds = (int) time;
// read the sensors
int leftValue = left.get() ? 1 : 0;
int middleValue = middle.get() ? 1 : 0;
int rightValue = right.get() ? 1 : 0;
// compute the single value from the 3 sensors. Notice that the bits
// for the outside sensors are flipped depending on left or right
// fork. Also the sign of the steering direction is different for left/right.
if (goLeft) {
binaryValue = leftValue * 4 + middleValue * 2 + rightValue;
steeringGain = -defaultSteeringGain;
} else {
binaryValue = rightValue * 4 + middleValue * 2 + leftValue;
steeringGain = defaultSteeringGain;
}

// get the default speed and turn rate at this time
speed = powerProfile[timeInSeconds];
turn = 0;

// different cases for different line tracking sensor readings
switch (binaryValue) {
case 1: // on line edge
turn = 0;
break;
case 7: // all sensors on (maybe at cross)
if (time > stopTime) {
atCross = true;
speed = 0;
}
break;
case 0: // all sensors off
if (previousValue == 0 || previousValue == 1) {
turn = steeringGain;
} else {
turn = -steeringGain;
}
break;
default: // all other cases
turn = -steeringGain;
}
// print current status for debugging
if (binaryValue != previousValue) {
System.out.println("Time: " + time + " Sensor: " + binaryValue + " speed: " + speed + " turn: " + turn + " atCross: " + atCross);
}

// set the robot speed and direction
drive.arcadeDrive(speed, turn);

if (binaryValue != 0) {
previousValue = binaryValue;
}
//oldTimeInSeconds = timeInSeconds;

Timer.delay(0.01);
}
// Done with loop - stop the robot. Robot ought to be at the end of the line.
drive.arcadeDrive(0, 0);
}
}
Reply With Quote
  #4   Spotlight this post!  
Unread 05-02-2011, 16:46
kinganu123 kinganu123 is offline
Registered User
FRC #1747
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Piscataway, NJ
Posts: 243
kinganu123 is on a distinguished road
Re: Robot going left during autonomous

You may need to invert your motors
I suggest you write your own code using truth tables
__________________
Reply With Quote
  #5   Spotlight this post!  
Unread 05-02-2011, 19:10
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: Robot going left during autonomous

what are you seeing for output on speed values?

// get the default speed and turn rate at this time
speed = powerProfile[timeInSeconds];

this is the only code where it is set.
try making it a static rather than an array like this.
start simple. then get more complicated.

I am guessing that it is 0. That would explain your spinning. Either that or your one motor may not be initialized correctly (1,2) may not be the right ports. or it may we wired correctly.
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
  #6   Spotlight this post!  
Unread 11-02-2011, 18:52
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: Robot going left during autonomous

My team is still having this same problem. We calibrated sensors and tried lineskier's fix, but that didn't do anything either.

Anyone else have any more suggestions?
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
Reply With Quote
  #7   Spotlight this post!  
Unread 11-02-2011, 19:06
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: Robot going left during autonomous

If you are both using line trackers, I'm guessing you're never seeing atcross
so you never leave the line tracker code. It has something to do with the line tracking code. Basically once you are at target, you should never enter the line track loop again. It sounds like you are either reentering it or never leaving it.

If you have a camera you could use it to simple confirm your at target, rather than the cross. This will let you set the distance to target based on your arm or lift. rather than the fixed point the field gives you.
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
  #8   Spotlight this post!  
Unread 11-02-2011, 20:45
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: Robot going left during autonomous

Never mind, we fixed it with our own code.

Code:
DigitalInput left, middle, right;
left = new DigitalInput(1);
middle = new DigitalInput(2);
right = new DigitalInput(3);

public void autonomous() {
    while(isAutonomous()) {
        if(left.get()) {
            // drive code to turn right.
        } else if(middle.get()) {
            // drive code to go straight.
        } else if(right.get()) {
            // drive code to turn left.
        }
    }
}
or something like that. It was pretty simple, now that I think about it.
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:03.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi