MicroBasic script problem

5 years 1 month ago - 5 years 1 month ago #29533953 by StianI
Hi, I am having a problem with my microbasic script. The script is below. My setup consists of a motor set to closed loop position operating mode, moving along a monorail. It has clickswitches on both sides, so that it can detect when it crashes into to plates at the very ends of the monorail.

I want to set up a homing sequence for this setup. When I turn in on, I want the motor to move along the monorail to the left, hit the left boundry (so that the switch is pressed in). I tried putting the homing code into "init", but it is not working now. The setup starts moving to the left and stops moving when the left clickswitch is pressed in. However, the SetCommand(_C,0) does not seem to work. I want it to be set to 0 when the setup is in the left boundry position.
Any ideas? I hope I explained it good enough.
Thanks:)
init:

SetCommand(_C,0)
new_init_cmd = -100000
setCommand(_P, new_init_cmd)
lftSafety = GetValue(_DI,5)
initPos = getValue(_C)
 if lftSafety = 0
 	
 	setCommand(_p,initPos)
 	end if
wait(50)
print ("Startposisjonen er satt")
SetCommand(_C,0)

main:

new_cmd = GetValue(_VAR, 9)
if cmd <> new_cmd then
  cmd = new_cmd
  setCommand(_P, cmd)
end if

lftSafety = GetValue(_DI,5)
rgtSafety = GetValue(_DI,4)
c_pos = GetValue(_C)

if lftSafety = 0 And cmd < c_pos then
    print ("Cannot move left!")
	cmd=c_pos
	setCommand(_P, cmd)
elseif rgtSafety = 0 And cmd > c_pos then
	print ("Cannot move right")
	cmd=c_pos
	setCommand(_P, cmd)
end if
wait(5)
goto main

'################################

Please Log in or Create an account to join the conversation.

5 years 1 month ago #29533959 by Gabriel_Isko
Replied by Gabriel_Isko on topic MicroBasic script problem
The homing position routine has to be run continuously in a loop. I think with this script you are only running it once. You should also check to make sure your limit switch is wired correctly and that you can see that input on the motor controller.

I'm also not sure where you got that homing routine from. Homing should really be done in open loop. We give a homing search script in our sample script download, please find it attached to this post.

File Attachment:

File Name: home-search.zip
File Size:1 KB
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: tonysantoni
Time to create page: 0.075 seconds