Tuesday, February 3, 2015

February 3, 2015

Overview:

Following yesterday's runs where Magellan would not find the cone, today, testFindCone.py was made to test the cone finding code specifically in RobotControlBuilder2.py. After tuning, some resolutions were made: 

   -In RobotFunctions.py, line 202-258, the proportional variable for turnpower is now proportionalTurn instead of a hard coded number (which is now 20 instead of 50 previously), and the drive forward when the cone is straight ahead has changed from a non-PID function to a PID function that takes heading every 4 ticks (one rotation). 
   -Some variables were changed (such as turn power) to allow less dramatic turning when moving toward the cone

Currently, testFindCone,py takes in a file, but does not use it. Inputting a file is mostly to prevent code from breaking as various variables have hard coded numbers for testing, such as coneDistance = 20#coneDistance = 6 * abs(superbot.angle_fix( coneDirection, heading ))/180 + 2 [line 139]. Near the end, we had realized that if the robot goes into programming mode at all, many of the settings are reset. An issue when testing for the robot to approach the cone from a couple feet away (in code, it is indicated in print as "print "Went towards cone 10 ft"  " in lines 141 to 149), the robot would not initiate movement unless pushed. This was due to the speed controller being in brushless mode. We tested this hypothesis by running when the robot sees the cone and moves forward, where Magellan exhibited the same behavior. Since Robert, Ariel, and Tommy had to leave for elec10, Andrew stayed behind and reprogrammed the speed controller for tomorrow's use.

To-Do:
    -Fix the getting close to cone from a couple feet away
    -Fine-Tune turn parameters
    -Integrate code from testFineCone to RobotControlBuilder2 afteward
    -Run Full Course


[Previously Mentioned Line 202-258 in RF)
 if (cone_X > robot.width/2 + tolerance):
                #advance right
                coneSeenFlag = True
                direction = True
                turnpower = turn_offset-int(2*(robot.width/2-cone_X)/robot.width*proportionalTurn) + cone_size / 100
                #print "Turn Power",turnpower
                robot.turn(turnpower)
                robot.setDesiredVelocity( conePIDtarget )
                if direction == False:
                    robot.motorPower = 35
                robot.drive( robot.drivePID( ) )
                robot.drive( robot.drivePID( ) ) #For Spooling
                time.sleep( .15 )
                last_visible = "right"
                print 'going right ',turnpower
            #no? well then is it to the left?
            elif (cone_X < robot.width/2 - tolerance):
                #advance left
                coneSeenFlag = True
                direction = True
                turnpower = turn_offset-int(2*(robot.width/2-cone_X)/robot.width*proportionalTurn) + cone_size / 100 
                #print "Turn Power",turnpower
                robot.turn(turnpower)
                robot.setDesiredVelocity( conePIDtarget )
                if direction == False:
                    robot.motorPower = 35
                robot.drive( robot.drivePID( ) )
                robot.drive( robot.drivePID( ) ) #For Spooling
                time.sleep( .15 )
                last_visible = "left"
                print 'going left ',turnpower
            #no? well then is it in the middle?
            elif ((cone_X < robot.width/2 + tolerance)&(cone_X > robot.width/2 - tolerance)):
                #advance straight
heading = robot.modules['imu'].getHeading()
robot.setTarget(heading)
robot.turn( robot.PID( ) ) #Start Turn
                coneSeenFlag = True
                direction = True
                if last_visible == "left":
                    robot.turn(-10)#100 should be 
                elif last_visible == "right":
                    robot.turn(10)#100 should be 10 test
                else:
                    robot.turn(5)#0
                robot.setDesiredVelocity( conePIDtarget )
                if direction == False:
                    robot.motorPower = 35
                for i in range(4):
                        heading = robot.modules['imu'].getHeading()
                        robot.turn( robot.PID( ) ) #Start Turn
                        robot.drive( robot.drivePID( ) )
                        time.sleep( .05 )
                #robot.drive( robot.drivePID( ) ) #For Spooling
                #time.sleep( .15 )
                last_visible = "center"
                print 'going straight'

No comments:

Post a Comment