View unanswered posts | View active topics It is currently Fri Nov 28, 2014 8:10 pm






Reply to topic  [ 11 posts ] 
Recording movement in RobotC? 
Author Message
Rookie

Joined: Sat May 04, 2013 4:20 am
Posts: 4
Post 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?


Sat May 04, 2013 4:28 am
Profile
Rookie

Joined: Sat May 04, 2013 4:00 am
Posts: 3
Post Re: Recording movement in RobotC?
That is a good question. I'm interested as well! Hopefully we'll get a response here soon.


Sat May 04, 2013 12:52 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post 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.

_________________
sudo rm -rf /


Sun May 05, 2013 11:33 am
Profile
Rookie

Joined: Sat May 04, 2013 4:20 am
Posts: 4
Post 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...


Sun May 05, 2013 1:52 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Recording movement in RobotC?
magicode wrote:
... but it's impossibly difficult either.



Don't you mean not impossibly difficult?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Sun May 05, 2013 6:53 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post 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:

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sun May 05, 2013 7:27 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post 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.

_________________
sudo rm -rf /


Sun May 05, 2013 8:40 pm
Profile
Rookie

Joined: Sat May 04, 2013 4:20 am
Posts: 4
Post 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.


Mon May 06, 2013 7:16 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Recording movement in RobotC?
Sorry, I didn't mean to imply that you were a beginner. I was just stating the difficulty level.

_________________
sudo rm -rf /


Mon May 06, 2013 10:49 am
Profile
Rookie

Joined: Sat May 04, 2013 4:20 am
Posts: 4
Post 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.


Mon May 06, 2013 1:36 pm
Profile
Rookie

Joined: Sun Apr 06, 2014 5:25 pm
Posts: 1
Post 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?


Sun Apr 06, 2014 5:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.