Go to Post I don't get what all you people have done wrong to make the drills have so many problems. - Cory [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-09-2005, 06:37
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Array problems( i think....)

The reason (as someone sort of mentioned) that you're getting the code error is because it never calls the master_up function. (Sorry, don't remember the exact name.) If the master processor doesn't hear from your code (through that function) at least every 26 ms, it stops running the code and alerts you to a problem with the code error light.

Code:
pwm01,pwm02=127
Just to clear this up, the comma operator is valid C, however, all it does it does is create a sort of "soft" semicolon that allows you to put in a new command, but not actually end the current one. It's a little confusing, but the context you see it most often in is for loops. IE:
Code:
for(i = 0, j = 2; i < someArray[j]; i++, j++)
{
}
Overall, you don't need to use it. As a couple people said,
Code:
pwm0 = pwm02 = 127;
is what you actually want.

Good luck on this!

--EDIT--
Sorry, that was the best explaination for the comma operator I could come up with on the fly. Computer science majors, don't shoot me!
__________________


Last edited by Ryan M. : 22-09-2005 at 06:40.
  #2   Spotlight this post!  
Unread 22-09-2005, 07:12
Andrew Blair's Avatar
Andrew Blair Andrew Blair is offline
SAE Formula is FIRST with Gasoline.
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry
Posts: 1,193
Andrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond repute
Send a message via AIM to Andrew Blair Send a message via Yahoo to Andrew Blair
Re: Array problems( i think....)

Thanks so much! I'll try it out this morning and see i i can get it to work. And I promise, no more commas!
__________________
Reading makes a full man, conference a ready man, and writing an exact man.
-Sir Francis Bacon

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
-Albert Einstein
  #3   Spotlight this post!  
Unread 22-09-2005, 07:46
Andrew Blair's Avatar
Andrew Blair Andrew Blair is offline
SAE Formula is FIRST with Gasoline.
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry
Posts: 1,193
Andrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond repute
Send a message via AIM to Andrew Blair Send a message via Yahoo to Andrew Blair
Re: Array problems( i think....)

Well, i've fixed what has been advised, an it compiles and runs. I now have no code error and can drive in the record/replay mode, but it does not seem to be recording. Reason I know, it does not replay! Any suggestions? Thanks again!
__________________
Reading makes a full man, conference a ready man, and writing an exact man.
-Sir Francis Bacon

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
-Albert Einstein
  #4   Spotlight this post!  
Unread 22-09-2005, 08:41
foobert foobert is offline
Registered User
no team
 
Join Date: May 2005
Location: oakland, ca
Posts: 87
foobert is a jewel in the roughfoobert is a jewel in the roughfoobert is a jewel in the rough
Re: Array problems( i think....)

i know this isn't the problem you're currently working on, but it will be soon.

in your replay code at the end of the while loop i will be 90. the if statement that follows will fail because i will not be greater than 90, so your pwm will stay at the last recorded value and you bot will keep running. very bad.

there is no need for a conditional at all, since when the loop stops you want the robot to stop.
  #5   Spotlight this post!  
Unread 22-09-2005, 11:16
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Array problems( i think....)

Andrew

You need to remember that, by default, the software in your robot controller will only read the joysticks once per loop (Getdata in Process_Data_From_Master_uP).
Same goes for outputting pwm values (Generate_Pwms in Process_Data_From_Master_up).
<Slightly off topic>For reference, the only thing that you're able to read and be assured that it's the current value is the digital inputs because their software representation is tied directly to the pin</Slightly off topic>

I think is what you really want to do is the following....
<disclaimer>This code purposely has some small syntax errors to force the reader to actually understand the code. None of them will affect the program flow, they will just cause compilation errors.</disclaimer>
Code:
// In a header that user_routines.c can see
// It is a good habit to get into to create defines for your
// inputs and outputs.  That allows the programmer to write code
// with arbitrary mappings until the interface is finalized.  Also
// if all of a sudden you want to record with port 3 top, you only
// have to change it in one place in the #define
// Also notice that I assigned meaningful names to the pwms, and constants
#define record_button p2_sw_trig
#define playback_button p1_sw_trig
#define LEFT_DRIVE_STICK  p1_y;
#define RIGHT_DRIVE_STICK  p2_y;
#define LEFT_DRIVE_MOTOR  pwm01;
#define RIGHT_DRIVE_MOTOR  pwm02;
#define N_SAMPLES 90
#define PRESSED 1
#define NOT_PRESSED 0

//In your slow loop (Process_Data_From_Master_uP) 
// Use static variables so that they hold their value
// between loops
static int sample_num = 0
static unsigned char left_side[N_SAMPLES]
static unsigned char right_side[N_SAMPLES]
static unsigned char prev_record_button = NOT_PRESSED
static unsigned char prev_playback_button = NOT_PRESSED

// Temp variable
int temp;

// This takes into consideration the case that both buttons are pressed.  
// You will probably also need some sort of reset signal to clear the recorded values.  I have made the assumption that every time the buttons are pressed
// they will be reset
if(record_button == PRESSED and playback_button == NOT_PRESSED)
{
  if(prev_record_button == NOT_PRESSED)
  {
   //We are just starting to press the button
   // Clear the recorded values
    for(temp = 0; temp < N_SAMPLES)
    {
      left_side[sample_num] = 127
      right_side[sample_num] = 127
    }
    // Reset the sample number
    sample_num = 0;
  }

  if(sample_num < N_SAMPLES)
  {
    // Record the current states
    left_side[sample_num] = LEFT_DRIVE_STICK
    right_side[sample_num] = RIGHT_DRIVE_STICK
  }
  sample_num++
}

if(playback_button == PRESSED and record_button == NOT_PRESSED)
{
  if(prev_playback_button == NOT_PRESSED)
  {
    // We are just starting playback
    sample_num = 0
  }
  if(sample_num < N_SAMPLES)
  {
    // There are more values, use them
    LEFT_DRIVE_MOTOR = left_side[sample_num]
    RIGHT_DRIVE_MOTOR = right_side[sample_num]
  }
  else
  {
    // No more values, hold still
    LEFT_DRIVE_MOTOR = 127
    RIGHT_DRIVE_MOTOR = 127
  }
  sample_num++
}
// Store the previous record state
prev_record_button = record_button;
// Store the previous playback state
prev_playback_button = playback_button;
One other thing that you will want to keep in mind is that 90 samples is equivalent to 90*40ms = 3.6 seconds. You will need to adjust the number of samples to get a good sampling time.

Last edited by Dave Scheck : 22-09-2005 at 19:50. Reason: Did calculation for 26ms loop instead of 40ms
  #6   Spotlight this post!  
Unread 22-09-2005, 19:57
Andrew Blair's Avatar
Andrew Blair Andrew Blair is offline
SAE Formula is FIRST with Gasoline.
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry
Posts: 1,193
Andrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond repute
Send a message via AIM to Andrew Blair Send a message via Yahoo to Andrew Blair
Re: Array problems( i think....)

Wow. Christmas came early this year. Thanks so much Dave! Now all I have to do is fill in the blanks, then on to EEPROM!

By the way, I ran a printf on my increment variable, and for some reason it was not incrementing....I think thats my problem in the original program. I don't seem to have any luck with for loops.....
__________________
Reading makes a full man, conference a ready man, and writing an exact man.
-Sir Francis Bacon

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
-Albert Einstein
Closed Thread


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Problems: Possible<stdio.h> Alex Wijtowych Programming 7 26-01-2005 04:39
Robot Rodeo - fixing control problems Gary Dillard Off-Season Events 7 26-10-2004 00:46
Do you all have problems with.... Munkaboo Website Design/Showcase 19 03-03-2003 19:51
Joystick problems archiver 2001 3 24-06-2002 02:40


All times are GMT -5. The time now is 14:04.

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