Australia
Asked — Edited

Script Evaluation

This thread is for the purpose of script evaluation. If you are stuck in writing a script or just can't get it to work post it and it can be checked by other EZ-B users. It can also be used for the sharing of a script that you believe would be particularly useful to others. Remember to include a breakdown of all the parts of your script.


ARC Pro

Upgrade to ARC Pro

Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming

Australia
#1  

I have been trying to work on movement equivalent of the Colour Found Script in the Camera box whilst DJ is making a real one. Here is what I have come up with.

ControlCommand("Sleep Script", ScriptStop) ControlCommand("Port Shutdown Script", ScriptStop) ControlCommand("Restart Script", ScriptStart) ControlCommand("Camera", CameraMotionTracking) WaitForServoMove(D4) Say ("Movement Detected")

"Sleep Script" is the script which "switches off" my robot and "Port Shutdown" is one that starts a shutdown of all the ports. "Restart Script" is the script that reverses what these scripts have done. I have allocated D4 as my head servo and the servo that will rotate to follow movement. If I have started the Camera Motion Tracking will it say "Movement Detected" when the head has moved? This may sound stupid but I am new to this.

Australia
#2  

I also have a variation.

ControlCommand("Sleep Script", ScriptStop) ControlCommand("Port Shutdown Script", ScriptStop) ControlCommand("Restart Script", ScriptStart) ControlCommand("Camera", PauseOff) WaitForServoMove(D4) Say ("Movement Detected")

This uses the "ControlCommand("Camera", PauseOff)" instead of "ControlCommand("Camera", CameraMotionTracking)." I am not sure which varitation is more correct. Or is it even "ControlCommand("Camera", CameraMovementTrackEnable)."

Australia
#3  

What a sad thread. I thought this would be really popular

PRO
Synthiam
#4  

I must have missed this thread. It's done right!

I do that with the wall-e, for example. When things like "Dance Please" are said, the top of the script Pauses the speech recognition, pauses the personality generator, and then does its action. When the action is done, it restores everything by calling the INIT script.

You did good :)

Australia
#5  

Thanks. It's good to know I am on the right track. I would hate to write hundreds of lines of code and find that it is all written incorrectly

PRO
Synthiam
#6  

If it works, there is no wrong way. I've designed the scripting and control model so that you can be creative, but not break anything. Meaning the number of configuration options and control interaction is limitless but if it works, it's right :)

Australia
#7  

That could be the new motto for ARC. "If it works, it's right".

#8  

I have a robot that uses the front wheel as both drive wheel and steering wheel. One servo rotates the wheel while a dc motor turns the wheel either forward or reverse. This is an old Hero Jr. robot from the 80's.

Both controls are attached to a mobile Movement Panel with right, left, forward, back and stop buttons. All the functions work...sort of. The robot moves forward and backwards fine, but to turn, I rotate the servo and then have to move the motor forward for a short burst to turn then stop and center everything again. The script I created does not actually do this but turns the robot in circles and I am not sure why.

ServoSpeed(d0, 3) #Rotate the servo... Servo(d0,130)

Rotate the robot...

repeatuntil($second = 2) Set(d1,Off) Set(d2,On) endrepeatuntil #Center the wheels and stop. Set (d1, Off) Set (d2, Off) Servo(d0,93) $TrackBarValue=90

The RepeatUntil does not seem to loop for 2 seconds...so I am assuming that $second means something else?

I appreciate any help someone could give me to get started...

Thanks, Greg

#9  

$second doesn't have a value that you can use that way, that's why... You don't need to use it anyway just use the sleep command as below...


ServoSpeed(d0, 3)
#Rotate the servo...
Servo(d0,130)

# Rotate the robot...
Set(d1,Off)
Set(d2,On)
sleep(2000) #pause for 2 seconds

#Center the wheels and stop.
Set (d1, Off)
Set (d2, Off)
Servo(d0,93)
$TrackBarValue=90

#10  

Just to clarify why $second isn't working. It is not the number of seconds from the time the step is hit, it is the seconds of the current time. ie, if it is 8:12:24 am, then $seconds with be = 24 ($hours will be 8 and at minutes will be 12)

So what your script was doing was executing the action for up to a minute depending on when you started it, until it was 2 seconds after the current (next) minute.

Alan

#11  

Richard / Alan, Thank you for the answers! I totally misunderstood the function of $second (sigh) and now I get how that works and will test with Richards method of using the delay (sleep xxx).

Just as an aside, do you suppose that is the best way to program rotation on this? I cant imagine I am the first to try and use a robot that was not differential steered?

Thanks, Greg

#12  

@Steve G used a steering wheel separate from his drive wheels in his K-9 project.

You might find details looking in his project showcase here: https://synthiam.com/Community/Questions/6837

Or searching his forum history: https://synthiam.com/User/steve-g/ForumPosts

Alan

#13  

Alan, That K-9 project looks great! Thanks for pointing me towards it. I am curious how @Steve G worked out his steering.

I will try a few things tonight and post my pics somewhere up here on my Hero Jr. Status.

Thank you! Greg

#14  

Steve has been dealing with some family issues and hasn't commented on the forum in a while, but I will drop him an email and point him to this thread.

Alan

United Kingdom
#15  

@Alan.

Hey buddy. I got you email. I'll shoot you one off back shortly. :)

@GregSS.

After reading Alan's email, and reading the thread, I'll see if I can offer some help for you. I will write two posts to help make things a bit clearer so I will take you through K-9's drive setup with script examples first, then hopefully give you some simpler script examples using your project using your port details. (Forgive me if things seem as clear as mud, lol, its been a while since I've been here writing anything so I'm a bit rusty).

Just to explain, K-9's drive setup is a two rear wheel drive system, with an freewheeling (un-powered) front steering wheel which sits on a bearing that turns using a 180 servo. The forward body weight is supported by a Lazy Susan bearing which takes all of the weight so there's no strain on the servo itself. If you have watched any of the K-9 showcase videos, you will also see his head move into the direction he turns (which also is a good visual indicator for which way the steering wheel is facing). The servo that moves the head is linked via script to the steering servo and works under the same principles explained below. The steering system that I have set up has the best of both worlds... steer then move, or steer AND move.

User-inserted image

Above is a screen grab of K-9's mobile interface control. As you can see, there are "Turn Right" and "Turn Left" buttons which steers the steering wheel left or right without drive movement, with "Turn Right" and "Steer Centre" centering the wheel for forward movement.

Above the left and right buttons, you will also see "Forward Right" and "Forward Left". These buttons will steer in the chosen direction and move the drive wheels forwards simultaneously, which I believe is what you're after. After the desired turning position is reached, I can either press "Forward Right" or "Forward Left" button a second time which will now stop the drive motors and centre the steering. Or, I can simply press "Steer Centre" which will centre the steering, but continue to power the drive wheels so he will now steer and drive in a straight line. Two quick taps of the forward or reverse buttons, and K-9 will stop. What you could do here is to add a "Stop" button to you mobile control.

Anyway, here's how my scrips are set up for turning while moving.

First off, I added an Init script to my EZ-B Connection control on ARC...

Connection INIT script.

#Initializes the press ON and press OFF button actions on mobile interface control.
$pressed = 0

Then I added a Custom Movement Panel, then opened the config menu to add the following scripts...

Custom Movement Panel script for "Right".

#Drive and turn right at the same time.

#Steering Servo
servospeed(d12,0)
servo(d12,135)
#Head servo
servospeed(d19,2)
servo(d19,20)
sleep(2000)

#Drive wheels
Set(D1, Off)
Set(D3, Off)
PWM(D0, 40)
PWM(D2, 40)

Custom Movement Panel script for "Left".

#Drive and turn left at the same time.

#Steering Servo
servospeed(d12,0)
servo(d12,55)
#Head Servo
servospeed(d19,2)
servo(d19,120)
sleep(2000)

#Drive motors
Set(D1, Off)
Set(D3, Off)
PWM(D0, 40)
PWM(D2, 40)

Custom Movement Panel scripts for "Stop".

#Stops drive movement and returns steering to center position.

#Drive motors
Set(D1, On)
Set(D3, On)
PWM(D0, 0)
PWM(D2, 0)
sleep(1000)

#Steering servo
servospeed(d12,0)
servo(d12,92)
#Head servo
servospeed(d19,2)
servo(d19,82)
sleep(1000)

The next thing was to add and configure the mobile control. I added three image buttons for Forward Right, Forward Left and Steer Centre, then added the following scripts to each of the corresponding buttons...

Mobile interface controls for Forward Right.

#Turn right while moving.
if (!$pressed)
Right()
$pressed = 1

ELSE
Stop()
$pressed = 0

endif

Mobile interface controls for Forward Left.

#Turn left while moving.
if (!$pressed)
left()
$pressed = 1

ELSE
Stop()
$pressed = 0

endif

Mobile interface controls for Steer Centre.

#Steer Centre while moving or while stopped.
servo(d12,92)
servospeed(d12,0)
servo(d19,82)
servospeed(d19,2)
sleep(1000)

Once everything is saved, EZ-B connected to ARC, to control K-9 using just the three buttons mentioned above I can press Forward Right once, and he will turn and move right. pressing Forward Right a second time and he will stop and steer centre (same for Forward Left. Or I can press Forward Right once, and he will turn and move right, then i can press Steer Centre and his steering will return to centre, but still move forwards. This is where you may want to add a "STOP" button to your mobile control and script it to press once and override all movement.

The next post will be using something similar to the above, but simplified and using the information in the script you posted...

United Kingdom
#16  

Here's a few script examples using your projects port details using the controls I use mentioned in the previous post.

First off, add an Init script to your EZ-B Connection control on ARC...

Connection INIT script.

#Initializes the press ON (start) and press OFF (stop) button actions on mobile interface control.
$pressed = 0

Then add a custom control panel, open the config menu, and add the following...

Custom Movement Panel script for "Right".

#Drive and turn right at the same time.

#Rotate the servo Right (or left)
ServoSpeed(d0, 3)
Servo(d0,130)

#Drive wheel
Set(d1,Off)
Set(d2,On)

Custom Movement Panel script for "Left".

#Drive and turn Left at the same time.

#Rotate the servo Left (or Right)
ServoSpeed(d0, 3)
Servo(d0,50)

#Drive wheel
Set(d1,Off)
Set(d2,On)

Custom Movement Panel script for "Stop and Centre".

#Stop drive motor and centre steering.
Set (d1, Off)
Set (d2, Off)
Servo(d0,93)

Script digital ports D1 and D2 or forwards and reverse movements in the custom movement panels. In the mobile interface control, add three buttons for steer left, steer right and stop motor/centre steering, then configure the buttons with the following scripts...

Mobile interface controls for Forward Right.

#Turn right while moving.

if (!$pressed)
Right()
$pressed = 1
ELSE
Stop()
$pressed = 0
endif

Mobile interface controls for Forward Left.

#Turn left while moving.

if (!$pressed)
left()
$pressed = 1
ELSE
Stop()
$pressed = 0
endif

Mobile interface controls for Stop/Steer Centre.

#Steer Centre and stop.
Stop()

Then you can add forward and reverse buttons.

Once saved and the EZ-B is connected to your ARC project, you should have the same kind of control mentioned in the previous post. Of course, you don't have to use the $pressed = 0 (Push On" "Push Off) mobile button idea, and you could simply use the the scripts I've used in the custom movement panel, and use the scripts directly in the mobile buttons. I like to use the $pressed variable in the mobile interface because it can sometimes save on adding buttons, for example a "On" button and an "Off" button where using the $pressed variable makes just one button have two uses.

Anyway, have a play around and I hope the info I provided will help you Greg, but although I'm not back on the forum properly yet, I do monitor the boards from time to time so if you have any further questions, let me know and I'll see if I can help further. If I'm not around, there are plenty of great guys here as you've seen already who will be able to help or advise.

good luck matey. :)

Steve.

#17  

Wow Steve. That was impressive. The rust rubbed off quickly. Miss you around here. Hope your doing OK.

#18  

Steve, What can I say, but...Thank you very much!

I understand what you worked out there and I like the idea of the $pressed variable to have fewer controls and more functionality in them.

I am working out the bits you outlined now and am having great results! I have the forward, reverse and right and left turns working (the timing was a little different due to my motor), with some experimentation on how long it took to turn the servo and then turn the bot.

I will be working on the rest tonight!

As soon as I figure out how to post the pictures of the project, I will update this thread with the link to the whole build.

United Kingdom
#19  

@GregSS.

You're more than welcome and hope you find the solution you're looking for. It'll be great to have a look at what you're working on... sounds like a fun project. What you could do is start a new thread and tag it as a "Project Showcase", then after you've taken photos, use the "Choose File" and "Upload File" tabs to upload your photos from your computer or phone, then put your pictures up on the forum for all to see.

@Dave.

Hey buddy. Hope you're keeping get well and B9 is coming along nicely. Yeah I miss you guys too. It's been a rough few months and things are still pretty hectic now with lots to sort out, still but I'll hopefully be back on the forum on a more regular basis soon. :)