More Spin help needed
NWCCTV
Posts: 3,629
Can anyone tell me what is wrong with the attached code? I am makeing a call to sense.start at the bottom of the program and that portion works fine but my Main code does not work. If I remove the call to Pings and sense.start my main code works fine. Sorry, I have not made any comments yet as I want the code to work first.
Con _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 IRP = 2 'ir receiver i/o port pin PING_Pin = 13 ' I/O Pin For PING))) LED1 = 8 ' I/O PIN for LED 1 LED2 = 9 ' I/O PIN for LED 2 ON = 1 OFF = 0 Distlimit = 6 ' In inches Var long code long range Obj pst : "parallax serial terminal" irt : "irtest" servo: "PropBOE Servos" 'Servo control object sense: "Ping Demo_NO_PST_Servo" ping : "ping" Pub Main pst.start(115200) irt.start(IRP, @code) 'after this "code" will contain the # for button pressed or 255 if no button is being pressed 'servo.start repeat pst.char(1) pst.dec(code) pst.chars(32, 3) waitcnt(clkfreq/100 + cnt) if code == (16) 'done, bail servo.Set(14, -250) ' P14 servo full speed counterclockwise servo.Set (15,250) elseif code == (17) servo.Set (0,300) servo.Set (1,-280) elseif code == (19) servo.Set (1, 75) servo.Set (0, -250) elseif code == (18) servo.Set (1, 250) servo.Set (0, -75) else servo.Set(14,-10) servo.Set(15, 45) pings Pub pings sense.start
Comments
Without looking at your complete code it's going to be very difficult to determine what is going on. Please use the File-->Archive-->Project and attach that file so that the entire scope of your code can be visualized.
One thing that I see is that you have two OBJ references to "PropBoe Servos". One of which looks like it is initiated properly with a "servo.start" but the other does not, but yet the program is trying to set various servos using the "servo.set" command without using "servo.start". And I'm not positive that they won't collide with each other if you try to initialize both of them together, although it might be ok. You just need to use "servo.start" within the "Ping Demo_NO_PST_Servo"
In the "IR_Servo_Ping" you are starting the 'irt', but there isn't anything to set the 'code' variable. so assuming code=0 then it falls through.... edit.. the code variable is being set, but even a value of 255 would fall through below if no buttons are pressed.
What code values are displayed when you 'remark' the 'pings' command at the bottom of "IR_Servo_Ping" without pressing any buttons on the IR?
if code == (16)
elseif code == (17)
elseif code == (19)
elseif code == (18)
upon which it calls "pings" and launches "Ping Demo_NO_PST_Servo"
EDIT: Hold on and I will test what you asked.
Edit: The IR object runs in the background in another cog constantly updating the variable "code" in the calling cog. Maybe you can operate the servo's, sense the ping all from the IR_Servo_ping.spin program?
EDIT: I tried placing the Ping code below the IR code and I get the same thing. The Ping code runs fine but the IR code does not work, like again it is just bypassing it for some reason. Code attached.
EDIT: I am flying to Montana tomorrow but will take my board, etc. with me so I can work on it. Thanks for the help.
time. Also the last "else" in your "if" part of your loop I imagine you will want to stop the servo's.
Also you want to stop them when you get to close to something. I altered your code a little where the bot
will stop when it gets to close or you are not pressing a button. I put a 3 second waitcnt but you can
replace that with what ever you want to happen. Maybe back up a little? The choice is yours.
usStepPerPulse)" method will do what you need. You do not need to call the start method of the servo object. If you include this in place of your startup routine you will have some control of ramping and the servos will be stopped. I picked 10 us step per pulse
but you can play with that to suit your needs.
reverse? If you do want to back up a little you will want to turn the servo's off after your waitcnt which should probably be more than the 10th of a second you have now. (Depends on what speed and how far you want it to move) Then the servo's will only move if you are
pressing a button and it has backed up far enough to be beyond your Distlimit..