Shop OBEX P1 Docs P2 Docs Learn Events
Position Calculations — Parallax Forums

Position Calculations

AA Posts: 22
edited 2007-04-16 03:29 in Robotics
Hello

I have a project I've been working on.· It is a hacked hummer rc truck.· The goal is to allow it to go wandering for either a given amount of time or a certain amount of area covered and then return home.· All the while the position,temperature,·and data from up to two 4-20ma or 0-5 volt sensors is being sent back to a pc via wireless.· The information is then being displayed in a MAtlab based gui.· The truck uses two BS2's commmunicating serially. IR and Ping are being used to find a clear path and avoid objects.· A regular hobby servo is providing the steering and a DC motor w/ programmable PWM H-bridge for movement.· Absoulte distance is measured from an axle encoder and a·pulse counting circuit(runs independently of stamp) and the bearing is measured from north with the hitachi compass.· At this point everthing is complete except for peforming the position calculations.· I don't want to send data to the bot with the wireless so the calculations need to be done on the stamp.· Each move the bot makes is broken down into the x and y cordinates and added to the previous counts.· The bearing flips 180 for reverse and is normal for forward. The problem I am having is with decimal roundoff.· the simple idea is x = x + (scale*pulse count)*cos(bearing)·: Does anyone know of an easy way to use the sin and cos functions perform a calc and then scale the result·back down as if cos or sin output between(-1·and 1). If I understand sin and cos output between -127 and 127? I would be gald to offer info on any of the above components for some advice.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-13 05:21
    Have you looked at Tracy Alan's website? (www.emesystems.com) There's lots of stuff there on math including fixed point arithmetic, multiple precision arithmetic, transcendental functions like sin/cos.
  • Tom CTom C Posts: 461
    edited 2007-04-13 14:37
    Hi A,

    I am attempting to·use an iRobot Create to perform a similar function using three networked BOE/BS2s.

    One of the BOE/BS2s is a master and the other two BOE/BS2s are slaves. The Master BOE/BS2 controls the slaves and communicates with the PC·with an eb500 Bluetooth wireless modem. One of the slaves operates the Hitachi Compass, the Ping·and the IR Sensors. The other slave operates a pan and tilt servo system for a wireless camera. The·Create will be used indoors only, but I would like to develop a tracked (Boe Bot with Mattracks) robot for outdoor use also.

    Would you be interested in sharing your control algorithms and in·return maybe I can assist with the bearing calculations? I believe I know where you can get all of the information that you need for position calculations as it has already been done and documented on the Parallax website.

    Just a thought.

    Regards,
    TCIII

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If you are going to send someone to save the world, you·better make sure that they like it the way it is!
  • AA Posts: 22
    edited 2007-04-15 04:37
    I'd be gald to share.· Are you intrested in any particular part of the controlls?· The short descritption is:


    The Ping·scans 5 points of 180 degrees in the front of the bot.· Each measurement is succesivley compared to find the largest clear distance.· As long as the largest distance is greater than the minimum distance the·tires are turned appropriatly and the·bot·begins to move forward.·if the distance is less than the min then the bot backs up.·I designed my own·PWM motor controller which runs independently after recieving speed and direction commands.· The first stamp then sends the motor direction to the second stamp.· The second stamp then calculates the postion based on the wheel encoder pulse and the compass bearing.To account for a clear horizon and avoid spining in circles the center ping measurment is compared to a max clear distance.··If this distance is exceeded the bot goes forward with no turns.· To get consistent results with the servos I have used some limit switches and a calibration routine.·After the ping routine the IR·detectors are sampled.· I have four so thats 16 different states.· I reduced the states down to 8 different behaviors ranging from normal to multipoint turns in one or more directions.· For each move the position is calculated by the·second stamp.··After the IR routine the·first stamp waits to recieve a command from the second. All the while the second stamp is checking the time (DS1302) or the area covered (width of bot * current distance summed with last area).· I currnetly don't have·a way to avoid covering the same are twice. I use an lcd,quadrature encoder and pushbutton for user input of time or area.· If·the selected·value is reached then the bearing home is calcualted and compared to the compass.· Steering data is derived and sent to the first stamp.· The tires are moved appropraiatly and the bot goes froward.··The same Ping and IR routines are used on the way home.· Again position is calculated for each move and then the sequence repeats.· If the position is within +/- 1 meter of the origin then·its home and the bot shuts down.· Oh yea the second stamp send the data to the wireless tx·each time the first stamp completes its·Ping and IR routines.· All the data appears in a matlab gui.·As far as the external sensor data my wirless board has·available ADC's that are sampled in its own program.· The wireless board is a Chipcon·CC2420 development kit.· It's overkill at the moment but I plan on using the MAtlab·program to send commands to the bot and then·network several bots together.·······
  • DgswanerDgswaner Posts: 795
    edited 2007-04-15 19:25
    I'm working on a bot to do almost exactly the same thing as both of you are working on. I'd love to see some actual code as that is my weak side. I'll help in anyway possible.
    I want my bot to behave in basically the same way except that I want it to seek out people in a room when it has "contacted" each person it then goes back to a starting location.
    A, Does your robot's return path head the direction of the start position and avoid obstacles until it gets there? or does it remember how it got to it's current location and then drive it in reverse? I was trying to think of a way so that it records the path it took, minus the wrong turns. and drive right back to the start position.

    I'm trying to do this on one BS2sx are you using multiple stamps because it's easier? or is it for the speed/multitasking part of it.

    using multiple stamps do you get hesitation in the robot movement while the bs2's are communicating/calculating? or do you get better performance. I would love to be able to pan the ping servo continuously while doing other things.

    I was going to mount a Hitachi compass on the ping module and decide on the best direction by ordinal degree. centering the ping to find the bots current direction and then turning the to best direction.

    I can get my bot to navigate with Ping and IRPD sensors but it's more of a blind bull in a china shop. I'd like to get a more robust nav system working.
  • Skywalker49Skywalker49 Posts: 172
    edited 2007-04-15 21:40
    A, Dgswaner,

    I had a quick look at the accuracy of the Hitachi compass on one hand and the resolution of
    the trigoniometric fucntions (SIN/COS etc.) on the other hand.

    The compass provides max resolution of 5.6 degrees. ( 64 positions to cover 360 degrees ).
    In case you deal with small variations of the direction of movement, the error can become unacceptable.

    The res. of the trig. functions is documented by Tracy Allen on her website http://www.emesystems.com/BS2math3.htm
    and it doesn't look very promising. Don't expect too much accuracy and again.

    I think that the repetitive calculation of the next position based on the previous one incl. angle (compass) & measured distance (axle encoder)
    will very quickly lead to extreme errors = loss of position.

    So, before to continue doing the math (I'm very interested too) we need to make sure that the results are usable.

    I hope I'm wrong and somebody will tell me now!

    Ed
  • AA Posts: 22
    edited 2007-04-16 02:01
    Currently my bot heads home and avoids obstacle until it gets there.· I plan on adding advanced features where the position of an obstacle can be plotted in my gui and Matlab will find the best route home.· I will continue to use the current code in case of communications loss.· Right now the angle home is found by a straight line to the staring point.· Either way I don't plan on saving each move although each turn will be inherintly stored in the matlab program

    I'm using multiple stamps because that is what I had available.· My wireless board is probably capable of doing all the work but it is much harder to program and requires more hardware design to run all the sensors.· All in all its probably not any easier or faster because of the serial communications.··The multitasking should increase the speed in·each stamp but I don't know what the trade off is.· another reason for two stamps is twice the program size and twice the·variable space.·I havent checked the specs on the other stamps

    I designed my motor control for the speed and direction to remain set until a new command is recieved.· This is a simple triangle wave compared to a ref volatge to produce PWM.· The vref is provided by a programmable serial in DAC.·It uses three pins, a fourth pin provides the direction indication.· This allows the motor to run smoothly while the stamp is doing other things.· The same circuit cab drive the steering servo to hold it a a certain point while the stamp is doing other things.· I'm not shure how to continuosly scan the ping servo because it requires the postion to be known to correlate the distance readings.· The previous circuit could pan the servo by replacing the refrence voltage by a slowly ramping voltage or a· low frequency sin wave.· It might be hard calculate its postion at a particular point.· The DAC could also be drivien by a seperate logic circuit to accomplish the same thing.· With this method the input to the dac could be sampled each time a reading is taken.· Mabey not that hard after all.· To compliment this the encoder is ran into a seperate counting circuit.· It is 2 cascaded binary counters the output is tied to·a parallel in serial out and is reset each time it is read.· This helps from missing pulses or waitin for a certain count to be achieved.· It·also reduces the load on the stamp.· The circuit can handle clock frequencies up to 4MHz >>> than my fastest speed.· Currently I have a very low resolution encoder but I'm only shootin for +/- one meter inside a bounded region of 50m^2

    As far as accuracy goes there will probably be a·large accumulated error.· I had considered GPS but i need positon in situatuations where it won't work.· Also the learnin curve seemed a little steep for a beginner.· From what·I've read getting·accurate GPS position isn't as easy·as it sounds.· To help with the error due to the compass, I'm taking three sampes and averaging them.· I don't care about any offset error due to its mounting because this error is fairly constant and·the position is all relative to the starting point·i.e North in my map is whatever way the bot was pointing when it starts.· To help remove some error from the encoder and limited math capabilities I eventualy intend to send the bearing and encoder count to Matlab to perform the X Y calcualtions.· Matlab should considerably knock down the error in the calcualtions. These values will be sent to the bot.· It will continue to update by itself·incase of comm loss. I will also send the distances from the ping, motor direction, and the location of any objects to matlab.· It will be some heavy programming but the information could be used to adjust the error by comparing the calculted position to the known position of an object already found.· The idea being that if you calcuate how far you move· you can also calculate the distance·to a known (stationary) object.· The difference between the calculated and measured object distances are representative of the error in your position calcualtions.

    Not quite there yet. one step at a time

    my current calcualtion is looking like this so far

    xpos =xpos + ((pcount*((100*(((COS angle)*10)/127))+(((COS angle)*10)//127)-((((COS angle)*10)//127)/5)))/100)····· ' = cm

    my pulse count represents .1 meters per pulse

    the angle is flipped 180 given motor direction of reverse first· The last term in the eqaution is epiraclly derived from measurements i've taken The worst error occurs when the pulse count is < 5 at higher counts the output is fairly accurate.· I'm sure there is a better way.· Any Ideas??

    A
  • DgswanerDgswaner Posts: 795
    edited 2007-04-16 03:29
    Wow! is all I can say! I'm in way over my head, I'm still not discounting the ping and compass method. I did know about the 60 deg limitation but in an area of a house I don't imagine it will be enough to make it unusable. I guess I'll find out. I'm working on it right now. the return path doesn't need to be absolute either. As it's possible that the path could change slightly before the bot returns.... a pet gets in way a kid moves a chair. I just want it to have a general path to follow back to a given point and or charger. The relative direction would work fine so long as the robot didn't have to go around an obstacle that would then block the direct path back.

    I've used a hand held GPS quite a bit. The best accuracy is about 10m from what I heard the military or gov. had a "fudge factor" built in. There are commercial/civil engineering GPS that have a high level of accuracy in the inches, but I heard one engineer say they were 40K. I'm all for getting one I just can't convince the wife!

    I have a roomba that finds it way back to a base. from what I can tell it just randomly drives around, when it gets to 25% battery life(that's a guess) it looks for the IR of the Base unit as it's bouncing around the walls and when it finds it, it goes home. If I can get the bot to return with in 5 feet +/- I plan on working on a similar IR system to bring it the rest of the way home.

    I don't think I'll be much help at least right now your light years ahead of me on your projects. I'll just try tag along. I'd be more than happy to beg borrow or make anything I can to help. I have access to a lathe and lots of other tools so let me know if I can be of assistance in other ways while you blaze the trail forward. in the mean time I'll try to catch up.

    Thanks for you input and formula.
Sign In or Register to comment.