go away spammer

Author Topic: Need help: webbotlib and cyclic routines  (Read 1645 times)

0 Members and 1 Guest are viewing this topic.

Offline klimsTopic starter

  • Robot Overlord
  • ****
  • Posts: 190
  • Helpful? 2
Need help: webbotlib and cyclic routines
« on: July 24, 2010, 03:03:41 AM »
I was hoping some of the better programmers out there might be able to point me in the right direction to programming a cyclic routine on my Axon using webbotlib.

I need to periodically read sensor values, make small adjustments then store them for other routines to use as needed. I need some kind of interrupt driven function that will call itself every so often.
I understand all the theory behind interrupts but have never actually tried to code them.

I am currently using the scheduler in webbotlib to get my cyclic routines since reading sensor values isn't very high up on my list of priorities of things to do. Here is the associated code:
Code: [Select]
void readSensors(SchedulerData data, TICK_COUNT lastTime, TICK_COUNT overflow)
{
//read sensors and adjust if needed
adjustX = a2dConvert10bit(posX) - 78;
adjustY = a2dConvert10bit(posY) - 90;

scheduleJob(&readSensors, &adjustX, lastTime, 50000);
}

Now I ask for help on better ways to do this because the &adjustX attribute is only there for show, which makes me think webbot planned for this to be used in smarter ways.
Can anyone tell me if there is a smarter or more efficient way to periodic read sensor and do minor adjustments?

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Need help: webbotlib and cyclic routines
« Reply #1 on: July 25, 2010, 10:25:24 AM »
Using the scheduler is definitely the way to go - unless you want to do something more than say every 1ms. But your example shows every 50ms so thats fine.
I guess what you are eluding to is adjusting the gait of your robot depending on say an accelerometer or gyro ?

The only time you have to be careful is if you are using multiple devices on the same bus(eg multiple I2C or SPI devices). The reason being that these protocols require more than 1 instruction to access the device. So your main loop can be in the middle of talking to one I2C device when the scheduler interrupt kicks in and it then tries to talk to another device over the same bus. In that event you are probably best reading the devices in each pass of your main loop - and then let the scheduler access the 'last read' values that you have stored away.

If the sensors are just using dedicated pins such as ADC pins then you don't have to worry.

Remember: the benefit of using the scheduler is that you can have many different things running via the scheduler and they don't require any additional (valuable) timer resources.

The scheduled routine runs with interrupts re-enabled so that other interrupt activities such as transmit/receive over a UART will continue to work even when the scheduled job is happening.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline klimsTopic starter

  • Robot Overlord
  • ****
  • Posts: 190
  • Helpful? 2
Re: Need help: webbotlib and cyclic routines
« Reply #2 on: July 25, 2010, 02:57:57 PM »
That's exactly right webbot. I'm reading gyro and accelerometer values from analog inputs.
No I2C but that's good to know.

So what value can I put in that data variable if I don't need to give it anything?


Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Need help: webbotlib and cyclic routines
« Reply #3 on: July 25, 2010, 05:47:45 PM »
Bit'o'history - Since klims is pro-active with my Gait Designer I have given him an early release of a future version which allows you to directly influence a gait that is currently running. This allows you to use sensors like accelerometers/gyros etc to sense if your robot is on a slope, say, and then adjust the biped robots ankles, or any joint, to compensate for the slope.

Quote
So what value can I put in that data variable if I don't need to give it anything?
I'm not sure I quite understand the question. ie its just a variable. But my expectation is that you read the sensors and then call the new gaitRunnerSetDelta to alter the gait for any appropriate servos/limbs. Passing a delta value of '0' will mean that limb/servo is not altered at all from the original gait.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Need help: webbotlib and cyclic routines
« Reply #4 on: July 25, 2010, 08:55:05 PM »
Bit'o'history - Since klims is pro-active with my Gait Designer I have given him an early release of a future version which allows you to directly influence a gait that is currently running. This allows you to use sensors like accelerometers/gyros etc to sense if your robot is on a slope, say, and then adjust the biped robots ankles, or any joint, to compensate for the slope.
Excellent! Exactly what I planned to write into my biped gait engine but never had time to do it.

Offline klimsTopic starter

  • Robot Overlord
  • ****
  • Posts: 190
  • Helpful? 2
Re: Need help: webbotlib and cyclic routines
« Reply #5 on: July 26, 2010, 12:55:59 AM »
II'm not sure I quite understand the question. ie its just a variable
If you have a look at my first post see the code of the callback function and the parameter &adjustX. I just put that there to satisfy the callback function, I don't need anything there in reality.
I just need a function that cycles every 50ms or so. This is why I was wondering if there was a better way to be writing a cyclic function other than using the scheduler.

The delta function is AWESOME! Hopefully I'll have some videos soon of my robot continuously adjusting for slopes, regardless of if its moving or not :-D
« Last Edit: July 26, 2010, 04:20:20 AM by klims »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Need help: webbotlib and cyclic routines
« Reply #6 on: July 26, 2010, 11:06:13 AM »
If you have a look at my first post see the code of the callback function and the parameter &adjustX. I just put that there to satisfy the callback function, I don't need anything there in reality.
I just need a function that cycles every 50ms or so. This is why I was wondering if there was a better way to be writing a cyclic function other than using the scheduler.
So rather than the 'adjust' varables - call the gaitRunnerSetDelta function instead. Stick with the scheduler - it has been used by others for similar tasks and is more portable to other AVRs then trying to play around directly with the timer hardware yourself.

Quote
The delta function is AWESOME! Hopefully I'll have some videos soon of my robot continuously adjusting for slopes, regardless of if its moving or not :-D
I look forward to a video and have got space to showcase it on http://webbot.org.uk

Just a quick note to others: you still need to read the sensors and then write your own code to decide how the gait needs to be adjusted. After all the impact of being on a slope is very different for, say, a biped compared to, say, a hexapod/spider or even a fish !


Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list