So a while ago, right before I left my robotics lab, I did a final little project about motor velocity mapping, PID velocity control and rerun program. The project is mainly successful as I did make the rerun work pretty well:
But I was never able to complete the final few steps – optimizing the output in debug stream. The method in the video is extremely tedious – print two lines of assign values and one line of delay every tenth of a second, and go as long as you want to. A 30 second record would take up 900 lines of code.
Well that’s not very nice, is it?
So today I had some time and decided to finish up one of the final steps of my little rerun project. Which is using an array to store the data and letting the debug stream print out a looped rerun program that has its identical independent data set as the recording. This way you can apply the recording to any motors on any cortex conveniently.
So, in summary, what I did was this:
https://vexforum.com/attachment.php?attachmentid=9447&stc=1&d=1434589985
[;
bool recording = false;
void initialize ();
void joystick_simulation ();
task LCD ();
task record_and_write ();
void writeReplayCode ();
task main()
{
initialize ();
while(true)
{
if (recording)
{
joystick_simulation();
recording=false;
}
wait1Msec(1);
}
}
//////////////////////////////////
void initialize_data_array ()
{
for(int i=0;i<150;i++)
{
data*=0;
}
}
void initialize ()
{
clearDebugStream();
initialize_data_array();
startTask(LCD);
startTask(record_and_write);
}
void visualize_joystick_simulation ()
{
writeDebugStreamLine(“%i”,joystick);
}
void joystick_simulation ()
{
for (int i=0; i<150;i++)
{
joystick = simulation_scale_factor*sin(i/PI);
wait1Msec(100);
//visualize_joystick_simulation();
}
}
task LCD ()
{
int count=1;
string time;
while(true)
{
if (nLCDButtons==2)
{
recording = true;
displayLCDString(0,0," recording “);
displayLCDString(1,0,” “);
while(count<15000)
{
count++;
sprintf(time,”%2.3f",count/1000.000);
displayLCDCenteredString(1,time);
wait1Msec(1);
}
}
displayLCDString(0,0," press to ");
displayLCDString(1,0,“start recording”);
wait1Msec(1);
}
}
void newLine ()
{
writeDebugStreamLine(“”);
}
void writeReplayCode ()
{
writeDebugStreamLine(“void replay ()”);
writeDebugStreamLine(“{”);
writeDebugStreamLine(" byte drive[150] = {“);
for(byte i=0;i<10;i++)
{
for (byte j=0;j<15;j++)
{
writeDebugStream(”%i,“,data[j+i15]);
}
newLine();
}
writeDebugStreamLine(“};”);
writeDebugStreamLine(" for(int i=0;i<150;i++)“);
writeDebugStreamLine(” {“);
writeDebugStreamLine(” motor[m] = drive;”);
writeDebugStreamLine(" wait1Msec(100);“);
writeDebugStreamLine(” }“);
writeDebugStreamLine(” motor[m] = 0;“);
writeDebugStreamLine(”}");
}
task record_and_write ()
{
int count = 0;
bool write = false;
while(true)
{
while(recording&&count<150)
{
data[count]=joystick;
count++;
write=true;
wait1Msec(100);
}
if(write)
{
writeReplayCode();
write=false;
}
wait1Msec(1);
}
}
[/CODE]
Cheers,
MartinMaVEXForever**](Letting ROBOTC Write Programs For You ?!!!!!!!! - YouTube)
practicing smart printing program.c (2.48 KB)