Another reason why my loyalties are shifting from Basic Stamp to Arduino

I was debugging some code on the Basic Stamp Autopilot this evening, trying to figure out why the navigation function isn't working right. The debug results were mystifying--variables that should have been +-128 were giving crazy values like 64526.

And then it hit me: The Basic Stamp doesn't really know the difference between an unsigned word variable (all 16 bits used) and a signed word (first bit is the +/- bit). You can adjust your debug displays to compensate for that (using SDEC --signed decimal-- format rather than DEC), but in other cases you just need avoid signed integers. For instance, it can't do comparisons ("if x < y") with signed variables when the value is less than 0. That's because it sees something like -30 (which should be less than 0) as 65432 [or whatever], which is more than 0.

I'm sure there's some clever work-around on this, but that explains why all the math is funky in the navigation routine--I ported it over from C, where variables are handled properly, and forgot that Basic Stamps can really only handle operations on positive integers correctly.

I think the solution is probably to add 256 or something to all data so that all the results of our calculations will be in positive territory, and then subtract 256 at the end to make it all right again, but I'll have to work it out on paper before I can be sure.

If I were to do the Basic Stamp autopilot all over again, I'd do it on the Arduino, which has no trouble with proper variables, floating point math and everything else (in fact, I may port it over to Arduino soon). I know Basic Stamp is a great hardware platform for learning embedded programming, but its limited variable space and bare-bones programming language is showing its age.

For those of you who have been frustrated with my Basic Stamp code, my apologies. It's going to take me another week or two to fix this.

Views: 2012

Comment by Harrison Jones on April 30, 2008 at 5:59pm
Perhaps you might take the new parallax product, the Propeller for a Spin?

hehe.. If you are dropping the Stamp you should consider trying out the propeller. I myself am using it and it's very nice. I've run into the problems you are having on the stamp and I completely understand your frustration.

3D Robotics
Comment by Chris Anderson on April 30, 2008 at 6:04pm
Oh, for sure. We use the Propeller for our high-end autopilots (and it's the core of the awesome new AttoPilot, which will be out soon). But it's a bit daunting for newcomers, which is why we still want an entry-level embedded system.

I'm thinking of shifting our beginners system to Arduino for the reasons above, but I have a call in to Parallax to see if there's anything they can tell us about the future of Basic Stamp that can change me mind

100KM
Comment by wayne garris on April 30, 2008 at 7:26pm
hey chris servo magazine had a great article that featured the stamp being used to navigate an electric kids car you might look at that code. ive messed with the propeller but quit frankly i dont think its all its cracked up to be . the problem is that you have 8 procecers churning away at 80mhz but things can get bottle necked at the cog witch has a very slow operating freq . and if i wanted to learn assembly there are much better platforms .If you are interested i am going to be test flying my new basicx AP this weekend i think it would be a great platform for beginers . i tell you what i will start a forum and post the code for it but i would like to test fly it first to make sure it works as intended.basicx is pretty sweet 32 bit , 60mhz 800 bytes ram (400 persistant bytes) and its very simple to code very close to vb.and oh ya it does floating point veriables making complex math like navigation and PID loops easy. ive sim'd a 747 flight from jappan to seatac with no prob.and ive made easy set up .txt files that make it very easy to get waypoints tune the PID and adjust other things like how close to get to WP before you go to the next WP .i will post more info soon got to go

3D Robotics
Comment by Chris Anderson on April 30, 2008 at 7:52pm
Wayne,

Sounds very cool. Can you report on the first flight (with pictures!) in a blog post here when you're done?

Thanks!

Chris

100KM
Comment by wayne garris on April 30, 2008 at 10:01pm
sure

100KM
Comment by wayne garris on April 30, 2008 at 10:53pm
GPS_Guided_Car.zipok here is the gps car code i was talking about
Comment by Ken Gracey on May 1, 2008 at 9:14am
Hello Chris,

I received your telephone call but thought I'd answer the questions about the BASIC Stamp on the discussion forum. The BASIC Stamp is ideal for first-time programmers and it's certainly not the best tool to use for every job, nor do we claim it to be. The issue you explained above requires you to use integer math and manage your variables closely.

The BASIC Stamp product line will continue to be developed by Parallax. Most of the improvements we make to the product line pertain to documentation, operating speed and memory, and the addition of commands. You won't be seeing a floating point library built into the BASIC Stamp. We will continue to provide detailed and friendly add-ons and documentation for the BASIC Stamp, particularly in education. For UAV uses you'd probably also be interested in sensors we offer, like GPS, temperature, accelerometers, etc.

But if you want to have true simultaneous processing with another high-level language, my suggestion is to use the Propeller. You seem to already know that processor so I'll skip listing the specifications. We aim to make the Prop very easy to use by publishing our educational tutorials (see Propeller Education on this page http://www.parallax.com/tabid/442/Default.aspx). The forums supporting the Propeller are very active at http://forums.parallax.com/forums/default.aspx?f=25. Supporting the growth of the Propeller is a big priority for Parallax and we back our position by responding to customer requests. In this case, you've got a complete floating point library to use. There's also a BS2 library for the Propeller in case the user wants to continue using something they've already learned.

We'll also support your investment of time into the Propeller. I'd be pleased to provide $500 of free hardware to the DIYDrones group. You could distribute it as you wish. Let me know if that is of interest by e-mail to kgracey@parallax.com.

Thanks, Ken
Comment by Adam French on May 6, 2008 at 9:56am
What advantages does propeller have over dividing the work between a few Atmega's. I'll confess, I'm really just reluctant to learn Spin. A day doesn't go by when someone doesn't suggest I pick up another language.

T3
Comment by Krzysztof Bosak on April 23, 2009 at 3:03pm
Adam French,
The advantage of Propeller is that the interprocess communication is much more reliable and much faster inside Parallax than between Atmegas. The disadvantage is that when propeller hangs, you're done, everything hangs.

Admin
Comment by Thomas J Coyle III on April 23, 2009 at 3:17pm
Chris,

I have worked with both the Parallax BS2 Stamp and the Propeller.

I had a similar problem with signed integers like you did. My work around was to test for bit 15 positive and set a flag to indicate a negative number. I would then take the absolute value of the negative number, perform whatever function was necessary and then convert it back. Most of my computational functions were simple and not as complex as yours are, however it was still a pain in the butt to work with.

Parallax has finally commissoned a C compiler for the Propeller, but I still think that they need a BASIC compiler for those of us who do not want to program in Spin or C.

Just a thought.

Regards,
TCIII

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2014   Created by Chris Anderson.

Badges  |  Report an Issue  |  Terms of Service