|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
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!
|
|
#2
|
|||||
|
|||||
|
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!
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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;
Last edited by Dave Scheck : 22-09-2005 at 19:50. Reason: Did calculation for 26ms loop instead of 40ms |
|
#5
|
|||||
|
|||||
|
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..... |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |