Author
Topic: New C library - testers required (Read 51486 times)

WebbotLib Version 1.24 has been released with the following new features:-

* core.h - added the 'isqrt' function to calculate the square root of an uint32_t without needing the floating point library

* The Stepper directory has been added to handle stepper motors. The initial (alpha) version copes with the Pololu A4893 as well as the generic L297 controller

* GaitRunner.h has been improved via the new gaitRunnerSetDelta and gaitRunnerGetDelta functions which allow you to modify the gait at runtime. For example: change the ankle joints of a biped if it is walking up, or across, a slope so that it doesn't tip over

* Sensors/Encoder/Generic/fastquad,h now has a MAKE_GENERIC_FAST_QUADRATUREx2 constructor. This requires an INT pin for both channels A and B - but the resolution of the encoder is doubled generating 4 ticks per stripe on the encoder disk.

* Sensors/Encoder/Generic/fastquad,h now has a MAKE_GENERIC_FAST_QUADRATUREx2 constructor. This requires an INT pin for both channels A and B - but the resolution of the encoder is doubled generating 4 ticks per stripe on the encoder disk.

To clarify, this means you are reading full resolution quadrature counts now? Or something fancier?

* Sensors/Encoder/Generic/fastquad,h now has a MAKE_GENERIC_FAST_QUADRATUREx2 constructor. This requires an INT pin for both channels A and B - but the resolution of the encoder is doubled generating 4 ticks per stripe on the encoder disk.

To clarify, this means you are reading full resolution quadrature counts now? Or something fancier?

Full res . . . I gave Webbot a good talkin to (he gave in after I brought up the crying kittens)

Actually, if coded, it can get even fancier but accounting for rotational velocity and guessing the location between clicks.

The encoders now work in one of 3 different ways - and this really depends upon how many INT, PCINT, and just normal IOPins you have available. So all of the 'older' code will continue to work.

1. You can use a PCINTxx for Channel A - along with a general IOPin for Channel B. This gives two ticks per 'stripe' ie 2 x resolution. But PCINTs are 'slowish' so not good for a hires encoder

2. You can use an INTxx for Channel A - along with a general IOPin for Channel B. This is the same as option 1 - but the interrupt is processed faster and copes better with more hires encoders

3. The new addition. You can use INTxx for Channel A and INTyy for Channel B. This gives double the resolution compared to the previous methods (ie 4 ticks per 'stripe') and, like option 2, is highly optimised for the speed of hires encoders.

So the choice is up to you depending on what pins are available.

Quote

Full res . . . I gave Webbot a good talkin to(he gave in after I brought up the crying kittens)

Well my dog weighs about 30kg. He eats kittens in his sleep. Takes a lot to make him cry (unless he runs short on kittens)

Next release will add a 4th option - using 2xPCINT pins with 4 clicks per revolution.

Am considering an overhaul of the I2C code. At the moment WebbotLib assumes one hardware I2C bus - which is fine for the currently supported processors. But 'other' processors have more than one. Main change is that the slave I2C device address should be unique on the given bus (at the moment each device must be globally unique given one bus).

One reason for thinking about this: if you want say 2 of a particular device but its I2C address cannot be changed then you are stuffed. So if I allow a bit bang sw I2C bus then you can add extra buses and have one device on each. Or if the hardware has 2 x I2C hardware bus' then thats fine too.

I've already done the SPI stuff like this. ie you create a SPI bus (either using hardware or simulated in software) and then say what devices are on that bus.

Just a heads up - as you may then need to re-create any I2C devices in Project Designer to attach them to an I2C bus.

* Encoders - The MAKE command now has an extra parameter to say whether or not you want the encoder to interpolate to generate a guesstimate of its current 'part-click'. Most useful for low resolution encoders attached to large wheels. For backwards compatibility you will need to add a FALSE parameter to your encoder MAKE commands or, if using Project Designer, then regenerate the code.

* Stepper Motors - fixed some bugs and also added Stepper/Generic/Bipolar.h for a generic stepper motor controller using h-bridge components such as the L293 series

Followed closely by... a beta 2.00 - which does some more code generation - mainly to do with initialising things like timers and interrupt handlers. Makes the code smaller and the interrupt handling much more efficient hence leaving more cpu time for your program to run. Also generates 'makefile's for those not using Windows/AVRStudio.For those who use 'ant' it will also be possible to have an ant task to generate the code from the Project Designer project file without having to launch Project Designer. Useful for doing a batch clean build of all of your projects when a new WebbotLib is downloaded.

Sort of put the C++ port on ice for now. The avr C++ compiler has quite a few bugs/anomalies and trails the C compiler in support.

In my opinion, I fully support forcing people to use project designer in the next major release if it optimizes code. I know you had mentioned it in the past... What's your stand on it now?

Yep thats my preference too. But folk like KurtEck make a good case for keeping some of the other bits'n'pieces. So my view is that if you use Project Designer then you'll get better/smaller/tighter code; but if you use the 'power features' like setting up your own timers and handlers then it will still be possible to do - but it will then bring in the extra payload. That way the power users are no worse off, but the PD users get a benefit.

Forgot to mention that in Version 1.28 there is the extra functionality:1. The Tools | Generate menu option now laos creates a makefile - great for those non-AVRStudio, Mac, Unix users who have no other way to build their code. Just change to the project folder and run 'make' to create your hex file.2. Mac and Unix users were reporting that the 'Tools | Generate' command didn't do anything. I think I've fixed this but have no way of testing. So can the first person who finds it works or fails reply to this post to confirm (ie don't say 'It doesnt work on a Mac' if someone has already said that.

EDIT: A Mac user has confirmed that the Project Designer 'Tools | Generate' option now works correctly.

I now want to trial a pre-release of WebbotLib Version 2 - PM/email me if you are interested in being a guinea pig having read the following !

What is it?Well its a new download of WebbotLib (not yet in SourceForge - so if you enroll then I'll send you the link) Yes - you can install it into another directory. So you can keep the existing WebbotLib version 1 as well as the new Version 2The edit box in Project Designer (which asks you to locate the WebbotLib directory) decides if its Version 1 or Version 2 and then generates code, AVR Studio file, makefile accordingly. So the same Project Designer can cope with both versions.Yes its an alpha release so may have some issues - but you can still use your Version 1 download as well.

Why would I want it?In summary - it produces much smaller code.

Yep - but I have an ATMega mega with mega amounts of mega program space. So why would I care if the code is smaller when I've got lots to spare?Well small code normally = more efficient code.And the main point here is in interrupt handling - ie since the interrupt code is more efficient/quicker then it leaves more time for your application to run or more 'things' that the interrupts can do in the same time - like control more servos via software PWM for example.

So what's the catch?In order to create more efficient code then the library needs to know what devices you've got connected. With Version 1 then it only knew this at runtime and so had to assume that you might do anything. With version 2 then you must use Project Designer (from my site http://webbot.org.uk) so that it knows ahead of time what you actually want to do. This allows WebbotLib to throw away code it knows you will never use - as well as generate some highly optimized code for the devices you ARE using.

Ok - but I'm an advanced geek and want to add my own code to tap into timer overflows, compare match, and capture interrupts to handle devices not supported directly in Project Designer! Can I still do that?Sure. All the old calls are still there - but using these advanced features will bring in extra code and cut down on the memory savings.

Do you still support AVRStudio ?The build process for Version 2 is quite complex to try and squeeze out every bit of non-used code to make the executable as small as possible.This means setting different compile options for different files. Version 2 even creates a library (.a file) for your project.Some of these things are achievable in AVRStudio - but not everything. In the meantime, until I find a better solution, then I would suggest that before you regenerate the code form within Project Designer that you close the project in AVRStudio and delete the '.aps' and '.apw' files. Failure to do so may mean that AVRStudio doesn't pick up the latest changes since it doesn't scan these files to see if they have been updated by another thread like Project Designer.The toolchain in AVRStudio is also rather limited. So to squeeze the last bit of memory in your program then I suggest you use the 'makefile' generated by Project Designer. From a command prompt: move to the project directory and just type in 'make' (without the quotes) and press return.Alternatively: in AVRStudio go into the project settings and tell it to use an external makefile instead.

What boards do you support?Since the whole 'sys/' folder has disappeared then you can only use Version 2 if there is a board file for Project Designer to work with. If you have a custom, or unlisted, board then I suggest using my Board Designer to create your own board for subsequent use in Project Designer. Since the resultant code is smaller then Project Designer will now support the ATMega8 - and a 'bare bones' project that does almost nothing, but has the whole WebbotLib harness, only needs about 2.5k.

Why keep AVRStudio?Well this is one for the future really. Project Designer generates all your skeleton code and a 'makefile'. So it could also run the 'makefile' - ie build your code. So all that is left is a 'text editor' and executing something like 'avr-dude' or 'fboot' to upload it to the chip. The only missing piece is the AVRStudio simulator/debugger.

SummaryThe main difference is that you must use Project Designer. If you are using the Axon, Axon II, $50 Robot, or any other board currently supported then this is not an issue.If you have an unlisted board, or a home made board, then you will need to use Board Designer to make it available to Project Designer. Whilst this may be a hassle - it is a one off process. If you are using Board Designer to describe an unlisted commercial board then let me know - I could add the board design to future releases of Project Designer to allow everyone to benefit.

For those of you who want to try the alpha version of WebbotLib Version 2.00

Step 1 - download the library. Its not on sourceforge yet so get it here http://webbot.org.uk/webbotlib/webbotavrclib-2.00.zipStep 2 - unzip the file into a fresh directory so that you keep your Version 1.xx of WebbotLib as its possible to use both versions.Step 3 (optional) - if you want to try an existing project with Version 2.00 then I would recommend that you copy your current version 1 directory to a new workspace so as not to clobber your version 1 project. But dont copy the *.aps and *.aws AVRStudio files so that these are generated afresh.

Dont forget that Version 2 needs you to use Project Designer - you can't just build it on the fly by adding a sys/*.h file as they no longer exist. (But don't worry - you can use Board Designer to create your own custom board if its unlisted and use that within Project Designer).

The 'decision point' is in Project Designer when you choose the tools + code generation option. In the familiar 'WebbotLib' folder text box you need to select either your Version1, or your new Version2 directory created in step 2 above. Project Designer will then create code that is appropriate to that version of WebbotLib. Dont worry - it can tell by looking at the directory whether its Version 1 or Version 2.

Having generated the code then either use AVRStudio, or BETTER, launch a DOS Command Prompt and change to your project folder and type in 'make' to execute the makefile generated by Project Designer.

Hint: if you aren't using devices built onto your board then disable them in Project Designer by clicking on the tick box to make the finished code smaller. EG if you aren't using the LED segment display on your Axon II then disable it. Its the only 'built in' device which requires the scheduler code. So it could make your code smaller. Or if your finished robot doesn't require a UART for PC comms then disable any on board uarts. You get the picture.

New: there is a new device called 'clock' which is auto-added to your project. In Version 1 the clock, which generates all the internal timings, was set up to use any timer left over after you had initialised all your hardware. The 'clock' device is automatically added to your project but is ignored if you are still generating code for Version 1 - although the error checking makes sure that there will at least be a timer available for it. However: if you are using Version 2 then it sets aside the timer you have indicated for use by the clock and scheduler. The clock device also has a parameter to allow you to set how many concurrent jobs your own code will put into the scheduler. For example: the marquee on the segmented LED of the AxonII is the only device, currently, which requires the scheduler (to scroll the text) - but no need to worry about that as Project Designer knows that that is the case. However: if your own code uses the scheduler (say to update a PID or IMU) then you will need to edit the 'clock' and indicate that you need '1' scheduled job. Of course you can take the 'mad' approach and say you need loads - but that will waste memory unnecessarily.

Version 2 generates all sorts of new files into the auto-created 'lib' sub folder of your project. By all means take a look at them (but don't change them!). Since Project Designer knows about all the timers you are using, and how best to setup prescalers and timer modes, then the code to initialise timers, and the clock, is now very small and exact.

Advanced: look at lib/opt_TimerCompare.c and similar - these sets up the interrupt service routines for each timer and channel. The generated makefile won't bother including these file unless you have used one of the 'attach' functions to add your own call back to a timer overflow, compare match, or input capture. Hence all those ISRs (which are only a handful of C code lines but generate masses of code) are only added to your finished program if you are using those advanced functions.

Anyway - have a play. Enjoy (ie get frustrated, bang head on table/wall, call me every name under the sun). Since its 'alpha' then PM/email me any issues - rather than posting on SoR. Try comparing the finished program size from Version 1 with the new Version 2 for the same project. Stats would be interesting - well to me anyway! The ATMega8 is definitely a 'supported' player again - although its lack of useful timers will still limit what it can be used for!

BUT - don't forget, you can carry on using your Version 1 code simply by changing the WebbotLib directory at code generation time.

Just released a new application called Webbot Downloader. This allows you handle all of my apps in one central place, including automatic downloads to your computer when something changes.Check it out here: http://webbot.org.uk/iPoint/48.page

Edit: 13 Feb 2011 - New version released to fix a new problem caused by SourceForge changing their site.Edit: 17 Feb 2011 - Fixed another (SourceForge related) issue which stopped it downloading WebbotLib itself

Main changes are to add WebbotLib V2 and also to let you know if there is a new version of the downloader ! I cant get it to auto-overwrite itself whilst it is running.

No docs yet for WebbotLib V2 (am working on it) - but you MUST use Project Designer to create your code - no more sys/*.h files. You can still access all the low-level stuff to add, at runtime, support for any bits'n'pieces not directly supported by Project Designer.

So the original version of WebbotLib (V1) is planned to be phased out in the next month or two - unless anyone can give me a valid reason !

Is there a way to set the PWM frequency for the motor driver? I ask, since I am worried that it is too high for my motor driver. I'm using the ST L293D, and in the datasheet it says:

"This device is suitable for use in switching applications at frequencies up to 5 kHz" (First page, last paragraph under "Description")

It would be nice to be able to set the frequency for different conditions. IIRC, I heard that greater efficiency can be achieved at lower frequencies, with the trade-off being audible hum (for freq. between 30 Hz and 20k Hz) or vibration (for freq. below 30 Hz). I think for battery powered motors, efficiency may be more important in some conditions than sound or vibration.

I've done a 'memo to self' to remind me to look at it for the next release - as it will need a new Project Designer as well as libraries. As you've probably noticed it currently uses 10kHz. Having said that I have successfully used it with a L293D but not sure if its a ST one or not though (too faded to read!).

Edit - Coding and docs have been completed - so will definitely be in the next release.