Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Autonomous Mode (http://www.chiefdelphi.com/forums/showthread.php?t=52869)

Mark McLeod 29-01-2007 08:21

Re: Autonomous Mode
 
Those two extra lines will make the joystick mixing act as if the motors are not reversed and are all oriented the same way on the robot.
Based on what you're seeing I'd guess since your motors are reversed, as is the case for the vast majority of our FIRST robots, then the wiring on your Victor(s) for one drive side is reversed (on the motor output side).

You can leave that code in to correct for the reversed wiring job, however, purely as a matter of personal opinion, I consider reversing the meaning of the x and y axis to be poor technique. You can accomplish the same thing without adding confusion by just reversing the p1_x and p1_y terms in the mixing equation.


Quote:

Originally Posted by DylanRoss (Post 567352)
I've had TONS of trouble trying to figure out how their one-joystick drive code works. Our robot won't drive correctly if I take that bit out (because of the way one motor is mounted "backwards"), but in all the testing I do on the computer, the numbers come out way wrong.

Commenting out those two lines shouldn't change anything, should it? Because it keeps me from driving...


Bomberofdoom 29-01-2007 09:26

Re: Autonomous Mode
 
Simply writing our autonumous code will make it work, or do we need to comment/uncomment some part or write some code to make it work?

Mark McLeod 29-01-2007 10:18

Re: Autonomous Mode
 
Quote:

Originally Posted by Bomberofdoom (Post 567421)
Simply writing our autonumous code will make it work, or do we need to comment/uncomment some part or write some code to make it work?

The User_Autonomous_Code() routine is called when you enter autonomous mode and you can just add your own driving code for it to work as it is.
If you are depending on using the camera then you'll need to add camera calls as found in Process_Data_From_Master_uP() to User_Autonomous_Code().

Slick 31-01-2007 08:01

Re: Autonomous Mode
 
Mark we are still having the same problem. I did everything you instructed me to do and the problem still exists. The camera performs perfectly when we use Kevin’s default 2.1 code with nothing added. Starting from scratch: If I put my code in the Autonomous loop where the code tells us to place it, the camera will not track anymore when we use the dongle and try to enter autonomous mode. The camera seems to go to a home position and stop.
Example:
void User_Autonomous_Code(void)
{
/* Initialize all PWMs and Relays when entering Autonomous mode, or else it
will be stuck with the last values mapped from the joysticks. Remember,
even when Disabled it is reading inputs from the Operator Interface.
*/
pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;
relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;
relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;
relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;
relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;

while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */

/* Add your own autonomous code here. */
if(Get_Tracking_State() == TARGET_IN_VIEW) /* make sure camera is tracking */
{
if(((((int)PAN_SERVO - 124) * 65)/124) > 20) /* check current pan servo position. 0 > is right, 0 < is left */
{
pwm15 = 167; /* do a left turn */
pwm13 = 87;
}
else if(((((int)PAN_SERVO - 124) * 65)/124) < -20)
{
pwm15 = 87; /* do a right turn */
pwm13 = 167;
}
else
{
pwm13 = 167;
pwm15 = 167;
}

Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}

If I take out everything but my code in the Autonomous loop the camera will work fine and the robot will respond when we enter autonomous mode (everything is perfect), but when we exit autonomous mode the drives (wheels) will start running wildly and the joysticks will not work.
Example:
void User_Autonomous_Code(void)
{
if(Get_Tracking_State() == TARGET_IN_VIEW) /* make sure camera is tracking */
{
if(((((int)PAN_SERVO - 124) * 65)/124) > 20) /* check current pan servo position. 0 > is right, 0 < is left */
{
pwm15 = 167; /* do a left turn */
pwm13 = 87;
}
else if(((((int)PAN_SERVO - 124) * 65)/124) < -20)
{
pwm15 = 87; /* do a right turn */
pwm13 = 167;
}
else
{
pwm13 = 167;
pwm15 = 167;
}
}

}

What am I missing???? Thanks for your help….

Mark McLeod 31-01-2007 08:55

Re: Autonomous Mode
 
I'm restating my answer to more directly address your two examples.

In your first example I'm sure you've noticed that the Autonomous routine runs instead of the main loop where the camera operational functions are called in Process_Data_From_Master_uP(). "while (autonomous_mode) " keeps the code from going back to main() until autonomous_mode is over.

So your normal camera operation calls are no longer being made when you flip the dongle switch.

To make the first example work you'll have to modify the Autonomous routine by copying the camera calls from Process_Data_From_Master_uP() to your Autonomous routine. e.g.,
Camera_Handler();
Servo_Track();

and optionally for feedback:
Tracking_Info_Terminal();
if(Get_Tracking_State() == CAMERA_ON_TARGET)
{
Switch3_LED = 1;
}
else
{
Switch3_LED = 0;
}

You can also accomplish the same thing by calling Process_Data_From_Master_uP() inside your autonomous loop - just be sure it's called BEFORE you set your pwm outputs since the buried call to Default_Routine() would override your pwm values.
------------------------------------
Your second example is a valid approach as well (it's how I tend to do it).
Have you modified main() at all?

Removing the "while (autonomous_mode) " loop and the Getdata/Putdata calls as you did, so you always return to main(), allows Process_Data_From_Master_uP() to be called as it normally is.

If you walk through the sequence of how things are called you've probably seen that Default_Routine() will get called before the Autonomous routine. So if you haven't modified main() while in autonomous mode you are setting the motors based on the joysticks then overriding those settings with the subsequent call to User_Autonomous_Code().

It's a little dangerous to call both Default_Routine() and User_Autonomous_Code(). If you don't set EVERY output in the last routine called you can end up with quite a mixed bag of outputs. I'd redesign it to call one or the other, not both, by pulling the call to Default_Routine() out of Process_Data_From_Master_uP() and using an "if else" to get either Default_Routine() or User_Autonomous_Code().

After leaving autonomous mode you should just stop overriding the pwm outputs, so something else is happening.
I suspect main() with no other evidence.

Slick 31-01-2007 09:20

Re: Autonomous Mode
 
I agree. I prefer to do it the second way. But if I use this method, how do I get the joysticks to respond after autonomous mode????

After reading your response again I will try a few things.... Thanks....

LieAfterLie 01-02-2007 15:02

Re: Autonomous Mode
 
I know I'm a little late but pan is pwm 1 and tilt is pwm 2. Forgive me if I missed the answer to this already.

This came from Kevin's 2.1 Bells and Whistles camera code, tracking.h:

Code:

// By default, PWM output one is used for the pan servo.
// Change it to another value if you'd like to use PWM
// output one for another purpose.
#define PAN_SERVO pwm01

// By default, PWM output two is used for the tilt servo.
// Change it to another value if you'd like to use PWM
// output two for another purpose.
#define TILT_SERVO pwm02


ace123 01-02-2007 19:26

Re: Autonomous Mode
 
Are you sure you copied the three camera functions that are in Proces_Data_From_Master_uP()?

You should add these three functions inside the loop in your User_Autonomous_Code():
Code:

        Tracking_Info_Terminal();
        Camera_Handler();
        Servo_Track();


        if(Get_Tracking_State() == CAMERA_ON_TARGET)
        {
                Switch3_LED = 1;
        }
        else
        {
                Switch3_LED = 0;
        }

The Switch3 LED thing after that will give you feedback if the robot is seeing anything. You might want it as well.

Anyway, this should fix your problem.
__

Another problem is that your code uses Generate_Pwms() instead of the new PWM() function.

See: http://chiefdelphi.com/forums/showthread.php?t=53211

If you are indeed using the 2.1 Kevin code, you might have to replace "Generate_Pwms(pwm13,pwm14,pwm15,pwm16);" with "PWM(pwm13,pwm14,pwm15,pwm16)".

You also might have to #include "pwm.h" at the top of the file.


All times are GMT -5. The time now is 23:51.

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