Case Statements in Atom Basic?

Anyone know a way to do case statements (like in C) in Atom Basic?

Switch(var)
   {
   case a:
    code...
   break;

   case b:
     code...
   break;
   }

Alan KM6VV

You could use If…Then…Else statements. Besides that I don’t think there’s anything else.

BAP has a BRANCH command…

BRANCH index, [update1,update2,update3,update4]

if that does anything for ya.

Here’s the info on BRANCH from the manual, if it helps:
basicmicro.wikia.com/wiki/MBasic … nes#BRANCH

Branch!

Thanks Beth. I thought there was something in BASIC that would do a similar job.

Atom Basic. It’s not your father’s Dartmouth BASIC.

Alan KM6VV

yeesh not only did I post 2 minutes before but I gave a code example. :unamused:

:laughing:

Yeeees, but I posted a Wiki link. 8)

Just ignoring the fact that I only knew what to link to after I read your reply, of course. :laughing:

Well, Thanks to both of you! Sometimes my mind goes blank when I’m working in a language I don’t use as often. OK, so it goes blank other times as well…

Of course I’ll have to use GOTOs to get back, not like the more in-line case statement of ‘C’. but I can work with it.

If you’re curious Eddie, I’m trying to implement a state machine for a Quad Gait. And I found this video to be an excellent study:

youtube.com/watch?v=wt_k2aoF6l0

Alan KM6VV

I think that, um, well…

Sigh… My mind went blank. :frowning:

just messing around anyway, but y’all probably knew that.

what I don’t get is why everybody goes for the komodo dragon approach to designing a quad but fails to include 4 things that factor significantly into its motion. first, no tail. second, no head. both of those have significant mass and 2 or mor axis of movement. third, feet are not a point contact on the ground but have at least 2 axis of ability to apply force. and fourth, there is a roll component along the long axis in the gait that allows a significant shift of cg from left to right with very small movement laterally.

most quadrapeds in nature are more like dogs and horses and less like man eating lizards… but everybody keeps trying to make half a lizard walk like something recognizable. I don’t get it. :unamused:

Hard to say. Maybe just starting small? I’ve mentioned it before; I’d really like to do a cat or dog. KÃ¥re Halvorsen (Zenta) has a 'quad design that I’d like to try out. OK, no head or tail, but should be able to do a little body roll.

It’s much easier to mount servos vertically between two plates, which lends it’s self most readily to a lizzard. KÃ¥re has departed from this of course. Jim showed a leg with a horizontal coxa servo. I think the plate that enabled it bolted up to either a hex or octo chassis. but that’s still not a sagittal plane, as a dog/cat/horse would need.

I think the calcs get a little harry if greater then 3DOF. Matrix calculations might be more in order. I suppose they can be done in BASIC.

But I’d be happy just to get a state machine-driven gait generator running. I’m temped at this point to do it in C first.

Alan KM6VV

I believe I’ve found an example of a “case/switch statement” from the Phoenix code (Atom Pro).

[code]SELECT gaitCode ’ depending on gaitCode
CASE $00 ’ Adjust Legs if 0 is selected
ptrEEPROM = Adjust
rightRamp = Fast
leftRamp = Fast
GOTO Walking_Engine

CASE $01
  ptrEEPROM = LTurn                 ' Spin left
  rightRamp = VeryFast              ' Assign ramp to
  leftRamp = VeryFast               ' left and right sides
  GOTO Walking_Engine

CASE $02
ptrEEPROM = RTurn ’ Spin right
rightRamp = VeryFast
leftRamp = VeryFast
GOTO Walking_Engine
ENDSELECT
[/code]

Much better way to code then if…then…else, although I’m still not finding it in the pro manual.

Although I do miss the curly brackets…

Alan KM6VV
sequence, iteration, alternation

But that’s in C. You were talking about Basic, right?

The Phoenix code is not written in C.

Looks like Xan found an undocumented feature. :stuck_out_tongue: Weird.

I can’t find or figureout things that ARE documented. :laughing: :open_mouth:

oops. my bad. :blush: I guess I just assumed it was in C.

why not ask Acidtech. wouldn’t he know something about this?

I did found some undocumented features…
But the switch/case function wasn’t in there. :wink:

The shown code isn’t mine either.

Xan

My Error! It is in Jonny’s Quad walker BAS code.

'-------  QuadWalker] -----------------------

'---- [Gait Selection] ---------------------------------------------------
Parse_GaitCode:                         ' Assign gait parameters

Still a nice find!

Alan KM6VV

Um… What processor was this code written for? Atom Pro basic does NOT recognize select as a command. :unamused: Just tested it myself.

I hadn’t had a chance to test the instructions. Jonny had a collection of programs that he graciously shared with me. I don’t recall if he specified that it was a different BASIC. No doubt it is.

But it does point out the desirability of a CASE-type instruction in BASIC.

Sorry for mislead. Perhaps It’s something that could be added to Atom Pro?

Alan KM6VV