loading
 
Controlling motors of iRobot Create through VB script program
Ishwarya from United States  [2 posts]
14 year
Hi,
I'm trying to write a script using the VB script program in RoboRealm to cause iRobot Create to respond to the position of a COG marker and move appropriately.  Following is a piece from my script (it is only a rough, incomplete version):

'Find the middle of the horizontal image
centerX=GetVariable("IMAGE_WIDTH")/2
centery=GetVariable("IMAGE_HEIGHT")/2
SetVariable "COG_X", cogX

SafeRange=5

'if image is within the center with a small range
'then move straight

if COG_X = centerx + SafeRange
then left_motor = 128
right_motor = 128

if COG_X = centerx - SafeRange
then left_motor = 128
right_motor = 128

if COG_X > (centerx + SafeRange)
then left_motor = 200
right_motor = 128

if COG_X < (centerx - SafeRange)
then left_motor = 128
right_motor = 200

SetVariable "left_motor", left_motor
SetVariable "right_motor", right_motor
_________________________________

It is not working though, and I think it is an interfacing issue.  I can't seem to find the iRobot's motor variables to use in the script.  Can I please receive some immediate help?

Thanks,
Ishwarya
Anonymous 14 year
Ishwarya,

Check your code. You are missing a bunch of end ifs and you cannot compare for equality to the COG as it is most likely not the exact value. Also you need a GetVariable and NOT a setVariable for the COG_X.

Also careful with typecase. In VB centerx and centerX are the same, not so in most other languages. So it is not incorrect but just good form to use the same typecase.

Note that we also have Python and now C as similar modules to the VB one in case you are more comfortable with those languages. Here's your simplified fixed code:

'Find the middle of the horizontal image
centerX = GetVariable("IMAGE_WIDTH")/2
centerY = GetVariable("IMAGE_HEIGHT")/2
cogX = GetVariable("COG_X")

SafeRange=5

if cogX > (centerX + SafeRange) then
  left_motor = 200
  right_motor = 128
else
  if cogX < (centerX - SafeRange) then
    left_motor = 128
    right_motor = 200
  else
   'if image is within the center with a small range
   'then move straight
    left_motor = 128
    right_motor = 128
  end if
end if

SetVariable "left_motor", left_motor
SetVariable "right_motor", right_motor
Ishwarya from United States  [2 posts] 14 year
Thanks!  As is evident, I know very little VB syntax, but am pretty comfortable with C++.  I will use the Cscript program-- I didn't know it existed.  I assume it comes automatically with a purchased license (will obtain soon) ?

Thanks,
Ishwarya
Anonymous 14 year
Ishwarya,

No worries, the CScript didn't exist until about 3 days ago! So most people are not aware of it.

Yes, the trial and the purchased copy contain the same functionality with the purchased copy just not expiring after 30 days.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index