|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
We wrote a routine in user_routines_fast.c and user_routines.c for autonomous. Here are the definitions in user_routines_fast.c: long Left_Encoder_Count = 0; long Right_Encoder_Count = 0; int lh_encoder_max; unsigned int rh_encoder_max; long int rh_en_count; long int lh_en_count; float target_ratio; float actual_ratio; unsigned char autorun_status = 1; #define lh_en Left_Encoder_Count; #define rh_en Right_Encoder_Count; #define pwm1_lh pwm01 #define pwm2_rh pwm02 int pw2_rhpos; int pw2_rhneg; /* delete all of thse ---- float lh_30turnfactor ; */ int onecnt = 0; /* one tenth of a second counter */ int rhcnt = 0; int lhcnt = 0; int rhcnt1000 = 0; float actual_factor = 0; float rh_adjust_factor = 0; int rh_speed_var = 220; these are the variables in user_routines.c int pwadd = 0; int pwadd2 = 0; char heat = 'c'; unsigned float pwadd3 = 300; int pwadd4 = 0; int p1xvar2; int p1yvar2; int p1xcoef = 150; /*max no =100 50 takes 14 scans to catch up*/ int p1ycoef = 150; /*con 100 takes 6 scans to catch up 150 = 5 SCANS*/ int p1yfl; /* p1x filter */ int p1xfl; /* p1y filter */ float lh_30turnfactor ; int onecnt = 0; /* one tenth of a second counter */ int rhcnt = 0; int lhcnt = 0; int rhcnt1000 = 0; float actual_factor = 0; float rh_adjust_factor = 0; int rh_speed_var = 220; float pwadd5 = 1; int pwadd6 = 0; rom const char *StrPtr = "Hello world!"; /* int x = 15; *int y = 0x50; *long z = 0xdeadface; */ extern long Left_Encoder_Count; /* tm 226 see these in fast.c*/ #define lenco Left_Encoder_Count extern long Right_Encoder_Count; /* tm 226 see these in fast.c*/ #define renco Right_Encoder_Count #define Deadband 15 #define DriveFilter .3 #define p1_x_right p1_x #define p1_y_fwd p1_y #define p1_sw_trig_plow_out p1_sw_trig #define p1_sw_top_plow_in p1_sw_top /*p1_wheel p1_sw_aux1 p1_sw_aux2 */ #define p2_x_winch p2_x #define p2_y_mast_fwd p2_y #define p2_wheel_mast_up p2_wheel #define p2sw_trig_claw_sov p2_sw_trig #define p2sw_top_unclaw_sov p2_sw_top #define p2_sw_aux1_compr_on p2_sw_aux1 #define p2_sw_aux2_compr_off p2_sw_aux2 #define p3_x_right p3_x #define p3_y_fwd p3_y #define rl1a_mast_back_sov relay1_fwd #define rl1b_claw_sov relay1_rev /* 2/18/04 */ #define rl2a_plow_mtr relay2_fwd #define rl2b_plow_mtr relay2_rev #define rl3a_winch_mtr relay3_fwd #define rl3b_winch_mtr relay3_rev #define rl4a_compresr relay4_fwd #define rl5a_mast_mtr relay5_fwd #define rl5b_mast_mtr relay5_rev #define rc_din2_lh_sw rc_dig_in02 #define rc_din3_rh_sw rc_dig_in03 #define rc_din4_plow_out_ls rc_dig_in04 #define rc_din15_plow_in_ls rc_dig_in15 #define rc_din6_mast_ls_dn rc_dig_in06 #define rc_din7_mast_ls_up rc_dig_in07 #define rc_din11_pres_sw rc_dig_in11 #define pwm1_lh pwm01 #define pwm2_rh pwm02 #define pw3_winch pwm03 #define pw4_mast pwm04 I thought that the variables used in user_routines_fast.c could be defined as "extern" also for use in user_routines.c. At least it did work for these variables: user_routines_fast.c: long Left_Encoder_Count = 0; long Right_Encoder_Count = 0; user_routines.c: extern long Left_Encoder_Count; /* tm 226 see these in fast.c*/ extern long Right_Encoder_Count; /* tm 226 see these in fast.c*/ When we compile we get an error message as shown below: if (autorun_status == 1) /* State 1 - Initialize for straight movement for seven feet fast 5.0 --*/ { pwm1_lh = 127; /* Stop left motor */ pwm2_rh = 127; /* Stop right motor */ rh_en = 0; /* Reset actual encoder count we get an error on this line!!!*/ lh_en = 0; /* Reset actual encoder count */ rh_en_count = 0; /* Reset saved encoder count */ lh_en_count = 0; /* Reset saved encoder count */ rh_encoder_max = 771; /* Initialize max encoder counts for step 1 */ lh_encoder_max = 771; /* Initialize max encoder counts for step 1 */ target_ratio = 1.0; /* 1.0 straight, 1.1 turns left (more rh) .9 turns right */ pwm1_lh = 180; /* Set inital left motor speed */ pwm2_rh = 180; /* Set initial right motor speed */ autorun_status = 2; } /* or send to #3 and try that */ /* State 2 - Maintain target ratio for seven feet */ Sorry, but we cannot see anything wrong with the syntax of rh_en = 0; ?????? I think we need help in defining variables used in user_routines_fast.c versus those used in user_routines.c. Thanks to anyone who can help!! David Bryan 818 |
|
#2
|
|||||
|
|||||
|
Re: Need help with Variables ?
First of all, use the [code ] tag (no space). So it looks like this:
user_routines_fast.c: Code:
long Left_Encoder_Count = 0; long Right_Encoder_Count = 0; int lh_encoder_max; unsigned int rh_encoder_max; long int rh_en_count; long int lh_en_count; float target_ratio; float actual_ratio; unsigned char autorun_status = 1; #define lh_en Left_Encoder_Count; #define rh_en Right_Encoder_Count; #define pwm1_lh pwm01 #define pwm2_rh pwm02 int pw2_rhpos; int pw2_rhneg; /* delete all of thse ---- float lh_30turnfactor ; */ int onecnt = 0; /* one tenth of a second counter */ int rhcnt = 0; int lhcnt = 0; int rhcnt1000 = 0; float actual_factor = 0; float rh_adjust_factor = 0; int rh_speed_var = 220; user_routines.c Code:
int pwadd = 0;
int pwadd2 = 0;
char heat = 'c';
unsigned float pwadd3 = 300;
int pwadd4 = 0;
int p1xvar2;
int p1yvar2;
int p1xcoef = 150; /*max no =100 50 takes 14 scans to catch up*/
int p1ycoef = 150; /*con 100 takes 6 scans to catch up 150 = 5 SCANS*/
int p1yfl; /* p1x filter */
int p1xfl; /* p1y filter */
float lh_30turnfactor ;
int onecnt = 0; /* one tenth of a second counter */
int rhcnt = 0;
int lhcnt = 0;
int rhcnt1000 = 0;
float actual_factor = 0;
float rh_adjust_factor = 0;
int rh_speed_var = 220;
float pwadd5 = 1;
int pwadd6 = 0;
rom const char *StrPtr = "Hello world!";
/* int x = 15;
*int y = 0x50;
*long z = 0xdeadface; */
extern long Left_Encoder_Count; /* tm 226 see these in fast.c*/
#define lenco Left_Encoder_Count
extern long Right_Encoder_Count; /* tm 226 see these in fast.c*/
#define renco Right_Encoder_Count
#define Deadband 15
#define DriveFilter .3
#define p1_x_right p1_x
#define p1_y_fwd p1_y
#define p1_sw_trig_plow_out p1_sw_trig
#define p1_sw_top_plow_in p1_sw_top
/*p1_wheel p1_sw_aux1
p1_sw_aux2 */
#define p2_x_winch p2_x
#define p2_y_mast_fwd p2_y
#define p2_wheel_mast_up p2_wheel
#define p2sw_trig_claw_sov p2_sw_trig
#define p2sw_top_unclaw_sov p2_sw_top
#define p2_sw_aux1_compr_on p2_sw_aux1
#define p2_sw_aux2_compr_off p2_sw_aux2
#define p3_x_right p3_x
#define p3_y_fwd p3_y
#define rl1a_mast_back_sov relay1_fwd
#define rl1b_claw_sov relay1_rev /* 2/18/04 */
#define rl2a_plow_mtr relay2_fwd
#define rl2b_plow_mtr relay2_rev
#define rl3a_winch_mtr relay3_fwd
#define rl3b_winch_mtr relay3_rev
#define rl4a_compresr relay4_fwd
#define rl5a_mast_mtr relay5_fwd
#define rl5b_mast_mtr relay5_rev
#define rc_din2_lh_sw rc_dig_in02
#define rc_din3_rh_sw rc_dig_in03
#define rc_din4_plow_out_ls rc_dig_in04
#define rc_din15_plow_in_ls rc_dig_in15
#define rc_din6_mast_ls_dn rc_dig_in06
#define rc_din7_mast_ls_up rc_dig_in07
#define rc_din11_pres_sw rc_dig_in11
#define pwm1_lh pwm01
#define pwm2_rh pwm02
#define pw3_winch pwm03
#define pw4_mast pwm04
Code:
long Left_Encoder_Count = 0; long Right_Encoder_Count = 0; Code:
extern long Left_Encoder_Count; /* tm 226 see these in fast.c*/ extern long Right_Encoder_Count; /* tm 226 see these in fast.c*/ Code:
if (autorun_status == 1)
/* State 1 - Initialize for straight movement for seven feet fast 5.0 --*/
{
pwm1_lh = 127; /* Stop left motor */
pwm2_rh = 127; /* Stop right motor */
rh_en = 0; /* Reset actual encoder count we get an error on this line!!!*/
lh_en = 0; /* Reset actual encoder count */
rh_en_count = 0; /* Reset saved encoder count */
lh_en_count = 0; /* Reset saved encoder count */
rh_encoder_max = 771; /* Initialize max encoder counts for step 1 */
lh_encoder_max = 771; /* Initialize max encoder counts for step 1 */
target_ratio = 1.0; /* 1.0 straight, 1.1 turns left (more rh) .9 turns right */
pwm1_lh = 180; /* Set inital left motor speed */
pwm2_rh = 180; /* Set initial right motor speed */
autorun_status = 2; } /* or send to #3 and try that */
/* State 2 - Maintain target ratio for seven feet */
|
|
#3
|
|||||
|
|||||
|
Re: Need help with Variables ?
What error? What file is it in?
|
|
#4
|
||||
|
||||
|
Re: Need help with Variables ?
Ok, this is how you declare global variables and do definitions... When you do a constant definition, always do it in the header file (always!) do it sepreate from all other variables.
You declare the reg variables at the top of the source file and set them to their starting state if you want. If you want them to be an external you declare them in the H file the same as in the C file, but you add extern in front and DONT set the starting val ex Code:
//blah.c
#include "blah.h"
// our global variables
unsigned int var1 = 3;
signed int var2 = -2;
double var3 = 3.5;
// our types
OMGtype origion;
OMGtype point1;
OMGtype point2[4];
/*also you can have static vars that are not seen publicly. If you want
*you can make a sub that will return them to other source file function
*thingys. You would delcare the function globaly but only delcare the
*var inside the source C file. I wouldnet recomend this method but it
*is an option if you want to have vars that share a name in different
*source files.
*********************/
double Left_Speed; //the static (non-public) var
double Get_Left_Speed(void) { return Left_Speed; }// and then the function
void playwithtypes(void)
{
point1.blah = 3 //this is how we read/write to a structure
point2[0].blah = 4 // this is how we read/write to a structured array
}
Code:
//blah.h
#ifndef _blah_h
#define _blah_h
// defines
#define STATE1 0
#define STATE2 1
#define STATE3 2
#define LEFTMOTOR pwm01
#define RIGHMOTOR pwm02
//declare vars
extern unsigned int var1;
extern unsigned signed int var2;
extern unsinged double var3;
//declare prototype functions
double Get_Left_Speed(void);
void playwithtypes(void);
/* also you can do types which are like variables inside variables
* this is usefull if you have many different variables, all related in
* groupes. Ex coordinates
typedef struct defOMGtype
{
double blah; // for my blah variable
double x; // for my x variable
double y; // for my y variable
double z; // for my z variable
} OMGtype
// now define externals that use the structure
extern OMGtype origion;
extern OMGtype point1;
extern rom OMGtype point2[4] = { // a structured array!
/*if you want to you can define the variables here and set it as a constant
*in the rom
*********/
//blah, x, y, z
{2,3,4,6}, //array element 1 [0] //alway start at zero!
{3,2,5,6}, //array element 2 [1]
{3,5,3,2}, //array element 3 [2]
{3,2,1,0} //array element 4 [3]
}; //remember to end it
#endif
Last edited by Kevin Karan : 23-02-2004 at 08:13. |
|
#5
|
|||||
|
|||||
|
Re: Need help with Variables ?
Just don't include blah.h in blah.c
|
|
#6
|
||||
|
||||
|
Re: Need help with Variables ?
hu? what are you talking about
BTW, you can include the first code and it will automaticy exclude the rest ex [code]Last edited by Kevin Karan : 23-02-2004 at 07:56. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Joystick Variables | fred | Programming | 8 | 20-02-2004 10:58 |
| Global Variables, anyone? | Darkman_X000 | Programming | 3 | 05-02-2004 22:11 |
| Simple problem with variables | sear_yoda | Programming | 4 | 05-02-2004 09:12 |
| Help On Coding 2K1 Controller | GregTheGreat | Programming | 9 | 05-12-2003 18:35 |
| VB Program to monitor robot variables | DanL | Programming | 7 | 15-02-2002 22:35 |