The Applescript examples aren't working for me

Supporting 10.7 and up
User avatar
mparadis
Site Admin
Posts: 609
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: The Applescript examples aren't working for me

Postby mparadis » Mon Apr 21, 2014 1:00 pm

Again, I apologize- I don't have a Mac workstation so it's a little awkward for me to view our applescript examples and API because there's no way to do so in windows. I had a co-worker take a look, and it seems like our applescript libraries don't have a calibrate function. The employee who wrote these libraries and examples hasn't been here for quite some time, so it's easy to forget these things. Either way, the calibrate function is just a matter of convenience, so you can still get your servo working without it.

You can just modify the numbers in the sample program and observe what the servo does. First, make sure the program is in RAW_us_MODE; there should be function that lets you change the servo type to this. You can then go to the part where it tells the servo to go to position 40, and change that '40' to a different number. Just keep changing that number and running the program until the motor seems to stop right at the end of it's range of movement. Then change the number to a higher number and keep adjusting that until you find the servo's high limit. Write these numbers down and whenever you want to move the servo to a certain position, use these two numbers.

For example, if your servo's range is 180 degrees and the minimum position is 20 μs and the maximum position is 200 μs, if you wanted to go to the 90 degree position, you'd want to enter a position value half way between your min and max: (200 + 20) / 2 = 110 μs. If you plan on changing position a lot, you can write a function to do this conversion for you, which is effectively what the calibration function would have done.

dgdg
Phidgetsian
Posts: 10
Joined: Wed Apr 09, 2014 5:44 pm
Contact:

Re: The Applescript examples aren't working for me

Postby dgdg » Mon Apr 21, 2014 6:34 pm

You are being very helpful, and as always I appreciate that. But none of the examples, and nowhere on the internet does it show how to use Applescript to set the servo to RAW_us_MODE.

Here's what I did to attempt to calibrate:

Code: Select all

         repeat
            set myresult to text returned of (display dialog "Enter number" default answer "" buttons {"Continue"} default button 1)
            set the first advanced servo motor's position to myresult
            delay 2
         end repeat


But this didn't work, in fact it didn't move the servo at all (sometimes the servo moves when the program begins, but not consistently), possibly because I'm not in the right mode. Can you tell me how to modify the example Applescript code in PhidgetAdvancedServo2.scpt to set the servo type to RAW_us_MODE?

I'll just buy a bunch of new servos if you tell me which brand will work without calibration headaches.

User avatar
mparadis
Site Admin
Posts: 609
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: The Applescript examples aren't working for me

Postby mparadis » Tue Apr 22, 2014 7:47 am

You should be able to find the function in the API, which can be generated from your applescript editor in File -> Open Dictionary -> PhidgetsOSA. The function should be called something like "setServoType". There should also be a list of acceptable models in there, along with raw mode. If you get any of those servos, you can set the type to that servo to calibrate it.

dgdg
Phidgetsian
Posts: 10
Joined: Wed Apr 09, 2014 5:44 pm
Contact:

Re: The Applescript examples aren't working for me

Postby dgdg » Wed Jun 25, 2014 6:45 pm

I tried all your ideas (which is not to say I'm certain I understood what your ideas were, because I've never used libraries with Applescript before.) Nothing worked. The servo always acts weird (turns right quickly, pauses 10 seconds, turns left slowly, and finally freezes) upon starting the sample program PhidgetsAdvancedServo2 and then the servo won't move again until I bounce the controller's power. So I guess we're back to my earlier question. What Servo model can I buy that will allow me to get this Phidgets controller to work? I'm only going to buy one from your site for starters, because maybe the problem is this Phidgets controller isn't working, so I don't want to throw good money after bad. If I can get one servo to work I will buy many more servos, but so far I can't even get one to work. While I'm not the brightest programmer on the planet, I have been programming for several decades. But sometimes a person just gets stuck. I found "HS 422" listed in the API, so I'll try buying that on this website. But if the sample programs don't work out of the box with that servo, I'll be back here to plead for help again. I don't want to give up on this product until I absolutely cannot get it to work.

dgdg
Phidgetsian
Posts: 10
Joined: Wed Apr 09, 2014 5:44 pm
Contact:

Re: The Applescript examples aren't working for me

Postby dgdg » Sun Jul 20, 2014 6:25 pm

It still isn't working. I even bought a new servo, a HITEC HS 311. You sell lots of HITEC servos on your site. The problem is the same. The sample code provided, PhidgetAdvancedServo.scpt, fails in the same way. When I run the sample program the wheel spins a little, gets stuck, and then the device is no longer usable until I cycle its power. The only theory I have that makes sense is that the sample code is wrong. Until I can see some sample code that works, I can't see how I can make this Phidgets servo to work. Is there any chance you could get an Applescript developer at your company to check the script?

User avatar
Patrick
Lead Developer
Posts: 3049
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: The Applescript examples aren't working for me

Postby Patrick » Mon Jul 21, 2014 10:34 am

Hi,

I've checked the script and it works fine. I think a bit of confusion here is that the example is setting the acceleration to a really low value - this is why the servo moves so slowly. Also, the 'delay 2' between each move isn't really sufficient for some of the moves to complete, so it's not always reaching position. Also, some of the positions are probably out of range for your servo, so this would cause the grinding. The default servo type is for historical reasons set to the odd defaults, but you will probably want to chance this.

I'm not sure if you've had a look at the Applescript documentation. To get to this, you open up the script, then click File->Open Dictionary, then double click PhidgetsOSA.app. Then, click on the 'Phidget Advanced Servo Suite', then click on 'advanced servo motor' - this brings up the servo motor properties. Click on 'servo type' - this is how you set the servo type. servotype is an enum with a bunch of different servos in it. the HS 311 is not in the list, so you will want to calibrate this servo yourself. Setting it to raw us mode is simple:

Code: Select all

set the first advanced servo motor's servo type to raw us mode

For example, you can can an idea of the movement like this:

Code: Select all

set the first advanced servo motor's engaged to false
set the first advanced servo motor's servo type to raw us mode
set the first advanced servo motor's acceleration to the first advanced servo motor's maximum acceleration
set the first advanced servo motor's velocity limit to the first advanced servo motor's maximum velocity
set the first advanced servo motor's position to 1500 --set to a middle position before engaging
set the first advanced servo motor's engaged to true
         
delay 2
set the first advanced servo motor's position to 700 --turn one way
delay 2
set the first advanced servo motor's position to 2300 --turn the other way
delay 2
         
set advanced servo motor 1's engaged to false

Your HS311 servo datasheet states that the neutral position is 1500us, and I just took a typical +-800us on either side for the example.

The Applescript library doesn't allow you to set custom parameters for a servo, so you need to either find a supported servo which is close to yours, or stick with raw us mode, and convert us to degrees youself.

The HS311 looks pretty similar to the HS322HD, so I would try:

Code: Select all

set the first advanced servo motor's engaged to false
set the first advanced servo motor's servo type to Hitec_HS322HD
set the first advanced servo motor's acceleration to the first advanced servo motor's maximum acceleration
set the first advanced servo motor's velocity limit to the first advanced servo motor's maximum velocity
set the first advanced servo motor's position to 90 --set to a middle position before engaging
set the first advanced servo motor's engaged to true
         
delay 2
set the first advanced servo motor's position to 0 --turn one way
delay 2
set the first advanced servo motor's position to 180 --turn the other way
delay 2
         
set advanced servo motor 1's engaged to false

-Patrick

dgdg
Phidgetsian
Posts: 10
Joined: Wed Apr 09, 2014 5:44 pm
Contact:

Re: The Applescript examples aren't working for me

Postby dgdg » Sat Aug 23, 2014 2:09 pm

After 4 months of struggling I finally got it working. Not sure why it started working.

However I still have some new issues. I'll post them in a separate thread.

Tajara
Fresh meat
Posts: 2
Joined: Thu Jan 29, 2015 8:59 pm
Contact:

Re: The Applescript examples aren't working for me

Postby Tajara » Fri Jan 30, 2015 1:09 am

You are funda galaxy s6 being very helpful, and as always I appreciate that funda galaxy a7.


Return to “macOS”

Who is online

Users browsing this forum: No registered users and 1 guest