loading
 
Setting arduino variables
Alan Coggins from Australia  [32 posts]
11 year
I still think I must be missing something very basic here... I couldn't get my Spykee to work, and now I can't make any headway with linking the Arduino module to a variable. It's all fine when I control the servo with the slider, but as soon as I try and do anything that involves setting a variable, my servo is useless.

This is the most basic example: I have used the set variable command, then followed with the Arduino module. It doesn't matter what value I use for servo_setting, and what min/max I use in the Arduino module (and I've tried everything!), the servo just goes full to one side and stays there. For example, in this example it says it's at 200 and the range is 50 - 500 so it should be nearer the middle.

By the way, I've tried setting the range to 0 to 179 and 1 to 180 but when I
save, close and reopen, the limits always revert to 0 and 1. ????

 
Anonymous 11 year
Alan,

Best you include your robofile that we can fix things for you.

The image shows you've adjusted the range from 50 to 500 which will NOT work with the Arduino and any servo we know of. The range is there so that most people can reduce the range not to destroy their servos ... your numbers are way off.

The min/max do not change the range of the number... they just limit its value. Thus if you are working with a number at 200 you cannot just change the min/max ... you MUST scale the 200 to fit into that range. For example, if you have a number that ranges from 0 to 320 (normal width of an image) and want to use it in an Arduino you would need to multiply that by 2000 divide by 320 and add 500 to produce

var = ((var * 2000)/320)+500

or just use the scale variable module to get that into the right range.

For you, I'd just ignore the min/max settings and use the scale variable module to get the number you are working with to fit into that range.

FYI, the numbers 500 and 2500 actually translate to the servo pulse widths ... read more about that at

http://www.roborealm.com/articles/moving_motors.php

Think, when I move the slider and it works what are the min and max numbers ... that's what the variable's range needs to fall into too.

STeven.
Alan Coggins from Australia  [32 posts] 11 year
Ahh... now I get it. I was trying to set the Arduino module min/max to something that would suit the servo. I should have been doing it the other way around - scaling the variable to suit the existing min/max.

Thanks Steven.
Anonymous 11 year
Correct. That will make things much better behaved!

Cheers,
STeven.
Alan Coggins from Australia  [32 posts] 11 year
Hi Steven - I have now worked out why I am having so many problems!!

If you look at my thread on Spykee you'll see that I discovered that any motor variables starting with a '1' are being ignored in that program. And now I've found that the same thing is happening with my Arduino programs. I can get a servo to pan or tilt as long as the values I set are in the range 500 to 999 and 2000 to 2500.  Any servo setting in the range 1000 to 1999 are just not being recognised.

I have absolutely no idea what is going on... I hope you might be able to advise something.

Alan Coggins from Australia  [32 posts] 11 year
Here are some screen shots. As you can see, if I set tilt = 79 then the modified variable and available TILT variable both correctly show 993.75. When I make tilt = 81 the modified variable is 1006.25 but available variable drops to minimum of 500. It stays at 500 until I get it up over 2000 as in third example, when it all works correctly again.

   
Anonymous 11 year
Alan,

We detected an issue that may be causing that behavior. Can you download the latest version and see if that helps with the ignoring the '1' value?

Thanks,
STeven.
Alan Coggins from Australia  [32 posts] 11 year
YAY!! The new version has fixed the problem. Working now for Arduino and Spykee. I'm very relieved... I was starting to think that I was a complete idiot because I couldn't even get the simplest thing to work!

Thanks for your help Steven. I'm really looking forward to playing with the program now.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index