Sienna's stumbling through Basic thread

Since it seems no one has been able to help me get an account on Basic Mirco’s forums, I am relegated to having to post here. :angry:

This is my first night playing with the Atom Pro, and I can’t even get basic things to work.

I got off to a decent start, “Low P12” turns the LED on, and “High P12” turns it off. Great. Now, because I never trust myself to remember what state turns things off and on, I want to abstract those into constants. So, here is my code right now:

[code]Main
; tailored to the BotBboardII
i var word ; variable
red con P12 ; red is on pin 12
yellow con P14 ; yellow is on pin 14
green con P13 ; green is on pin 14
ledoff con 1 ; make a high state off
ledon con 0 ; make a low state on
dird = 1 ; set 12-15 as outputs.
outd = 1 ; set leds off = high.

Loop
for i = 1 to 10
yellow = ledon
pause 200
yellow = ledoff
pause 100
next
Goto Loop
End
[/code]

Now, this code won’t compile, and just sends up tons of errors. And of course, Basic Micro in some fit of wisdom decided that it would be unwise to let me copy the entire error window at once, reducing me to many copy and paste operations. Nor does the editor seem to support turning on line numbering, or if it does I have not yet seen that option despite looking for it.

Error: FILE E:\DOCUMENTS\BCVBCVB.BAS(LINE 14) : [TOKEN P14] : Unknown Command Error: FILE E:\DOCUMENTS\BCVBCVB.BAS(LINE 14) : [TOKEN =] : Unknown Command Error: FILE E:\DOCUMENTS\BCVBCVB.BAS(LINE 14) : [TOKEN LEDON] : Unknown Command Error: FILE E:\DOCUMENTS\BCVBCVB.BAS(LINE 15) : [TOKEN PAUSE] : Compiler error 102

I don’t even begin to know where to look. I am running 8.0.1.3, on Vista x64.

Thanks for the help.

(p.s., why for the love of all that is good and holy is the semi-colon used for comments? everyone knows that // and /* */ are comment markers, semi-colons are statement ending markers! This is the standard for C, C++, Objective C, Java, Javascript, you name it! Why break that!)

AcidTech is the one who could answer this one…

If I counted my lines properly, it is complaining about the line:
“yellow = ledon”

The problem is that you are trying to assign one constant to another constant. I understand what you are trying to do, but I am not sure how to do it in basic! What you would really like is the equivelent of the #define in C, but I don’t know of an equivelent way in basic.

Sorry

Actually using semi-colon as both end of statement and to allow line by line commenting predates any of the newfangled languages you apparently identify with. This is from assembly language programming, the mother of them all. :wink:
:mrgreen:

The only way I could think of that might work is to maybe do it in a subroutine or subroutines. Maybe something like:

[code]…
Loop
for i = 1 to 10
gosub SetLEDOn[yellow]
pause 200
gosub SetLEDOff[yellow]
pause 100
next
Goto Loop
End

ledPin var word
SetLEDOn[ledPin]
low ledPin
return
SetLEDOff[ledPin]
high ledPin
return
[/code]
Obviously this added a little overhead, but at least you no longer had to worry if it was high or low… And it compiles!

Pins can be accesed either using commands(eg high/low etc) or by pin variables. There are two kinds of pin variables. Direction and state. Direction variables set the input output ness of a pin. State variables set or get the high low state of a pin

So you set the pin you want to use as an output and then set it’s state to the desired level.

dir14 = 1 ;set pin as output out14 = 1 ;set pins output state high

If you replace your constants with their values in your original code it reads as:

Loop for i = 1 to 10 p14 = 0 pause 200 p14 = 1 pause 100 next Goto Loop

Which doesn’t make any sense. You are trying to set a constant = to another constant.

If however you chaneg your definition of yellow to:

yellow var out14   ;make yellow an alias of the out14 variable

Then you code looks more reasonable:

Loop for i = 1 to 10 out14 = 0 pause 200 out14 = 1 pause 100 next Goto Loop

Then our final code, with constants would look like this:

[code]Main
; tailored to the BotBoardII
i var word ; variable
red var out12 ; red is on pin 12
yellow var out14 ; yellow is on pin 14
green var out13 ; green is on pin 14
ledoff con 1 ; make a high state off
ledon con 0 ; make a low state on
dird = 0xF ; set 12-15 as outputs.
outd = 0xF ; set leds off = high.

Loop
for i = 1 to 10
yellow = ledon
pause 200
yellow = ledoff
pause 100
next
Goto Loop
End [/code]

Note that dird and outd are nibble sized variables. Each bit in the nibble specifies each of the four pins they access.

To me “p14 = 0” makes entire sense, because your “high” command can use p14 and it makes sense there. (Think of it as a newbie… not within your syntax limitations. You are used to saying “out14 = 0”, but when your first example references P14, I expect P14 to be a pin that I can set to zero.) But if Aliases are the way to do it, then aliases I will use! :stuck_out_tongue:

Onward to the next question! While that was being answered, I was… charging up my old receiver nicad… I mean playing with servo commands!
(bolded lines are the debug, below, and underlined is the math that is prolly screwing up.)

[code]ENABLEHSERVO

Main
; tailored to the BotBboardII
i var word ; variable
servopos var sword
DIRC = 15
DIRD = 15
outD = 1

;HSERVO [P8\0\0,P9\0\0,P10\0\0,P11\0\0]
pause 1000

ControlLoop
out14 = 0
maxturn con 12
travellimit var word
travellimit = maxturn * 500
for i = 0 to maxturn
out13 = 0
servopos = -(travellimit) + (i * 1000)
debug [dec i," ", dec servopos, 13]
;HSERVO [10\servopos\2]
pause 25
out13 = 1
pause 275
next
out14 = 1
out12 = 0
for i = 0 to maxturn
out13 = 0
servopos = travellimit - (i*1000)
debug [dec i, " ", dec servopos, 13]
;HSERVO [10\servopos\2]
pause 25
out13 = 1
pause 275
next
out12 = 1
goto ControlLoop
End[/code]

Cut and Pasting the debug window:

0 6000 1 5000 2 4000 3 3000 4 2000 5 1000 6 0 7 4294966296 8 4294965296 9 4294964296 10 4294963296 11 4294962296 12 4294961296 0 4294961296 1 4294962296 2 4294963296 3 4294964296 4 4294965296 5 4294966296 6 0 7 1000 8 2000 9 3000 10 4000 11 5000 12 6000

So, when ‘servopos’ is positive, the equations all seem to work out. But when servopos is negative, something dastardly is going on.

Looking at just one of the lines:

servopos = -(travellimit) + (i * 1000)

I interpret that to be:

  1. take “travellimit” (in this case an unsigned word set to 6000),
  2. make it negative (so we are now working with a signed variable equal to -6000)
  3. and add some number of thousands onto it.
    Steps 1 through 3 result (in my mind) into a signed word, which matches servopos’s type.

Yet clearly I am making an assumption that Basic doesn’t… anyone help?

(The hservo commands are all commented… because apparently during debug mode they don’t work and all the servo’s twitch constantly)

In your example, both variables i and travellimit are defined as word (ie unsigned). So the question would be when are the values sign extended. In C you would probably need to do some casting to make this work properly. In this case it would probably work if you make travellimit and i be of the type SWORD.

Kurt

I tried making everything a sword, and no go… same deal as before.

Oh, and apparently I forgot to say earlier, I am using 8.0.1.6 atm.

One thing I forgot to mention in my previous post, is that on the debug statement, you are using the DEC modifier to output the numbers, which is unsigned. Try SDEC to output signed numbers.

Kurt

Debug doesn’t seem to like sdec, gave me a compile error.

I vastly simplified my program, just to see if I can get the servos working the “easy” way…

[code]ENABLEHSERVO

Main
; tailored to the BotBboardII
i var sword ; variable
red con P12 ; red is on pin 12
yellow con P14 ; yellow is on pin 14
green con P13 ; green is on pin 14
ledoff con 1 ; make a high state off
ledon con 0 ; make a low state on
servopos var sword
DIRC = 15
DIRD = 15
outD = 15

HSERVO [P8\0\0,P9\0\0,P10\0\0,P11\0\0]
pause 1000
ControlLoop
HSERVO [P8-12000\255,P9-12000\255,P10-12000\255,P11-12000\255]
pause 2500
HSERVO [P8\12000\255,P9\12000\255,P10\12000\255,P11\12000\255]
pause 2500
goto ControlLoop
End[/code]

There is some extra declarations that aren’t used there.
I am pretty sure that the code as written should be swinging servos to their extents, yes?

Well, I am not sure what is happening:
youtube.com/watch?v=HMtY_rqTG3c
The Servo in the upper left of the video, is a Futaba S3004, plugged into channel 8. In the video, it is doing what the code is I think doing.
Next in line is another S3004, on channel 9, and then a S3151 on 10, and another S3151 on 11. They are all powered by a 4 cell reciever pack. (Futaba was just what I happened to have around)
In the video though, can anyone explain what the other three servos are doing??

AcidTech would be much better here! However I think you said you are using the version 8.0.1.6. I believe that one had problems with HSERVO. You might try 8.0.1.7, which is mentioned in the thread: lynxmotion.net/viewtopic.php?t=3473

However, things I would check on your BotBoardII do you have the right jumper VS for the power of the servo group 8-11.

Also I have a tendancy to skip P9 for a servo as it is connected to the speaker on the BB2 (unless you removed that jumper).

I don’t see anything obviously wrong here. If I were doing the test like you have, I might put in calls to HSERVOWAIT. Something like:

ControlLoop HSERVO [P8\-12000\255,P9\-12000\255,P10\-12000\255,P11\-12000\255] HServoWait[P8, P9, P10, P11] pause 2500 HSERVO [P8\12000\255,P9\12000\255,P10\12000\255,P11\12000\255] HServoWait[P8, P9, P10, P11] pause 2500 goto ControlLoop

:desk

Yep, upgrading to 8.0.1.7 solved it. Now the servos are all doing what they are supposed to do! I have a hard time staying up to date in terms of IDEs it seems.

And yes, I did remove the speaker jumper.

Thanks for the help Kurte!

I have been asking for this for a long time now. We need to be able to copy and paste the contents of the entire build window where errors come up.

8-Dale

The build window is a listbox, not an edit window. Grabbing multiple lines is a pain but it isn’t going to change anytime soon. Each line is clicakble. This allows the error messages to be double clicked to get to the actual line the error is on. We could lose that capability and give you the ability to copy multiple lines. Which would you prefer?

You are welcome… I kept up as I had problems getting my BRAT to work properly on the different IDEs.

As for the error messages, I agree, however I do like double clicking on error messages to go to the actual line. Not sure what the IDE is writen in, but if VB for example, ListBox objects do allow you to select multiple lines, by changing the “SelectionMode” property… But I understand that it may not be a high priority change…

Kurt

It’s written in Visual C++. Yes they do allow that. But by doing so single line double click is no longer functional. A lot of code has to be junked and rewritten in order to check for muliline versus single line double clicking because you enabled multi line select. Also a lot of code has to be rewritten to handle the multiline copy now as well. So it’s a matter of how much time he can spend on a limited use feature when he has a lot of other things that he is working on that will effect a lot more people.

Since you asked what I prefer, I will volunteer my opinion :stuck_out_tongue_winking_eye: (no, I don’t expect anything to change based on my opinion, but hey, I am conceited enough to offer it :smiley:)

I would rather have the ability to copy and paste multiple lines. However, I also want to see the code window get line numbers. (These both go hand in hand)

There are more ways to do the UI as well:

  1. Make the “list box” actions modal: So, if only a single line is selected, a doubleclick takes you to that line. If multiple lines are selected, doubleclicking unselects all but the line that was actually doubleclicked, and takes you there (this is a standard Windows convention, try it in Explorer or similar). Or, if multiple lines are selected, right clicking will allow you select copy from the right click menu.

  2. Just add a simple “copy” button that copies the entire contents of the compile window into the copy buffer.

I’m aware there are many ways to do the UI. The problem is I am unwilling to completely rewrite large chunks of code for, at this point, one or two people. That means that 1 is unlike to happen anytime soon. However 2 is doable and I’ll keep that in mind when I next work on the IDE.