|
SetTimedVariable Anonymous |
15 year
|
Hello,
I am using the SetTimedVariable to turn a motor for certain period of time. THe scenario is something like the Lego Grabber tutorial. I open first the hand, allow the motor to spin for 2000 miliseconds and then via switch change the stage. However, when i approach the object I want to do the same action but in the opposite direction. I copy the code a little of modifications and does not work. I keeps on spining forever. What is the problem? I will include the code. Maybe I need to use the Timer() which gives me a starting value of something like 65000 seconds which I whatsoever do not have a clue.
Thank you in advance. program.robo
|
|
|
Anonymous |
15 year
|
Your basic technique is correct except that when the SetTimedVariable function gets called each time (since step nor step1 are not yet <> 0) the function will reset the timing to change the variable.
So if you use
SetTimedVariable "step", 2, 1000
to set the variable step to 2 in about 1 second but instead call the same function again BEFORE 1 second has passed that will reset the timer to +1 second from that point. Thus because you call the function each time in the VBScript module it never has a chance to trigger.
So instead what you need to do is something like
select case GetVariable("state")
case 0:
period = 2000
SetTimedVariable "state",2,period
SetVariable "state", 1
case 1:
' literally do nothing while waiting for SetTimedVariable to trigger
case 2:
// ok continue on by stopping motor,etc.
end select
I'd recommend just using one variable "state" and multiple case statements rather than confusing things with more "step" variables.
STeven.
|
|
|
Dario Mirkovski from Macedonia, Former Yugoslav Republic [20 posts] |
15 year
|
Hello.
The SetTimedVariable method you showed me, works perfectly. However, I have one more question. Mentioned previously, I have an NXT trying to reach and catch an object. After that, has to realease it on the specific place. At the beggining the destination is the object, but as soon as the robot catches it, i need to set the new destination. How this can be done? I was thinking of including another Path_Planning module but it does not make sense.
Thank you in advance.
|
|
|
Anonymous |
15 year
|
You can specify variables for the destination in your current path_planning module just by using the [variable] nomenclature. Thus once the ball has been captured you would need to update the destination variables with the new location and then follow the path planning orientation again. There is no need for a second path planning module as using a variable allows you to change that destination. I.e. where you type in a number use [your_variable_name] instead.
STeven.
|
|
|
Dario Mirkovski from Macedonia, Former Yugoslav Republic [20 posts] |
15 year
|
Hello,
I think i did not get the solution you purposed. For the time being, I am using [ball_x] and [ball_y] as destination. When i reached it and grab it, i need to set new destination. I tried setting ball_x = GetVariable[place_x], but it actually did not work. What am i doing wrong?
Thank you again for the fast reply.
Dario
|
|
|
Anonymous |
15 year
|
Dario,
I'm not sure you have the syntax correct. It would be more like
ball_x = GetVariable("place_x")
and then you NEED to have
SetVariable "ball_x", ball_x
in order to save the value from the VBScript module to a RR variable that can be used in other modules (like the path planning).
STeven.
|
|
|
Dario Mirkovski from Macedonia, Former Yugoslav Republic [20 posts] |
15 year
|
Hey,
I did tried the way you showed me. However, when I add the new object and a blob filter, the destination is automatically set to be the new obejct, althogu i did not grab the initial one. The last thing i added is an if statement, which will do apply the new filter to find the place_x and place_y and set them as final destination but only if the state is 10, meaning that the object is already grabbed.
I will include the robo file. And one more question. Why does not the state show as a variable at the VbScript module?
Thank you in advance. program.robo
|
|
|
Anonymous |
15 year
|
|
|
Anonymous from United States [3 posts] |
14 year
|
Hi Steve,
Please find the script with my post. I want roborealm to check if it sees a rotating color ring (Red -Green -Blue ), it has to track colors starting and ending with red. So i have made changes to the code which was on the portal. if tracks red for 2 second then green for 2 second so on. I am adding colors to an array, 1, 2,3..I will process the array and find out that it got the RGBR color rotating ring. I am not sure that my logic is correct. Please guide me if i am on the wrong track
int period = 2000;
int step = getVariable("step");
int cogx = getVariable("cog_x");
int cogy = getVariable("cog_y");
int red = getVariable("MEAN_COLOR_R");
int blue = getVariable("MEAN_COLOR_B");
int green = getVariable("MEAN_COLOR_G");
int cog_bx =getVariable("COG_BOX_SIZE");
int arr[];
if (step == 0)
{
if(red > 10 && cog_bx > 70){
setVariable("data", 2);
setVariable("step", 1);
setTimedVariable("step", 2, period);
arr[0]=1;
}
else {
setVariable("step", 0);
}
}
else
{
if (step == 2)
{ if(green > 10 && cog_bx > 70){
setVariable("data", 4);
setVariable("step", 3);
setTimedVariable("step", 4, period);
arr[1]=2 ;
}
else{
setVariable("step", 0);
}
}
if (step == 4)
{ if(blue > 10 && cog_bx > 70){
setVariable("data", 6);
setVariable("step", 5);
setTimedVariable("step", 0, period);
arr[2]= 3 ;
}
else{
setVariable("step", 0);
}
}
}
|
|