
Prenil
Hi everyone,
I've been playing around with the color tracking on my JD and while I can get the tracking to work, I'm having trouble getting the servos to move in response to seeing a color. Here is the code I have been using to try and Identify the color blue and then point in the general direction of the blue object:
:loop
$CameraObjectColor = ("Blue" ) ControlCommand("Camera", CameraStart)
SayWait("let me see" )
ControlCommand("Camera", CameraMultiColorTrackingEnable)
IF ($CameraObjectColor != "Blue" ) SayWait(" No I do not see the color" ) ENDIF
IF ($CameraObjectColor = "Blue" ) SayWait("I see a dot colored" + $CameraObjectColor) SayWait("It is in" +$CameraVerticalQuadrant +"and" + $CameraHorizontalQuadrant) ENDIF IF($CameraHorizontalQuadrant < 0) Servo(D4, 110) IF($CameraVerticalQuadrant < 0) Servo(D3, 75) ENDIF IF($CameraVerticalQuadrant > 0) Servo(D3, 110) ENDIF ENDIF IF($CameraHorizontalQuadrant < 0) Servo(D7, 110) IF($CameraVerticalQuadrant < 0) Servo(D2, 75) ENDIF IF($CameraVerticalQuadrant > 0) Servo(D2, 110) ENDIF ENDIF goto (loop)
I have not been able to get the servos to move at all. Can anyone suggest what I might be doing wrong? Thank you
Maybe this will work....? You'll need a lot of light on the object and check different shades of blue as well....
Not an answer to your question but an observation which may lead to more efficient code and easier to follow code...
ElseIf and Else can be used to save nesting Ifs inside Ifs. Also, or and and operators can also be used to make If statements easier to follow.
The rest of the code can just be simplified with ElseIf and Else to eliminate the nested Ifs. This should then help finding the problems and any bugs you may have.
Why not use servo relative tracking? The code seems to be doing the same thing...
@Technopro Maybe the op has additional code he wants to add to the script in order to do something custom?
Or they may be like me and want to script everything regardless of if there is a control for it.
I ment to add, if you need some guidance on the ifs, elseifs and elses or the structuring of code to make it easier to follow (and therefore easier to adjust 3 years down the line) I'll gladly re-write it with comments and explanations. Personally I am very picky when it comes to code and, at least my own or any I am using needs to be structured well, please don't take offence if this is implying I think your code isn't well structured (blame my OCD)
Hi everyone, I'm very sorry for not replying, I had some trouble with my email with is why my user name is a bit different now. Thank you very much for all your suggestions I will get to work trying them out right away and give you some feedback. Yes, I am trying to code all of it instead of using controls. @Rich, the sleep commands work very well, thank you! I didn't quite understand how to use them properly till that
@Rich I'm not sure I fully understand the repeat until statement in your code, I know it is meant to repeat all the code between RepeatUntil and EndRepeatUntil until the specified condition is met but I don't understand the condition 1=2?
@RichardR uses an impossible statement to repeat forever. It's no different to using the label and goto method.