angular speed and gyrometer


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Mar 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    yes i had a look a sparkfun.com and the devices they sell seems very good for what i plan to do next, but for the moment i just want to sense the motion of my head and send it by the ppm signal of my radio to get it on my receiver it should move a servo that move a camera who send the signal to my head mounted display(i know that's a long sentence)

    i think that should be enought accurate with the need of a reset button of course.

    the ppm sending part is already running with my equipement (just need to put a value from 0 to 1200 in every channel variable)


    here is my code:
    define OSC 4
    OSCCON=%01100000 'pour f88 pic oscillateur interne config marche pas sans ca
    output portB.0 'suncro led
    output portb.1 'ppm out
    input porta.0 'gyro 1
    output porta.2 'lcd

    ANSEL=%00000001

    ADCON1.7=0 ' Left justified bits (10-bits ADRESH=Left ADRESL=Right)
    PAUSE 10

    ADCON1=%00000000 ' Switch ON an0 A/D's with Vdd as Reference

    ' A/D 0
    ADCON0 = %10000001 ' 20 MHz, Channel 0

    'variable for adc
    AD0H VAR BYTE ' High Byte 0 - 255
    AD0L VAR BYTE ' Low Byte 0 - 255
    AD0 VAR WORD ' AD0 word (10 bits)

    'need to put fosc2-1 = 100 that means r7 and r8 is i/o et xtal is internal
    ch1 var word 'word = 256bit value or 65000 dec val i think
    ch2 var word
    ch3 var word
    ch4 var word
    pan var word
    tilt var word
    ch7 var word
    ch8 var word
    chsyncro var word
    chseparator con 300'296 'with the pauseus it is 0,3ms or 300us
    servotest var word
    A var word
    'change those value for more angles 90° 120°
    servomin con 400'700
    servomed con 1000 'this is med
    servomax con 1600'1700

    'channels goes from 0.7ms to 1.7ms min to max
    'so that's sounds good with the 0.3ms, entire signal varies from 1ms to 2ms
    'neutral without interchannel minipulse is 1,2ms and 1,5ms with minipulse

    'i assume that 1200 would be the neutral 1,2ms with the pauseus instruction

    'initialise servo position
    'put pan servo inthe middle
    ch1 = servomed
    ch2 = servomed
    ch3 = servomed
    ch4 = servomed

    pan = servomed'is ch5
    tilt = servomed'is ch6
    ch7 = servomed
    ch8 = servomed







    gosub lcd_init 'goto lcd init

    ' Send the ASCII value of B0 followed by a linefeed out Pin0 serially at 19200 baud
    SEROUT2 PORTA.2,32,["headtrack ppm adc"]
    pause 1000



    main:

    ReadAD:

    ADCON0.2 = 1 ' Start conversion

    pauseus 10

    AD0H = ADRESH
    AD0L = ADRESL
    AD0=(AD0H*4)+(AD0L/64)
    'ad0=((ad0-460)*10)+ servomed
    pan = ad0
    SEROUT2 PORTA.2,32,[$A3,$01] 'clear alcd and locate in 0,0
    SEROUT2 PORTA.2,32,["value is:",dec pan]
    pause 10





    'is all servo test mode

    'for servotest = servomin to servomax step 5 'start to the min angle and go to max angle progressivly
    'ch1 = servotest
    'ch2 = servotest
    'ch3 = servotest
    'ch4 = servotest
    'pan = servotest
    'tilt = servotest
    'ch7 = servotest
    'ch8 = servotest
    'gosub ppmtrame
    'next

    'for servotest = servomax to servomin step -5 'start to the min angle and go to max angle progressivly
    'ch1 = servotest
    'ch2 = servotest
    'ch3 = servotest
    'ch4 = servotest
    'pan = servotest
    'tilt = servotest
    'ch7 = servotest
    'ch8 = servotest
    'gosub ppmtrame
    'next
    'goto main





    'send ppm trame and high del0 during chsyncro time
    ppmtrame:

    'protection against overrange
    if ch1 > servomax then ch1 = servomax 'protection cannot go upper than servomax value
    if ch1 < servomin then ch1 = servomin 'protection cannot go less than servomin value

    if ch2 > servomax then ch2 = servomax 'protection cannot go upper than servomax value
    if ch2 < servomin then ch2 = servomin 'protection cannot go less than servomin value

    if ch3 > servomax then ch3 = servomax 'protection cannot go upper than servomax value
    if ch3 < servomin then ch3 = servomin 'protection cannot go less than servomin value

    if ch4 > servomax then ch4 = servomax 'protection cannot go upper than servomax value
    if ch4 < servomin then ch4 = servomin 'protection cannot go less than servomin value

    if pan > servomax then pan = servomax 'protection cannot go upper than servomax value
    if pan < servomin then pan = servomin 'protection cannot go less than servomin value

    if tilt > servomax then tilt = servomax 'protection cannot go upper than servomax value
    if tilt < servomin then tilt = servomin 'protection cannot go less than servomin value

    if ch7 > servomax then ch7 = servomax 'protection cannot go upper than servomax value
    if ch7 < servomin then ch7 = servomin 'protection cannot go less than servomin value

    if ch8 > servomax then ch8 = servomax 'protection cannot go upper than servomax value
    if ch8 < servomin then ch8 = servomin 'protection cannot go less than servomin value

    'calcul de chsyncro
    '22000-4 for errors = 21996
    chsyncro =21996-((chseparator*8)+ch1+ch2+ch3+ch4+pan+tilt+ch7+ch8-10)

    'start sending the ppm frame:
    high portb.0 'begining of the syncro del is on
    high portb.1
    pauseus chsyncro
    low portb.1
    low portb.0 'ending of the syncro del is off
    pauseus chseparator 'should be 3us low state between channels
    high portb.1
    pauseus ch1
    low portb.1
    pauseus chseparator 'should be 3us low state between channels
    high portb.1
    pauseus ch2
    low portb.1
    pauseus chseparator 'should be 3us low state between channels
    high portb.1
    pauseus ch3
    low portb.1
    pauseus chseparator 'should be 3us low state between channels
    high portb.1
    pauseus ch4
    low portb.1
    pauseus chseparator 'should be 3us low state between channels
    high portb.1
    pauseus pan
    low portb.1
    pauseus chseparator 'should be 3us low state between channels
    high portb.1
    pauseus tilt
    low portb.1
    pauseus chseparator 'should be 3us low state between channels
    high portb.1
    pauseus ch7
    low portb.1
    pauseus chseparator 'should be 3us low state between channels
    high portb.1
    pauseus ch8
    low portb.1
    pauseus chseparator 'should be 3us low state between channels
    'stop sending the frame
    'return
    goto main



    'the lcd routine initialisation
    lcd_init:
    SEROUT2 PORTA.2,32,[$A3,$01] 'clear alcd and locate in 0,0
    SEROUT2 PORTA.2,32,[$A1,2,0] 'locate in x,y
    SEROUT2 PORTA.2,32,[$A3,$0A] 'stop blinking cursor
    'SEROUT2 porta.1,32,[$A3,$0B] 'blink cursor
    SEROUT2 PORTA.2,32,[$A3,$0C] 'hide cursor
    'SEROUT2 PORTA.1,32,[$A3,$0E] 'show cursor
    return

    end

    fefenin

  2. #2
    Join Date
    Mar 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    if anbody has a piece of code as an example for me that will be nice i found it hard to do

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by fefenin View Post
    if anbody has a piece of code as an example for me that will be nice i found it hard to do
    Apparently, you've only been at it for a day.
    Jeeze...nobody finishes a project in a matter of hours. Give it some time...

  4. #4
    Join Date
    Mar 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    ok i get it
    i already try harder
    will see
    i ll tell you when it is done you could probably help me after to get it optimised


    bye

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by fefenin View Post
    ok i get it
    i already try harder
    will see
    i ll tell you when it is done you could probably help me after to get it optimised


    bye
    That's better. And no 'free help' here...
    Don't tell 'ME' when the code is done and don't expect 'ME' to help you optimize it.
    Post to the whole 'FORUM' that the code is done and ask the whole 'FORUM' if anybody has any suggestions for optimizations.
    And I don't see anything substantial in that code above...just a few statements testing this and that. It's like saying:
    "I building a car. Here's a spare tire, a seat, and a steering wheel cover. Oh, I have to pick up a few things yet, but I'm practically done."
    There's nothing about angles, nothing about integration, no 'real' math, etc.etc. I could go on and on...

  6. #6
    Join Date
    Mar 2007
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    i know there is no math yet i just post the soft working for sending ppm trame with my radio,there is still the angle soft and stuff like you said.

    i found you a bit hard with me i told you i m very new in programing and very bad in math

    i m actually working on the math part (trying some things like test adc value one time and just straight after an other test so i have to values)

    i m probably in the right way to make that works



    thank s again all

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by fefenin View Post
    i know there is no math yet i just post the soft working for sending ppm trame with my radio,there is still the angle soft and stuff like you said.
    i found you a bit hard with me i told you i m very new in programing and very bad in math
    i m actually working on the math part (trying some things like test adc value one time and just straight after an other test so i have to values)
    i m probably in the right way to make that works
    thank s again all
    Yep, but then again, sometimes, that's what it takes...a bit of drilling before it finally sinks in...
    But I do have to reiterate...once you get something you think is good, I'm positive a bunch of us will be more than happy to look it over to obvious (and not so obvious) mistakes or logic problems, as long as we've got a good explanation of what the end result is supposed to be...
    Now, going with that...
    You said you're using a radio setup to move a servo remotely. You also said you're a beginner. I don't know how much of a beginner you are, but I can see a problem coming up....that is...trying to do too much at once.
    Build it up in steps...and I think most importantly, keep the radio link as the very last step. Get the A/D working, make the servo move, make the servo move with the A/D, etc.etc.etc. I think you get the picture...

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts