Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Code problems (http://www.chiefdelphi.com/forums/showthread.php?t=34688)

doyler 15-02-2005 11:32

Code problems
 
1 Attachment(s)
I just uploaded my code and ended up with a few problems

1)When I hold the trigger on the right joystick (p1) the robot decideds to turn in a circle (1 wheel forwards and the other backwards)

2)When I go full on with p1 it ends up overlapping and going in reverse

3)There is rhythmic pulsing coming from the pwms (i hooked up a servo and it kept moving without any joystick interaction)

here is my user_routines.c file

Alan Anderson 15-02-2005 12:03

Re: Code problems
 
Quote:

Originally Posted by doyler
2)When I go full on with p1 it ends up overlapping and going in reverse

Joystick maximum is 254. Your code does something with the joystick value to get a number from 0 to 127. Your lookup array only goes to 126, so you're falling off the edge and picking up an undefined result. Make your table bigger by one. You might also consider initializing it as part of its declaration rather than having a whole bunch of code in a function to do it.
Code:

static char lookup[128] = (0,0,0,0,0,0,1,1,2,2,2,3,4,4...);
Quote:

3)There is rhythmic pulsing coming from the pwms (i hooked up a servo and it kept moving without any joystick interaction)
You're using pwms 13-16. They are generated by the RC user processor. When other interrupts are being used in the system, the pwm outputs jitter. Change to other pwm outputs, which are generated by the master processor and are not subject to the same interference.

Dave Scheck 15-02-2005 12:14

Re: Code problems
 
1) Are your motors wired correctly? If you uncomment the code at lines 401-2 does it behave as you would expect? If so, there's a software problem that needs looking into...If not, and it turns in circles, tip it up on end and note which motor(s) are driving the wrong direction. Reverse the motor wires at the M+ M- terminals of the speed controller.

2) One problem that I see is that what happens if p1_y == 254 (i.e. full forward)? Following your code, dist would equal 1, making dist = 254-127...which is 127. You then use dist in your lookup table, however, you don't have an entry for 127...you when you go full reverse (p1_y == 0).

3) Not sure about this one...It may be an issue with using pwm13-16...Is there a reason that you are using pwm13-16 other than the fact that you're electrically connected there? If not, I would suggest that you relocate that functionality to any unused pwm1-12 that you have. The reasoning is described in this thread. I can't guarantee that that's your problem there, but it may help.


<EDIT> Looks like Alan responded while I was typing...</EDIT>

doyler 15-02-2005 12:17

Re: Code problems
 
So could I just add this at the end?

lookup[127]=127;

and how would your array work, and why does it go to 128

-------

But the motors are doing the thing that the servos are

[edit]

The trigger is not supposed to make it do anything other then track

[/edit]

Dave Scheck 15-02-2005 14:46

Re: Code problems
 
Quote:

Originally Posted by doyler
So could I just add this at the end?
lookup[127]=127;

Sure
Quote:

and how would your array work
Not sure what you mean by that one...
Quote:

and why does it go to 128
The reason that you need to declare the array to size 128 is that array indecies C is zero-based. You want an index range of 0-127 (128 elements), therefore the size should be 128.

Quote:

The trigger is not supposed to make it do anything other then track
I just reread your original question...If the trigger is pressed you set p1_y = speed_control at line 384...but you never initialize speed_control. you go on to use p1_y in the Limit_Mix call on line 396 to set your outputs. So at that point, who knows what the y component of your output is going to be. If it happens to be in the speed controller deadbane (117-137 I think), you will get no forward motion. This could be why it spins.
I see a const int called speed_setting at line 46...did you mean to use this instead?

On a programming side note, the const ints steering_comp and speed_setting would be better written as
Code:

#define STEERING_COMP 30
#define SPEED_SETTING 150

You can put this in user_routines.h. Doing so will save you the size of two ints as well as a few program cycles of having to retrieve the values out of memory. Doesn't seem like a whole lot, but over time things like this add up and pretty soon you're out of space. Its better to get in the habit now so that you don't have to go back later and re-do it if you run into problems.

doyler 15-02-2005 15:42

Re: Code problems
 
When i tried to put
#define STEERING_COMP 30 //steering compenstation (0 to 127)
#define SPEED_SETTING 150 //forward speed setting (127 to 254)

in user_routines.h I was getting compiler errors that steering_comp wasn't defined

Dave Scheck 15-02-2005 15:47

Re: Code problems
 
Quote:

Originally Posted by doyler
When i tried to put
#define STEERING_COMP 30 //steering compenstation (0 to 127)
#define SPEED_SETTING 150 //forward speed setting (127 to 254)

in user_routines.h I was getting compiler errors that steering_comp wasn't defined

You also need to update your user_routines.c to replace all instances steering_comp with STEERING_COMP. C is case sensitive so they are not the same. By most conventions, constants are in all capitals so that they stand out.

doyler 15-02-2005 15:52

Re: Code problems
 
why would this give me a syntax error?

(this is in user_routines_fast)

Code:

if (SPEED_SETTING < 128 || speed_control > 254)        //Check speed_setting for valid forward speed
        SPEED_SETTING = 150;                                                //If not valid number set to default


Dave Scheck 15-02-2005 15:56

Re: Code problems
 
Quote:

Originally Posted by doyler
why would this give me a syntax error?

Code:

if (SPEED_SETTING < 128 || speed_control > 254)        //Check speed_setting for valid forward speed
        SPEED_SETTING = 150;                                                //If not valid number set to default


Don't you mean SPEED_SETTING > 254 instead of speed_control?

<EDIT>Disregard this post...don't know what I was thinking, but this won't help at all :o </EDIT>

AIBob 15-02-2005 15:58

Re: Code problems
 
Code:

#define SPEED_SETTING 150 //forward speed setting (127 to 254)
Code:

if (SPEED_SETTING < 128 || speed_control > 254) //Check speed_setting for valid forward speed
SPEED_SETTING = 150; //If not valid number set to default

You defined SPEED_SETTING as a constant, I believe you can not set a defined constant after you are running the code, also as noted by someone else before, C is case sensative.

Errors in your code I marked in red.

doyler 15-02-2005 16:02

Re: Code problems
 
1 Attachment(s)
I don't think it should be a constant

This is my user_routines*

Dave Scheck 15-02-2005 16:02

Re: Code problems
 
Quote:

Originally Posted by AIBob
you defined SPEED_SETTING as a constant, I believe you can not set a defined constant after you are running the code

Good catch Bob, I overlooked that.

AIBob 15-02-2005 16:07

Re: Code problems
 
Quote:

Originally Posted by doyler
I don't think it should be a constant

It shouldn't, but this is in your code:
user_routines.h:
Code:

#define SPEED_SETTING 150 //forward speed setting (127 to 254)
Which defines them as constants in C.

Quote:

Originally Posted by Dave Scheck
Good catch Bob, I overlooked that.

That's alright, we all make mistakes, even I do occasionally.

Dave Scheck 15-02-2005 16:10

Re: Code problems
 
I think this is what you are trying to do in user_routines_fast_DDT.c.

Code:

if(speed_control < 128 || speed_control > 254)
    speed_control = SPEED_SETTING ;


doyler 15-02-2005 16:23

Re: Code problems
 
Where would I put compressor code this year, last year it was in relayControl() in user_routines.c?

Also, why would i still be getting the jumps

How would I stop my trigger from doing stuff


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

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