Asked — Edited
Resolved Resolved by Rich!

Script Eval

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:


: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 1


#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


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

#1  

For one thing Kangaroos are daunting at best... I have not had much luck with mine... So they are on the shelf for now. The script is generally good, but one thing right off the bat is you are going to need to use sendserial() commands instead of Forward() in order to control the sabertooth (and kangaroo) properly... Especially if you want to use the Kangaroo with the sabertooth. Sendserial gives you way better control over the sabertooth... And if you will be using a V4 and the 12V batteries to power it... It has a built in software command to check battery voltage (and cpu temperature too)...

PRO
Synthiam
#2  

@Richard, why would you suggeset SendSerial instead of Forward() if @mdeming1 is using the sabertooth movement panel?

#3  

I was never able to get the forward() command to work well (I actually posted my problem months ago and someone suggested sendserial instead)... I couldn't control the speed of my sabertooth (until I switched to send serial command). So with the Forward($speed,5000) command and the sabertooth Movement Panel I was unable to control speed... No matter what value I entered for $speed, the sabertooth always went full out or stop... I will concede however, that maybe I didn't have the sabertooth set up right way back then when I was first experimenting with ARC and the sabertooth... I have never looked back since sendserial works perfectly...

#4  

Ok, so I just tried it again... Same problem. Have the 2x12 sabertooth set up for serial (as per the dips)... added the sabertooth movement panel... Then added a script with forward($speed,3000) command... where $speed=50... the Sabertooth (motors) just ran full out.. I tried different values for $speed... The sabetooth still just runs full out. The Movement Panel does however work as expected....

#5  

Hi and thanks again. 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?

United Kingdom
#6  

Quickly looking over the script;

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;


:loop
# Run every Saturday and Sunday
  IF($Dayname = Saturday AND $Daytimehour =8)
    Goto(script_1)
    WaitUntilTime(20,00)
    Goto(script_2)
  ElseIf($Dayname = Sunday And $Daytimehour =8)
    Set(D1, on)
    Goto(script_1)
    WaitUntilTime(20,00)
    Goto(script_2)
  Else
  Endif
#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)
Goto(loop)

Halt() # This will stop the script should it ever escape the loop for any reason, rather than running script_1's commands.
:script_1
# Script_1 commands
Return()

:script_2
#Script_2 commands
Return()

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.

#7  

I did use D0 as my port and as mentioned the Movement Panel works as expected. However, using the forward() command although it works, I can not control how fast the motors spin... So forward(50,3000) is the same as forward(200,3000)... Another reason I use sendserial instead is because not all motors put out the same power. More often than not one motor is stronger than the other which causes the robot to veer to either the right or left.... SendSerial allows you to fine tune each motor individually so you can compensate for any veer... So making the robot go straight more or less...

United Kingdom
#8  

You can change the forward and reverse speeds in the Sabertooth control panel by clicking on the gear icon. If the robot veers off to one direction you just need to reduce the full forward values to suit.

I'm not sure on the sabertooth speeds since I don't have one to play with.

#9  

I know Rich... I have played with the Movement Panel and it works as expected (speed changes are no problem just using the movement panel)... Also I do completely understand the sabertooth serial ControlCommand() set 1... 64 .... 127 (motor 1) and 128.... 192 ... 255 (motor 2). Changing these settings within the Movement Panel has the expected effect... What I am saying is that when I use the script command Forward($speed,500) and if the Movement Panel is set to default values ( which is full out), then I am unable to adjust the speed of the motors from within a script... So no matter what value $speed is set to, the motors just run full out... I can stop(), left(), right() and reverse() no problem... but only at full speed... So to summarize... In order to adjust speeds I have to manually go back to the Movement Panel and change the settings there... then the script commands (Forward, left, right etc) will run at the settings set in the Movement Panel only...

#10  

@RichardR

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

#11  

Man I wish I had my motors handy, should get them back today or tomorrow. I think I used that slider motor speed control when I rigged mine up briefly to compensate for the all out speed and I think it worked. I'm not clear on how built in functions like the controller interface and script functions are then all Combined to be a single program that runs automatically. Rich, thanks for the script pointers. I've read all of your tutorials and they've proven helpful. Richard R if I use the send serial with the kangaroo do I have to change my pin settings again? You had some you were trying in an earlier post. Is there a way to add the additional receive port for the ezb without having to buy a v4?

#12  

It's pretty simple... $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...

United Kingdom
#13  

@Richard R, comments are made by using the # not the '

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)


# Quick movement example
Goto(MoveForward)
Sleep(5000)
Goto(TurnRight)
Sleep(2000)
Goto(MoveForward)
Sleep(5000)
Goto(TurnLeft)
Sleep(2000)
Goto(MoveReverse)
Sleep(5000)
Goto(Stop)

Halt()

:MoveForward
# Left motor forward
SendSerial(D0,38400,127)
# Right motor forward
SendSerial(D0,38400,255)
Return()

:MoveReverse
# Left motor reverse
SendSerial(D0,38400,1)
# Right motor forward
SendSerial(D0,38400,128)
Return()

:TurnRight
# Left motor forward
SendSerial(D0,38400,127)
# Right motor reverse
SendSerial(D0,38400,128)
Return()

:TurnLeft
# Left motor reverse
SendSerial(D0,38400,1)
# Right motor forward
SendSerial(D0,38400,255)
Return()

:Stop
# Both motors stop
SendSerial(D0,38400,0)
Return()

#14  

Ooops, Thanks Rich... I go back and forth all the time between ARC and my basic atom IDE software... Basic atom uses ' to comment out...

#15  

OK, fantastic. Let me change my movements to script and i'll repost for eval. Just to be clear though, now that I'm using the kangaroo can I keep the pins as they were for 38400 when using just the sabertooth (1,3,6) or does it need to be changed? 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.

#16  

Well at the risk of sounding foolish. If I'm programming send serial with similar script to the above reference how/where do I indicate speed? For instance using an appended version of Rich's example:


Goto(MoveForward)
Sleep(5000)

:MoveForward
# Left motor forward
SendSerial(D0,38400,127)
# Right motor forward
SendSerial(D0,38400,255)
Return()

Would I do this?


Goto(MoveForward)
Goto(MoveForwardSpeed)
Goto(MoveForwardSpeedTime)
Sleep(5000)

:MoveForward
#Left motor forward
SendSerial(D0,38400,127
#Right Motor forward
SendSerial(D0,38400,255

:MoveForwardSpeed
#Left motor speed
SendSerial(DO,38400,50
#Right motor speed
SendSerial(D0,38400,198)

:MoveForwardTime
#not sure, maybe (5000)?

or, conversely Option 2:


#here just adding speed of 198 for 5 seconds
Goto(MoveForward,198,5000)
Sleep(5000)

:MoveForward
# Left motor forward
SendSerial(D0,38400,127)
# Right motor forward
SendSerial(D0,38400,255)
Return(

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.

United Kingdom
#17  

The speed of the sabertooth is set by the data.

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;


:MoveForwardHalfSpeed
# Left motor forward at half speed
SendSerial(D0,38400,63)
# Right motor forward at half speed
SendSerial(D0,38400,191)
Return()

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.

#18  

Thanks Rich. I feel like I'm so close and yet on so many things I'm clueless about the last few steps. 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:


#undock from charge port(not a current functionality, this is for later)
#send ir signal (I really hope this is a simple deal i.e. on sends a signal, off sends a signal.
$sendiropen = Set(D13, On)
Sleep(5000)
Goto(MoveForwardSlow)
Sleep(2000)
Goto(TurnRight)
Sleep(9000)
#hoping the above turns the bot 90 degrees
Goto(MoveForwardMed)
Sleep(5000)
stop()
Goto(TurnLeft)
Sleep(1800)
stop()
#hoping the bot now turns around 180 degrees
$sendirclose = Set(D13, 0ff)
sleep(3000)
Goto(TurnLeft)
sleep(1800)
#robot turns around 180 again
Goto(MoveForwardMed)
Sleep(5000)
#at this point the bot is really close to road assuming 5 seconds will get there, this is my mapping/sensor dilema
stop()
Goto(TurnLeft)
Sleep(9000)
#Robot turns left 90 degrees above
Goto(MoveForwardMed)
Sleep(5000)
Goto(TurnRight)
Sleep(9000)
#robot turns 90 degrees
Goto(Stop)

Halt()

:MoveForwardMed
#Right Motor forward med.
SendSerial(D0,38400,96)
#Left Motor forward med.
SendSerial(D0,38400,224)

:MoveForwardslow
# Left motor forward slow
SendSerial(D0,38400,63)
# Right motor forward slow speed
SendSerial(D0,38400,193)
Return()

:MoveReverse
# Left motor reverse
SendSerial(D0,38400,1)
# Right motor forward
SendSerial(D0,38400,128)
Return()

:TurnRight
# Left motor forward
SendSerial(D0,38400,127)
# Right motor reverse
SendSerial(D0,38400,128)
Return()

:TurnLeft
# Left motor reverse
SendSerial(D0,38400,1)
# Right motor forward
SendSerial(D0,38400,255)
Return()

:Stop
# Both motors stop
SendSerial(D0,38400,0)
Return()

United Kingdom
#19  

You will get there, we all have the Eureka moment where everything clicks in to place.

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


ControlCommand("Script Manager", ScriptStart, "Turn Left")
Sleep(3000) # Adjust this value to suit turning speed
ControlCommand("Script Manager", ScriptStart, "Stop")

Do the same for right turning


ControlCommand("Script Manager", ScriptStart, "Turn Right")
Sleep(3000) # Adjust this value to suit turning speed
ControlCommand("Script Manager", ScriptStart, "Stop")

Then, if needed, you can call on these 90 degree turning scripts to turn with another ControlCommand() in any other scripts;

ControlCommand("Script Manager", ScriptStartWait, "Turn 90 Left")

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.

#20  

Thanks Rich, i'll try to make the scripts. Take a look at my post about avm when you have a chance and weigh in.

#21  

Hi Rich, since my camera won't work I decided to work on some of the programming. Wish I hadn't taken a week because I've forgotten some things. I did learn to save my work after three instances of losing everything.

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


#send ir signal
ControlCommand("Script Manager", ScriptStart, "IR_Signal")
Return ()

ControlCommand("Script Manager", ScriptStart, "Move Forward")
#add speed/time (slow 2 sec)to above)
Sleep(2000)
ControlCommand("Script Manager", ScriptStart, "Turn Right")
Sleep(3000)
Return()
ControlCommand("Script Manager", ScriptStart, "Move Forward")
Return()
# Robot going outside above, add speed/time(medium,5000) to above
Sleep(2000)
ControlCommand("Script Manager", ScriptStart, "Turn Left")
Sleep(1000)
ControlCommand("Script Manager", ScriptStart, "IR_Signal")
Return ()
ControlCommand("Script Manager", ScriptStart, "Turn Left")
#add speed/time(slow,1800) to above
sleep(1000)
ControlCommand("Script Manager", ScriptStart, "Move Forward")
#add speed/time to above (med.,5000)
Sleep(1000)
ControlCommand("Script Manager", ScriptStart, "Turn Left")
#speed/time above
Sleep(1000)
ControlCommand("Script Manager", ScriptStart, "Move Forward")
#SpeedTime
ControlCommand("Script Manager", ScriptStart, "Turn Right")
#Speed/Time slow,9000
Sleep(1000)
ControlCommand("Script Manager", ScriptStart, "Stop")

Halt()

turn right script


:Turn Right
# Left motor forward
SendSerial(D0,38400,127)
# Right motor reverse
SendSerial(D0,38400,128)
Return()

(move forward, left, stop etc. are similar separate scripts as suggested)

Matt

United Kingdom
#22  

It's probably easier if you upload the project file, that way I can look at the whole project as there are some questions just from looking at the script which may be answered if I was to see the whole project (such as, why is there a return() on the third line, and dotted around throughout the script when there are no goto() commands?)

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.

#23  

Hi Rich 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