
mdeming1

Ok, so I've finally found Rich's and others script examples and come to understand that the cloud has repositories but is only available through the ez-b gui. So, I've been doing some scripting, cutting and pasting. I need a little evaluation and assistance.
First off. My goal is for the robot to wake up on specific days and times (that hopefully I can ultimately control from my house online calendar but for now using the script), send an ir signal, follow a path, send a few more signals and then return later, also not wake skynet.
So here is what I have so far. I connected a SMAKN 315Mhz Rf Transmitter and Receiver Link Kit (.Receiver module parameters: 1.Product Model: MX-05V 2.Operating voltage: DC5V 3.Quiescent Current: 4mA 4.Receiving frequency: 315MHz 5.Receiver sensitivity: -105DB 6.Size: 30 x 14 x 7mm
.Technical parameters of the transmitter head 1.Product Model: MX-FS-03V 2.Launch distance : 20-200 meters (different voltage, different results) 3.Operating voltage: 3.5-12V 4.Dimensions: 19 x 19mm 5.Operating mode: AM 6.Transfer rate: 4KB / S 7.Transmitting power: 10mW 8.Transmitting frequency: 315MHz 9.Pinout from left ? right: (DATA; VCC; GND)
Main Code:Code:
:script_1
:script_2
# Run every Saturday and Sunday
IF($Dayname = Saturday AND $Daytimehour =8)
Goto(script_1)
Return
WaitUntilTime(20,00)
Goto(script_2)
Return
ElseIf($Dayname = Sunday And $Daytimehour =8)
Set(D1, on)
Goto(script_1)
Return
WaitUntilTime(20,00)
Goto(script_2)
Return
Else
#not sure what to put after the bot returns to home at the end of script 2 to make it sleep until the next Sat/Sun
Sleep(1000)
Endif
Script 1Code:
#send ir signal
$sendiropen = Set(D13, ON)
Sleep(5000)
Forward(25, 1000)
Stop()
Right(25,900)
#go outside
Forward(50,5000)
Stop()
#turn around, close door, then turn around again
Left(25,1800)
$sendirclose = Set(D13, OFF)
Left(25,1800)
#proceed
Forward(50,3000)
#ok so here I need to figure how to plot the path and avoid obstacles see below
#continue following path
#avoid obstacles
#sleep
I have a DE-ACCM3D buffered 3d accelerometer attached to analog, the ez-b ultrasonic sensor which I have script for but not sure where to integrate, I also have the wireless camera that came with the kit or some nice old school camcorder tech or some iphone cameras, finally, I have the roborealm avm software but I'm clueless on integration for my purpose at this juncture.
My two wheelchair motors powered by two 12v batteries in parrallel are connected to the sabertooth 5x25 motor controller with the kangaroo (not sure if this needs scripting). I don't want to run a third battery pack and I'm told that the 5v from sabertooth may not be enough? It seems to run ok but would you rec an additional piece of hardware for good voltage?
My other questions are:
How is the script so far?
How can I integrate the other functionalities?
What hardware to I still need to get?
What am I not thinking about?
I have access to lots of parts. one offtopic question I'm not clear on as well. Does battery monitor script for sla batteries need a piece of hardware to work or will it work just as a software function?
I hope that it's ok to ask these. I feel so close to getting her rolling with the shoulders I'm standing on here on the forum and I really appreciate it.
Matt
Richard, for grins can you try it on D0 with the Movement Panel and dips at 1,3,6 on if you haven't already? The other week I found that only D0 worked for me (I haven't tried the roo yet) Despite up to date firmware on my v3, my sabertooth controller didn't work right until I set it to D0. My motors aren't at home right now or I'd reconnect them to try myself.
Any other suggestions regarding my initial queries?
The labels for script_1 and script_2 should be at the very end otherwise these will run when the script is first run regardless of the conditions. That said, I have now started to make sub code such as these bits as their own scripts and using ControlCommand to run them. This also means you can manually run the scripts or have other scripts start up the same sequence of commands without re-writing it in each script.
The return after the goto should be in the sub script not after the goto.
At the end of script 2 the code would continue after the EndIf not in the Else.
So something like this;
Code:
On Script_1, you don't need stop() between the forward() and left() or right() commands, just using left() or right() would change the direction. Unless you wanted a noticeable stop in the movement, if so you would need to add a sleep after the stop.
There may be other ways to write the script. What I do is list out the order of operation for the commands and then look at how to achieve each part. My latest Ping Roam script is split in to multiple scripts and uses the ControlCommand to start up each part when required. In the topic (which I'll link to when I get chance to find it) I posted a bunch of my notes on my first rough code too which may give an idea how I go about thinking how to do what, where, why and if there is anything that could be done differently or better.
Hope that helps.
I'm not sure on the sabertooth speeds since I don't have one to play with.
I was wondering if you might share with me the script that you use for the Sabertooth control using the SendSerial Commands.
I would like to test it out and see which would work better for me.
Thanks
$mot1=127 #full forward
$mot2=255 #full forward
SendSerial(D0,$mot1) #motor 1
SendSerial(D0,$mot2) #motor 2
So $mot1 can be any number between 1 and 127 .... 64 is stop ... below 64 is reverse, above 64 is forward for that motor
So $mot2 can be any number between 128 and 255... 192 is stop... below 192 is reverse, above 192 is forward for that motor
If $mot1 or $mot2 are set to 0 then both motors stop...
Also, SendSerial needs the baud rate, so should be SendSerial(Port, Baud, Data, Data, Data...) or in this case SendSerial(D0,38400,127).
Here's a quick example which also covers the correct use of goto, return and halt (2 birds with 1 stone and all)
Code:
ALso, I read in one of RichR's earlier threads the KRoo needed a sensor. I have the aforementioned 3d accelerometer attached physically to the ezb, should I connect this to the roo? Is it something that has to be separately programmed.
Thank you for your patience with my questions. Believe me I'm learning tons and reading and re-reading just about every forum post there has been. If I'm asking too much just let me know. I wish I hadn't have gotten delayed two years ago. Back then I totally agreed with DJ about the future of robotics and the robot rev. is going to burst into everyday consciousness any day now. Very exciting.
Code:
Would I do this?
Code:
or, conversely Option 2:
Code:
I understood the forward commands in my original example but am not sure if I can use the same speed/time variables in the sample send serial codes.
Hope it makes sense.
0 is stop
1 is motor 1 full speed reverse
127 is motor 1 full speed forward
63 is halfway between so I assume it is motor 1 stop (or motor 1 very very slow)
128 is motor 2 full speed reverse
191 is halfway between so I assume it is motor 2 stop (or motor 2 very very slow)
255 is motor 2 full speed forward
So, for instance, to move forward at half speed you would need to change the code I wrote to this;
Code:
1 to 63 is motor 1 reverse speed with 1 being fastest and 63 being slowest
64 to 127 is motor 1 forward speed with 64 being slowest and 127 being fastest
128 to 191 is motor 2 reverse speed with 128 being fastest and 191 being slowest
192 to 255 is motor 2 forward speed with 192 being slowest and 255 being fastest
0 is stop both motors
In my movement example, the sleeps basically determine how long the robot moves for before changing direction/movement. The script sets the motors to move forwards, then the script waits 5000ms (5 seconds), the robot will remain moving forwards for this 5 seconds. The script then changes the direction, this makes the robot turn, the sleep waits for 2000ms (2 seconds) then moves forwards again.
Hopefully that makes sense?
However if you use a kangaroo the syntax is different as the kangaroo uses a feedback sensor (or a pot) to determine position.
And FYI, there is no such thing as too many questions. Ask away. We are here to help.
I really wish the Forward programing would work with the sabertooth (and really the roo too)because it was very easy to understand. For instance, I've modified my original Script_1 with send serial commands and your modified code. I'm worried, however that when I want to turn the bot 90 degrees for instance, in the prior command structure of move forward I could put speed and 9 milliseconds and it was easy to understand. In the send serial commands I'm thinking if it turns right 9000 milliseconds it's going to turn in a circle for 9 seconds. Here is my modified script below for eval:
Code:
As for turning etc. the way I did it with Melvin was to time how long it takes him to turn 90 degrees in each direction (both directions are different for my setup) by setting him turning right and using a stopwatch (or stopwatch app on my phone) checked to see how long it took to move. Then I fine tuned this by tweaking the sleep in the "Turn 90 right" script. The same for left and for 180 degrees.
I did the same for his speed for moving, that way I could roughly move him half a meter or a meter based on the time it takes.
In the code example I posted personally I would split it to multiple scripts and name them "forwards", "reverse", "left", "right" and "stop". Just basically take the code between the :label and the Return() and paste it in to a new script in script manager. You can call these with ControlCommand() in any script or run them manually that way.
If you do this you could also run the "turn left", which will spin the robot anti-clockwise (counter clockwise if you're American...). Time to see how long it takes to turn 90 degrees (I did 3 or 4 tests to get an average), then run the stop script. Write another script for "turn 90 left" which would be something like
Code:
Do the same for right turning
Code:
Then, if needed, you can call on these 90 degree turning scripts to turn with another ControlCommand() in any other scripts;
Code:
Notice I used ScriptStart and ScriptStartWait. There is a difference. ScriptStart runs the script without pausing the script that calls it. ScriptStartWait will pause the script which called it until the called script is finished, then it will automatically resume.
Hopefully all of that made sense.
Here is my script 1 problem. No syntax errors but it always just stops at #8. I made the movements separate script commands like you suggested. I'll post them below as well. Why is it stopping? I know I have a lot of sleeps, I just want to be able to identify breaks in the program. I'm not even sure if these commands will work with the sabertooth and/or the kangaroo. It is somewhat frustrating because I feel I'm making mistakes that should be obvious but aren't.
script 1
Code:
turn right script
Code:
(move forward, left, stop etc. are similar separate scripts as suggested)
Matt
Save it to the cloud and make it public or attach it to a forum post and I'll gladly take a look when I get chance. If you want to keep it quiet my email address is in my user details.
I think that the few times I forgot to save the file after checking syntax my script got sloppy.
I originally had Forward commands, then Goto commands, then I replaced all of those with command control and now my brain is fried and I probably need to start over.
I appreciate your offer of assistance. Let me see how I can get my program a little easier to understand and i'll get back to you.
My program is nearly to the point that your avatar is about to be relevant to my situation.
warm regards
Matt