View Single Post
  #10   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