BasicMicro - Forums

www.basicmicro.com
It is currently Thu Sep 09, 2010 9:17 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Fallentine help thread, Various small issues.
PostPosted: Sun Mar 07, 2010 11:52 am 
Offline
Citizen
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 43
Location: Wisconsin USA
Hardware, Botboard 2, Basic Atom Pro 28-M.

Been gone a while, decided to start using my robot again.
I program mostly from an outdated manual that doesn't seem to be friendly with the new studio, so i'm encountering problems.
That's where you guys come in.

Current problem.
works
hserin 10000000, main,[dec cbot]

Does not work.
hserin 10000000, main,[dec4 cbot4]

I want to send 1 long string, but i want the atom to break up the string into multiple parts
Incoming string 1111222233334444.
Example of intended use "hserin 10000000, main,[dec4 cbot14,dec4 cbot24,dec4 cbot34,dec4 cbot44]
cbot1 = 1111
cbot2 = 2222
ect....

But i cant get it to accept the dec4 or cbot14.
The basic atom manual says it should work.


All my small problems i'll post in this thread.

_________________
If a giant battle mech, steps on your car, and the mech is made of icecream/craft sticks.. That's me inside.
Sorry in advance.


Top
 Profile E-mail  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Sun Mar 07, 2010 1:27 pm 
Offline
Citizen
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 43
Location: Wisconsin USA
Ok this is confusing. Since dec2 cbot2 doesnt work, do i do it this way?

hserin 10000000, main,[dec cbot,dec cbot2]

Send ASCII "1234,5678"

Then it will assign
1234 to cbot, and 5678 to cbot2? Is that it?
Can i send , over a serial line like that?


Another problem, hservo speed
hservo [p1500100]
The manual doesn't say.
Is higher faster or slower? and why does 0 seem to move instantly? Does 0 = the default 255?

Also if i add
hservo [p1100]
Near the top of my program, with the speed set to 100, the servo extends beyond it's full range (possibly damaging the servo) before moving to position of 0.
But if i set speed to 0, it moves directly to the intended position without trying to extend
What i mean is, if i set the speed to 100, the servers kind of "freak out" before moving to their intended positions, but they work properly if the speed is set to 0. Except if the speed is set to zero, they move to fast.

_________________
If a giant battle mech, steps on your car, and the mech is made of icecream/craft sticks.. That's me inside.
Sorry in advance.


Top
 Profile E-mail  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Mon Mar 08, 2010 1:06 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 699
Location: CA bay Area
The "4" doesn't work for input.
For your purposes, if you are inputting four values for each robot, you'd use:
bot1 var word ; a four digit number means a possible value of 9999, so you need a word
bot2 var word
bot3 var word
bot4 var word
enablehserin
(then do hserial setups)
hserin [dec4 bot1, dec4 bot2, dec4 bot3, dec4 bot4] ; each robot MUST receive four digits!
hserout [dec bot1, ", ", dec bot2, ", ", dec bot3, ", ", dec bot4, 13, 13] ; print out four values, followed by two new lines

If you type in
1234567890123456 ; 16 values received
you'll see
1234, 5678, 9012, 3456 in the display. The cursor is sitting two lines down and is waiting for the user to enter another 16 values.
I include the section about modifiers from the "new manual" I was working on for BasicMicro that never got published. I highlighted some parts in yellow. One of these parts relates to modifiers. Read carefully. I can't swear there's any real difference between this and the old manual you're probably using. Every little bit helps.

As for HSERVO, I seem to find it broke. I have example code for HSERVO specifically for an Atom Pro 28-M, and it doesn't work as I remember it. It's supposed to have the servo work like a washing machine, constantly rotating between CW and CCW. It zeroes, does one direction, then pretty much sits there twitching in one spot. I'll report this to the programmer.
Good luck with your project.
Attachment:
Command Modifiers.pdf [34.61 KiB]
Downloaded 55 times

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile E-mail  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Mon Mar 08, 2010 4:56 am 
Offline
Citizen
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 43
Location: Wisconsin USA
What about for negative numbers

if i want it to recieve 1000 or -1000 over serial, is it still 4 decimal points?
I notice when it returns a negative number, it's really long.

I want to control the servos position remotely, IE if i send it 1000 it goes 1 way, and -1000 it goes the other.
more specifically i intend to use 3digit transfer with a 100* multiplier for the servo, so if i send it 100, it'll goto 10,000. And if i use -099 it'll goto -9900.
I just don't know how i'd bind that.
besides using an sword.

_________________
If a giant battle mech, steps on your car, and the mech is made of icecream/craft sticks.. That's me inside.
Sorry in advance.


Top
 Profile E-mail  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Mon Mar 08, 2010 6:48 am 
Offline
Citizen
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 43
Location: Wisconsin USA
Quote:
If the input is 3456 (in ASCII characters)
hserin [dec2 a]
takes the two least significant digits (56) of the input and assigns the numeric value 56 (binary
00111000) to the variable “a”.


This is a problem for me.
I want it to take the first 2 digits, not the 2 least significant. This combined with my previous post

Input ASCII 45-23420500-45
hersin [dec2 cat, dec4 ant, dec4 dog, dec2 nerd]

cat = 45
ant = -2343
dog = 0500 = 500
nerd = -45

How would i go about this?
I learn best from examples, but the basic micro wiki's doesn't have an example code section.
People should upload their scripts along with pictures/videos of their contraptions and a decent explanation of their controls ect.

Edit:
Do i do it like this
hersin [dec2 cat, sdec4 ant,dec4 dog, sdec2 nerd]
in order to make the above work?

Does sdec allow both positive and negative numbers?

_________________
If a giant battle mech, steps on your car, and the mech is made of icecream/craft sticks.. That's me inside.
Sorry in advance.


Top
 Profile E-mail  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Mon Mar 08, 2010 7:15 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 291
First simple answer: yes SDEC does support positive or negative numbers.

One note: At least I ran into on output: if you do something like: sdec4 myvar4 and my var is -5
the actual output will be: -0005
That is the counts (at least on output) do not take the - sign into account.

Kurt


Top
 Profile  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Mon Mar 08, 2010 4:23 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 699
Location: CA bay Area
The programmer set me straight. Using a 100ms PAUSE between HSERVO commands was too short. He said to use HSERVOWAIT to wait the exact time needed.
Notice the "500". That is the step speed. Larger values mean faster movement. Do NOT use a step speed with the first HSERVO in the code.
Enjoy.
Code:
PAUSE 500  ; give the Pro time to initialize
temp var word
ENABLEHSERVO  ; set up the registers for servo work

Start
HSERVO [P1\0]  ; send to servo to home position, no speed value in first HSERVO

FOR temp = 4000 to 20000 STEP 4000  ; values for HiTech HS-422 servo motor
   HSERVO [P1-(temp)500] ; pin,position,speed
   hservowait[p1]  ; waits for HSERVO to finish last move

   HSERVO [P1   emp500]
   hservowait[p1]
NEXT


goto Start ; repeat forever

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile E-mail  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Mon Mar 08, 2010 4:53 pm 
Offline
Citizen
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 43
Location: Wisconsin USA
Thanks kenji but that's not the problem i have with the servos.
I didn't add pauses, and i always use hservowait after an hservo command.

Edit: I noticed you said don't add a step speed to the first hservo command, but that's the problem, i want a step speed in the first hservo command, because i want the servos to goto POS 0, but slower, else they snap there rather quickly, not good on a weight sensitive arm. The servos i used are junky ones, but these were free.

Code:
Hservo [p5\0\0,p6\0\0]
hservowait [p5,p6]
PAUSEUS 2000000
Hservo [p1\0\0,p312000\0]
hservowait [p1,p3]
PAUSEUS 2000000


That's in my code, above the main section, I want it to center my servos before anything else.
My problem is where you see[p5.p6] is the speed sets are the problem.
if i set it to p5100, it freaks out, but eventually returns to the right area (giving the servo hasn't overextended itself and locked up)

However if i use p5100 later on in the code, the speed works fine.
It only has problems when the speed is 100, but outside of the main area.

I'll post my entire code.
You'll notice the servo commands near the top, if i set their speed to 100, they over extend and freakout, where as if i set the speed to 0, they move directly to their designated positions.
note: Camera = robotic arm, i just didnt bother to rename it.

Code:
enablehserial
enablehservo

SETHSERIAL H9600, H8databits, Hnoparity, h1stopbits
PAUSEUS 40000

high p7
high p10
PAUSEUS 400000
LOW p11                                  ;motor controller reset on pin 13
PAUSEUS 400000
HIGH p11
PAUSEUS 600000                             ;motor controller startup time


Hservo [p5\0\0,p6\0\0]
hservowait [p5,p6]
PAUSEUS 2000000
Hservo [p1\0\0,p312000\0]
hservowait [p1,p3]
PAUSEUS 2000000


main
cbot var word
cbot2 var word
drive1 var sword
drive2 var sword
drive3 var sword
drive4 var sword
change var bit

hserin 8000000, main,[dec4 cbot,sdec4 cbot2]
hserout [dec cbot,",",sdec drive1,",",sdec drive2,",",sdec drive3,",",sdec drive4,"    "]

if (cbot = 1000) then
SEROUT p10, i9600, [$80, 0, 0, 0]
SEROUT p10, i9600, [$80, 0, 2, 0]
elseif (cbot >= 1001 and cbot <= 1100)
goto movement
elseif (cbot >= 2000 and cbot <= 2100)
goto camera
endif
goto main


movement
if (cbot = 1001) then                      ;forward full speed
  SEROUT p10, i9600, [$80, 0, 0, 127]
  serout p10, i9600, [$80, 0, 2, 127]
  PAUSEUS 200000
elseif (cbot = 1002)                        ;backwards full speed
  SEROUT p10, i9600, [$80, 0, 1, 127]
  serout p10, i9600, [$80, 0, 3, 127]
  PAUSEUS 200000
elseif (cbot = 1003)                        ;rotate left, right track forward, left track reverse at reduced speed
  SEROUT p10, i9600, [$80, 0, 2, 90]
  SEROUT p10, i9600, [$80, 0, 1, 90]
  PAUSEUS 200000
elseif (cbot = 1004)                        ;Rotate right opposite of above
  SEROUT p10, i9600, [$80, 0, 3, 90]
  SEROUT p10, i9600, [$80, 0, 0, 90]
  PAUSEUS 200000
elseif (cbot = 1005)                        ;forward Slow
  SEROUT p10, i9600, [$80, 0, 0, 55]
  serout p10, i9600, [$80, 0, 2, 55]
  PAUSEUS 200000
elseif (cbot = 1006)                        ;backwards slow
  SEROUT p10, i9600, [$80, 0, 1, 55]
  serout p10, i9600, [$80, 0, 3, 55]
  PAUSEUS 200000
elseif (cbot = 1007)                        ;rotate left slow
  SEROUT p10, i9600, [$80, 0, 2, 30]
  SEROUT p10, i9600, [$80, 0, 1, 30]
  PAUSEUS 200000
elseif (cbot = 1008)                        ;Rotate right slow
  SEROUT p10, i9600, [$80, 0, 3, 30]
  SEROUT p10, i9600, [$80, 0, 0, 30]
  PAUSEUS 200000
endif

goto main

camera
if (cbot = 2000 and change = 0) then                  ;Resets Servos
drive1 = 0
drive2 = 0
drive3 = 0
drive4 = 12000
change = 1
goto pantilt
elseif (cbot = 2001 and drive1 < 12250 and change = 0)  ;Rotate
drive1 = drive1 + 250
change = 1
goto pantilt
elseif (cbot = 2002 and drive1 > -12750 and change = 0)
drive1 = drive1 - 250
change = 1
goto pantilt
elseif (cbot = 2003 and drive2 < 13500 and change = 0) ;first arm
drive2 = drive2 + 250
change = 1
goto pantilt
elseif (cbot = 2004 and drive2 > -8000 and change = 0)
drive2 = drive2 - 250
change = 1
goto pantilt
elseif (cbot = 2005 and drive3 < 3000 and change = 0) ;Grabber
drive3 = drive3 + 250
change = 1
goto pantilt
elseif (cbot = 2006 and drive3 > -6000 and change = 0)
drive3 = drive3 - 250
change = 1
goto pantilt
elseif (cbot = 2007 and drive4 < 12500 and change = 0) ;Second arm
drive4 = drive4 + 250
change = 1
goto pantilt
elseif (cbot = 2008 and drive4 > -13000 and change = 0)
drive4 = drive4 - 250
change = 1
goto pantilt
endif
goto main

pantilt
if change = 1 then
hservo [p5drive1100,p6drive2100]
hservo [p1drive3100,p3drive4100]
hservowait [p1,p3,p5,p6]
change = 0
goto main
endif
goto main

_________________
If a giant battle mech, steps on your car, and the mech is made of icecream/craft sticks.. That's me inside.
Sorry in advance.


Top
 Profile E-mail  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Mon Mar 08, 2010 5:22 pm 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 291
The first move will typically always be fast as it has no way of know where the servo is. If there is a problem with the initial arm moving too fast, sometimes the best way to handle this is to always make sure it is is in some known park location when it is powered up and then have the initial state move to that known park state. That is what I do with the arm on my Rover. I assume that it is folded up in the rest location.

As for stuff in PM. I have had some luck with some cables that are FTDI based. I have a couple of old ones that I bought several years ago from RadioShack that work (they don't carry these in the stores any more). Also Lynxmotion sells one that is FTDI based and it is the preferred cable. Just because it works with terminal programs may not make it work well with Basic Micro. Also the Arc-32 board and or the boards that BM sells also use FTDI. But not all FTDI cables are created equal. Have you read the troubleshooting guide on Lynxmotion forum?

Got to run
Kurt


Top
 Profile  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Thu Mar 11, 2010 7:29 pm 
Offline
Citizen
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 43
Location: Wisconsin USA
Based on my previously posted code. How would i program my robot to stop removing if i stop sending the movement code, and how do i stop it from buffering?

Like if i hold down the button, and it sends 10 times, after i let go, it'll continue to finish the 10 cycles, even when i'm no longer holding down the button.


How do i set for example "1001" which is my Forward Movement command, To only run while i'm holding down the button, regardless of buffering?
IE how do i set it to check what the code is now, and not what it was supposed to be.
You know what i mean? I'm not sure how to explain it.

I'm want to make my robot stop moving when i let go of the macro key in my terminal program. My terminal program just sends "1001" which triggers the robot to move forward, until i send it 1000, which triggers it to stop.
I'm sure i can figure it out if i put 5+ hours into it, 3 battery recharges, and 50 or so BAP reprogrammings, But i think it might just be better for you guys to show me the code of how to do it, and i work from there.
I don't want to get frustrated or burned out over it or anything.


Edit:

I basically need it to send the forward movement to command, wait 500ms, then check again to see if the code still = 1001 before returning to main, if it does not still = 1001, it sends the stop command.

_________________
If a giant battle mech, steps on your car, and the mech is made of icecream/craft sticks.. That's me inside.
Sorry in advance.


Top
 Profile E-mail  
 
 Post subject: Re: Fallentine help thread, Various small issues.
PostPosted: Thu Mar 11, 2010 10:46 pm 
Offline
Citizen
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 43
Location: Wisconsin USA
Besides a slight delay, i managed to get it to work.
And it only took slightly less than 4 hours. Though i probably had to write to my atom over 50 times.


How many times can i re-write to the atom? 10k? 100k? 1million times?


New code, let me know if you guys can improve upon it, i'm limited to a max of 12 macros (F1 = F12)
F1 = switch between arm and rover mode
F2 Reset arm position, manual stop.
(rover F3- F6 movement, F7 Gear down, F8 Gear 70)

arm F3 arm forward, F4 arm back, F5/F6 rotate, F7-F8, main arm, F9 F10 secondary arm, F11-F12 = gripper
I want to add a rotate wrist on the gripper, but i'm all out of macros. 12 is literally my limit until i can find a terminal program that is fully customizable.

Code:
pause 500
enablehserial
enablehservo

SETHSERIAL H9600, H8databits, Hnoparity, h1stopbits
PAUSEUS 40000

high p7
high p10
PAUSEUS 400000
LOW p11                                  ;motor controller reset on pin 13
PAUSEUS 400000
HIGH p11
PAUSEUS 600000                           ;motor controller startup time


Hservo [p5\0,p6\0]                       ;Center arm servos.
hservowait [p5,p6]
PAUSEUS 2000000
Hservo [p1\0,p312000]
hservowait [p1,p3]
PAUSEUS 2000000


main
switcher var bit
cbot var word
drive1 var sword
drive2 var sword
drive3 var sword
drive4 var sword
change var bit
gear var nib               
speed var byte
Starterclk var bit
meep var bit

if (gear = 1) then
  speed = 30
elseif (gear = 2)
  speed = 60
elseif (gear = 3)
  speed = 90
elseif (gear = 4)
  speed = 127
else
speed = 60
endif

hserin 800000, hault,[dec4 cbot]
hserout [dec cbot,",",sdec drive1,",",sdec drive2,",",sdec drive3,",",sdec drive4,"    "]  ; Debug code return.

if (Starterclk = 0) then
drive4 = 12000
gear = 2
Starterclk = 1
endif



if (cbot = 777 and switcher = 1) then                        ;Switches from Arm to Rover mode
switcher = 0
cbot = 0
  Sound P9,[605000,404500,204000]
goto main
elseif (cbot = 777 and switcher = 0)                         ;Switches from Rover to arm mode.
switcher = 1
cbot = 0
  Sound P9,[202500,403000,603500]
goto main
elseif (cbot = 1000 and switcher = 0)
goto hault
elseif (cbot >= 1001 and cbot <= 1100 and switcher = 0 and meep <> 1)      ;Rover controls.
   pauseus 300000
   if (meep = 1) then  ; secondary check
     goto main
   endif
meep = 1
goto movement
elseif (cbot >= 1000 and cbot <= 1100 and switcher = 1)      ;Arm controls.
goto robotarm
endif
goto main

;         ` /`/
;           V /               
;          /. .       
;        = T /=                 
;         / ^     
;        /\ //;   
;     __ " " /__           
;  (____/^\____)

movement
if (cbot = 1001 and switcher = 0) then                      ;forward full speed
  SEROUT p10, i4800, [$80, 0, 0, (speed)]
  serout p10, i4800, [$80, 0, 2, (speed)]
   meep = 1   ;just making sure
elseif (cbot = 1002 and switcher = 0)                        ;backwards full (speed)
  SEROUT p10, i4800, [$80, 0, 1, (speed)]
  serout p10, i4800, [$80, 0, 3, (speed)]
   meep = 1
elseif (cbot = 1003 and switcher = 0)                        ;rotate left, right track forward, left track reverse at reduced (speed)
  SEROUT p10, i4800, [$80, 0, 2, (speed)]
  SEROUT p10, i4800, [$80, 0, 1, (speed)]
   meep = 1
elseif (cbot = 1004 and switcher = 0)                        ;Rotate right opposite of above
  SEROUT p10, i4800, [$80, 0, 3, (speed)]
  SEROUT p10, i4800, [$80, 0, 0, (speed)]
   meep = 1
elseif (cbot = 1005 and gear >1 and switcher = 0)
gear = gear - 1
Sound P9,[1003000]
elseif (cbot = 1006 and gear < 4 and switcher = 0)
gear = gear + 1
Sound P9,[1005000]
endif
meep = 1
goto main

hault  ; Hault right there criminal scum, it appears you stole a spoon, oh no! it's the gray fox.
meep = 0
SEROUT p10, i4800, [$80, 0, 0, 0]
SEROUT p10, i4800, [$80, 0, 2, 0]
goto main

;           _!__
;          | * *|
;          |____|
;          __||__    )
;       []/______[] /
;       / \______/ /
;      /    /__;     (   /____
robotarm
if (cbot = 1000 and change = 0 and switcher = 1) then                  ;Resets Servos
drive1 = 0
drive2 = 0
drive3 = 0
drive4 = 12000
change = 1
goto pantilt
elseif (cbot = 1003 and drive1 < 12250 and change = 0 and switcher = 1)     ;Rotate CW
drive1 = drive1 + 250
change = 1
goto pantilt
elseif (cbot = 1004 and drive1 > -12750 and change = 0 and switcher = 1)    ;Roate CCW
drive1 = drive1 - 250
change = 1
goto pantilt
elseif (cbot = 1001 and drive2 < 13500 and drive4 > -13000 and change = 0 and switcher = 1)     ;Extend Arm
drive2 = drive2 + 250
drive4 = drive4 - 250
change = 1
goto pantilt
elseif (cbot = 1002 and drive2 > -8000 and drive4 < 12000 and change = 0 and switcher = 1)  ;Retract arm
drive2 = drive2 - 250
drive4 = drive4 + 250
change = 1
goto pantilt
elseif (cbot = 1005 and drive2 < 13500 and change = 0 and switcher = 1)     ;first arm forward
drive2 = drive2 + 250
change = 1
goto pantilt
elseif (cbot = 1006 and drive2 > -8000 and change = 0 and switcher = 1)     ;first arm up
drive2 = drive2 - 250
change = 1
goto pantilt
elseif (cbot = 1007 and drive4 < 12500 and change = 0 and switcher = 1)     ;Second arm down
drive4 = drive4 + 250
change = 1
goto pantilt
elseif (cbot = 1008 and drive4 > -13000 and change = 0 and switcher = 1)    ;second arm up
drive4 = drive4 - 250
change = 1
goto pantilt
elseif (cbot = 1009 and drive3 < 3000 and change = 0 and switcher = 1)      ;Grabber Close
drive3 = drive3 + 250
change = 1
goto pantilt
elseif (cbot = 1010 and drive3 > -6000 and change = 0 and switcher = 1)     ;grabber open
drive3 = drive3 - 250
change = 1
goto pantilt
endif
goto main


pantilt
if change = 1 then
hservo [p5drive1100,p6drive2100]
hservo [p1drive3100,p3drive4100]
hservowait [p1,p3,p5,p6]
change = 0
goto main
endif
goto main

_________________
If a giant battle mech, steps on your car, and the mech is made of icecream/craft sticks.. That's me inside.
Sorry in advance.


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO