ROBOTC.net forums
http://www.robotc.net/forums/

Recording movement in RobotC?
http://www.robotc.net/forums/viewtopic.php?f=1&t=5814
Page 1 of 1

Author:  binamenator [ Sat May 04, 2013 4:28 am ]
Post subject:  Recording movement in RobotC?

I've recently shifted from using the lego minstorms GUI to RobotC. I used lego mind storms GUI recording block a lot - Basically if you put record in the program, and it records the movements as you move the robot. Then you edit the program to say play, and it plays the previous movements.
Is it possible to do this in RobotC?

Author:  Shaidar20 [ Sat May 04, 2013 12:52 pm ]
Post subject:  Re: Recording movement in RobotC?

That is a good question. I'm interested as well! Hopefully we'll get a response here soon.

Author:  magicode [ Sun May 05, 2013 11:33 am ]
Post subject:  Re: Recording movement in RobotC?

Yes it is certainly possible, but there's no "record" button. You have to implement it yourself. You have to track the sensors as you move the robot, and store them in a file. Then read from the file as you "play" the program. It's not the easiest program in the world if you're a beginner, but it's not impossibly difficult either.

//Edit: not impossibly difficult. Thanks Coder A.

Author:  binamenator [ Sun May 05, 2013 1:52 pm ]
Post subject:  Re: Recording movement in RobotC?

Hmmm... well does anyone know the command for tracking motors?
I'm pretty sure it has something to do with encoders....

Also it would be cool if we could just record the robots actions through joystick...

Author:  Coder A [ Sun May 05, 2013 6:53 pm ]
Post subject:  Re: Recording movement in RobotC?

magicode wrote:
... but it's impossibly difficult either.



Don't you mean not impossibly difficult?

Author:  NeXT-Generation [ Sun May 05, 2013 7:27 pm ]
Post subject:  Re: Recording movement in RobotC?

Not impossibly difficult, but pretty bleeping difficult. I guess you'd have to save the encoder values to an array and play that back, though how I'm not certain. I could probably do it if I had the time. But I've got like 5 robots to finish in about a month. :shock:

Author:  magicode [ Sun May 05, 2013 8:40 pm ]
Post subject:  Re: Recording movement in RobotC?

I've implemented this once, and it's not too bad. You just save every change in sensor values in an array, along with a timestamp, and feed the array to a PID algorithm. Save to a file for persistence. There is a little work involved in smoothing out the resulting motion (a little knowledge of statistics or googling skills reqiured). Again, definitely a challenge for beginners.

Author:  binamenator [ Mon May 06, 2013 7:16 am ]
Post subject:  Re: Recording movement in RobotC?

I'm no beginner in programming, I'll assure you that.
Using an array and PID control does give me some lead on what I should do, so thanks for the guidance.
If I do come up with something, I'll write the code down here. I have exams to complete first though, so don't expect anything till the summer.

Author:  magicode [ Mon May 06, 2013 10:49 am ]
Post subject:  Re: Recording movement in RobotC?

Sorry, I didn't mean to imply that you were a beginner. I was just stating the difficulty level.

Author:  binamenator [ Mon May 06, 2013 1:36 pm ]
Post subject:  Re: Recording movement in RobotC?

Sorry, I never really implied to say that you implied that I was a beginner.... >.<
Anyhow, I would have to learn a bit more in PID control.

Author:  wizgrao [ Sun Apr 06, 2014 5:31 pm ]
Post subject:  Re: Recording movement in RobotC?

I did this a while ago,

For Recording
Quote:
#pragma config(Motor, motorB, lMotor, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, motorC, rMotor, tmotorNXT, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"
#define RECORD_BUTTON 5
#define STOP_BUTTON 6
task main(){
int lMotorx;
int rMotorx;
TFileHandle hFileHandle; // will keep track of our file
TFileIOResult nIoResult; // will store our IO results
string sFileName = "recorded.txt"; // the name of our file
int nFileSize = 13000; // will store our file size
bool recording = false;
bool buttonPressed;
int recordCount = 6000;
bool recordingStarted = false;




while(true)
{
getJoystickSettings(joystick);
if (abs(joystick.joy1_y1)>10)
lMotorx = joystick.joy1_y1;
else lMotorx = 0;
if (abs(joystick.joy1_y2)>10)
rMotorx = joystick.joy1_y2;
else rMotorx =0;
if(joy1Btn(RECORD_BUTTON))
{
recording = true;
recordingStarted = true;
}
if(joy1Btn(STOP_BUTTON))
recording = false;

while(time10[T1] <1){}time10[T1]=0;
if((recording &&recordCount <=0)||(!recording && recordingStarted) )
{
recordingStarted = false;
PlaySound(soundBeepBeep);
while(recordCount>0){
recordCount--;
WriteShort(hFileHandle,nIoResult,0);
WriteShort(hFileHandle,nIoResult,0);

}
for(int i = 0; i < 100; i ++ )
WriteShort(hFileHandle,nIoResult,0);
recordCount = 6000;
Close(hFileHandle, nIoResult);
recording = false;

}else if(recording && recordCount ==6000){

PlaySound(soundBeepBeep);
Delete(sFileName,nIoResult);
OpenWrite(hFileHandle, nIoResult, sFileName, nFileSize);
WriteShort(hFileHandle,nIoResult,lMotorx);
WriteShort(hFileHandle,nIoResult,rMotorx);
recordCount --;

}else if(recording){
WriteShort(hFileHandle,nIoResult,lMotorx);
WriteShort(hFileHandle,nIoResult,rMotorx);
recordCount --;
}
motor[lMotor] = lMotorx;
motor[rMotor] = rMotorx;


}
}
for playing back:
Quote:
#pragma config(Motor, motorB, lMotor, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, motorC, rMotor, tmotorNXT, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"
#define RECORD_BUTTON 5
#define STOP_BUTTON 6
task main(){
int lMotorx;
int rMotorx;
TFileHandle hFileHandle; // will keep track of our file
TFileIOResult nIoResult; // will store our IO results
string sFileName = "recorded.txt"; // the name of our file
int nFileSize = 13000; // will store our file size
bool recording = false;
bool buttonPressed;
int recordCount = 6000;
bool recordingStarted = false;




while(true)
{
getJoystickSettings(joystick);
if (abs(joystick.joy1_y1)>10)
lMotorx = joystick.joy1_y1;
else lMotorx = 0;
if (abs(joystick.joy1_y2)>10)
rMotorx = joystick.joy1_y2;
else rMotorx =0;
if(joy1Btn(RECORD_BUTTON))
{
recording = true;
recordingStarted = true;
}
if(joy1Btn(STOP_BUTTON))
recording = false;

while(time10[T1] <1){}time10[T1]=0;
if((recording &&recordCount <=0)||(!recording && recordingStarted) )
{
recordingStarted = false;
PlaySound(soundBeepBeep);
while(recordCount>0){
recordCount--;
WriteShort(hFileHandle,nIoResult,0);
WriteShort(hFileHandle,nIoResult,0);

}
for(int i = 0; i < 100; i ++ )
WriteShort(hFileHandle,nIoResult,0);
recordCount = 6000;
Close(hFileHandle, nIoResult);
recording = false;

}else if(recording && recordCount ==6000){

PlaySound(soundBeepBeep);
Delete(sFileName,nIoResult);
OpenWrite(hFileHandle, nIoResult, sFileName, nFileSize);
WriteShort(hFileHandle,nIoResult,lMotorx);
WriteShort(hFileHandle,nIoResult,rMotorx);
recordCount --;

}else if(recording){
WriteShort(hFileHandle,nIoResult,lMotorx);
WriteShort(hFileHandle,nIoResult,rMotorx);
recordCount --;
}
motor[lMotor] = lMotorx;
motor[rMotor] = rMotorx;


}
}
Maybe you could adapt this code for your purposes?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/