Show Posts
Pages: [1] 2 3 ... 8
1  Development / Other Software Development / Re: Making USB bMaxPower value dynamic w/ Arduino 1.0.1 on: June 01, 2012, 02:32:06 am
Quote
Ok - I'll go away and research the correct type and stick a wrapper around it.

I didn't mean to pressure you into doing work you didn't want to do.  As it is now, the code is useful (thank you).  I just know that the hurdle for core modifications is very high; essentially you have to have something solid and ready-to-merge and there has to be a recognizable demand.  Bear in mind that, even if you do everything I suggest, there is still an unknown possibility that the modification will never be included.

Quote
I was originally more seeking guidance if its the right track at least..

It passes a basic "smell test" (as in, it doesn't stink).  Like @jwatte, I have concerns.  Unfortunately, in this case, I suffer from 3rd Order Ignorance: Lack of Process so I can't offer more than "I have concerns".


Thanks - appreciate the clarifications. I'll have a look at the submission requirements, and go through and test on what I can. I agree its inelegant - but since I know that Leonardo clones like Freetronics LeoSticks are ideal for use as a Keyboard/Controller HID given its size - I don't know if '500ma' and the resultant errors on low power hubs/keyboards etc is the best solution either.

I dont think it should be dynamic or set without care - but it should be at least adjustable...
2  Development / Other Software Development / Re: Making USB bMaxPower value dynamic w/ Arduino 1.0.1 on: June 01, 2012, 01:41:42 am

If you want your solution to be considered for the core you will have to use the correct data-type.  It will also require a "wrapper function" to perform validation.

Quote
I confirmed this using USBDeviceView on Win7 x64.

What about Mac and Linux?  Do you have a way to test?


Aside: The link in your signature does not work for me.


Ok - I'll go away and research the correct type and stick a wrapper around it. I was originally more seeking guidance if its the right track at least.. but yeah I'll go do more work on it...
3  Development / Other Software Development / Re: Making USB bMaxPower value dynamic w/ Arduino 1.0.1 on: June 01, 2012, 01:13:50 am
Doing this is a bad idea, though.
The reason is that, once you have negotiated on the bus, that value is fixed. You can't change your mind later, because the user may have plugged in other devices, enough so there's no more power to draw. Thus, the amount of power you want to draw AT MOST should be value you negotiate, and this is known a priori because you (presumably) know how much each component of your circuit draws.
The headers should test whether the device power macro is already set, and if so, not re-define it -- use your value. That value should be constant.


yes, you dont want to change it mid-script, you do want to be able to adjust it *per* script. If you plug a leonardo into a Mac keyboard at the moment, it produces an annoying error. If you intend to use the Leo as a HID Keyboard device for example (i.e, just the AVR running), then you might just want to set it to 100ma for that script to avoid Errors when plugged into a keyboard on the host - such as when made into a 'workstation locking dongle' or a PS3 controller.


Is int the correct data-type?

the current macro simply uses 500 as the value - so not sure...

The 32u4 chips present a few scenarios where there will be few if any external devices attached as they can be quite complex HID devices in their own right smiley
4  Development / Other Software Development / Re: Making USB bMaxPower value dynamic w/ Arduino 1.0.1 on: June 01, 2012, 12:51:03 am

Is setup too late?  I assume, by the time setup is called, the USB controller has already fetched the descriptor.


It seems to work fine in practice - From what I can determine it doesn't call it until something needs it - so in the example sketch the first thing is Serial. - as long as its place before that it works otherwise it'll default back to the old 500ma . I confirmed this using USBDeviceView on Win7 x64.

The CDC USB Decsriptors are set via the Bootloader - and they are hard coded to 100ma. So the above effects only a Sketches USB usage from what I can tell.
5  Development / Other Software Development / Making USB bMaxPower value dynamic w/ Arduino 1.0.1 on: June 01, 2012, 12:31:45 am
Hi all,

I originally posted this into Programming Questions but the only response was 'how many people would have Leonardos do you think?". Well, since its also an Arduino Core question as well as a request to see if I've done this properly, I'll post it in here.

I've been playing with what is ostensibly a Leonardo clone - the Freetronics LeoStick. I've compiled the new Arduino 1.0.1 Caterina bootloader and using the new 1.0.1 USBCore.cpp/.h files etc.
The current USB_CONFIG_POWER_MA Macro used as part of the D_CONFIG macro called out of USBCore.cpp is hardcoded at 500ma.
This can cause errors to appear when plugging the device into many Keyboard based USB Ports or Hubs. I'm lead to believe particularly on MacOSX ?

So I've tried to hack in, unfortunately (I hate modifying core code smiley-sad ) the ability to alter this in a sketch, so you can set it in the setup() function. Is this the best way to do this?
This works, and allows you to set any arbitrary integer value to be used for the negotiation of the sketch comport.

Edit USBCore.cpp . At line 47 Add the line
Code:
int usbMaxPower = 500;

Edit USBCore.h. Edit the D_CONFIG and set line 284 to be:
Code:
#define D_CONFIG(_totalLength,_interfaces) \
   { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(usbMaxPower) }

By default, it will now negotiate 500ma. However in your sketch, at the top, define
"extern int usbMaxPower" Then you can do in setup(), before calling any USB descriptors (i.e, one of the first things)
"usbMaxPower = 100;"

Test script - the Example Leonardo KeyboardSerial Sketch with the above additions.:
Code:
/*
// Comments Snipped
created 21 Oct 2011
 modified 27 Mar 2012
 by Tom Igoe
 
This example code is in the public domain.
*/
extern int usbMaxPower; // Import usbMaxPower from USBCore.cpp

void setup() {
  // Set USB MaxPower to be 150
  usbMaxPower = 150;
  // open the serial port:
  Serial.begin(9600);
  // initialize control over the keyboard:
  Keyboard.begin();
  // Print usbMaxPower int to Serial to check during setup
  Serial.print("usbma ");
  Serial.println(usbMaxPower);
}

void loop() {
  // check for incoming serial data:
  if (Serial.available() > 0) {
    // read incoming serial data:
    char inChar = Serial.read();
   
    // Print usbMaxPower int to Serial to check
    Serial.print("usbma ");
    Serial.println(usbMaxPower);

    // Type the next ASCII value from what you received:
    Keyboard.write(inChar+1);
  } 
}

Voila! Script defineable usbMaxPower values... albeit very klunky and involving hacks to the USBCore.cpp/USBCore.h - which I was trying to avoid.

Is this the best way to accomplish this for now with 1.0.1 ? What is the long term plans around the USB Descriptors ?

Adrian
6  Using Arduino / Programming Questions / Re: Best way to adjust the USB ConfigDescriptor bMaxPower in 1.0.1 on a Leonardo? on: May 31, 2012, 09:31:45 am
How many people do you suppose have Leonardos already?

I was asking broadly - Theres still a general programming question though ? Anyway.. no worries..
7  Using Arduino / Programming Questions / Re: Best way to adjust the USB ConfigDescriptor bMaxPower in 1.0.1 on a Leonardo? on: May 31, 2012, 01:28:09 am
No comments ? Or is this in the wrong Forum ?
8  Using Arduino / Programming Questions / Best way to adjust the USB ConfigDescriptor bMaxPower in 1.0.1 on a Leonardo? on: May 30, 2012, 08:32:31 am
Hi all,
I've been playing with what is ostensibly a Leonardo clone - the Freetronics LeoStick. I've compiled the new Arduino 1.0.1 Caterina bootloader and using the new 1.0.1 USBCore.cpp/.h files etc.

The current USB_CONFIG_POWER_MA Macro used as part of the D_CONFIG macro called out of USBCore.cpp is hardcoded at 500ma.
This can cause errors to appear when plugging the device into many Keyboard based USB Ports or Hubs. I'm lead to believe particularly on MacOSX ?

So I've tried to hack in, unfortunately (I hate modifying core code smiley-sad ) the ability to alter this in a sketch, so you can set it in the setup() function. Is this the best way to do this?
This works, and allows you to set any arbitrary integer value to be used for the negotiation of the sketch comport.

Edit USBCore.cpp . Around line 47 or so, you'll see
Code:
extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;

Add the line
Code:
int usbMaxPower = 500;


Edit USBCore.h. Edit the D_CONFIG define around line 284 to be:
Code:
#define D_CONFIG(_totalLength,_interfaces) \
   { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(usbMaxPower) }

By default, it will now negotiate 500ma. However in your sketch, at the top, define
Code:
extern int usbMaxPower


Then you can do in setup(), before calling any USB descriptors (i.e, one of the first things)
Code:
usbMaxPower = 100;

Voila! Script defineable usbMaxPower values... albeit very klunky and involving hacks to the USBCore.cpp/USBCore.h - which I was trying to avoid.

Is this the best way to accomplish this for now with 1.0.1 ?

Adrian
9  Forum 2005-2010 (read only) / Troubleshooting / Re: Windows 7 and arduino 17: AARRGGG! on: August 26, 2009, 02:38:35 am
Yup.. I'm still running the older beta - 7100.. but the RTM version went out on technet the other night I think (it was due - haven't checked yet...)

I'm sure i've uploaded a few times with 0017 fine under win7(7100)... I'll go and try shortly to confirm for sure...
10  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Mega - serial1, 2 und 3 - initialization fails on: August 25, 2009, 04:24:35 am
Running XPSP3 and also Vista 64 and Win7 (7100) and haven't tried more than three Serial's in 0017(Serial, Serial2-3) yet, but under 0016 I had all 4 running (Serial, Serial1-3)

No problems here.
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: How does the Kalman Filter Works? on: August 17, 2009, 06:29:49 pm
Hi - I will say right up - I really suck at maths smiley Also - I don't have anywhere near the grasp of Kalman that some of the other guys working on the Nunchuk/MP integration have.

But, from my lucid understanding.. if you want to smooth *just* an accelerometer, then... "This is not the filter you are looking for ".... smiley
It can work with just one input - but its a lot of work and Im not sure how much benefit it would bring to a single input versus iterative integrations of two.

This is all *very* lay terminology - so forgive me maths geniuses smiley Kalman smooths 'noisy' samples, and does that by integrating another set of samples from a sensor that is 'more accurate' over shorter times based on 'weighting' the results between the two.

The best example I can give is with the accelerometers and the gyro.

The accelerometers suffer very little drift over time compared to the gyro but are very sensitive, even at rest. Small movements can be lost. The Gyro's are very accurate in short bursts, but rapidly (compared to accelerometer drift) get distorted by drift... One could say the two sensors exhibit the complimentary behavior of each other.

So by using Kalman, we can predict an accurate result and cancel out noisy (i.e, not fitting within the prediction matrix for that particular sample ), thus smoothing the input from each and then combine the results to produce a set of very accurate numbers - using one sensor to cancel out the other sensors issues. In this instance, the Kalman wants to 'prefer' the gyro in the first instance, but as sampling continues, it wants to shift that weight to preferring the now more accurate accelerometer data. This produces a "smooth" plot of movement, without confusing plots based on 'noise' or 'drift' within each particular sensor. The hard part is tweaking those 'weightings' to produce smooth data - thats all the tuning that people refer to with Kalman. Not only the weighting of the integration, but also the weighting of the first stage of 'smoothing'..

One could also modify GPS data to interpolate with the accelerometers - I say modify because to the best of my knowledge, you need everything in the same "units of measure", thus you need to compute the acceleration between two GPS sample points and the Heading as discreet values and then use them to integrate in Kalman (i.e, you can't just plonk in the lat/lng and use that as an Int smiley )

If you haven't seen Tom Pykes excelent MAV-blog, then thats probably one of the more comprehensive explanations of how to apply Kalman filters to IMU's.. http://tom.pycke.be/mav/71/kalman-filtering-of-imu-data

I'd love to have a better understanding of the actual Maths... but like I said originally.. I suck at maths  ;D My apologies if I have really butchered this explanation....
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arduino and GPS module on: August 27, 2009, 03:35:59 am
someone might have a more specific answer - but its probably no different than the maths used in solving the same issue in GoogleMaps API.

If you checkout the googlemaps site, there is examples that talk about the maths needed for various conversions of co-ordinates in order to calculate distances between points given lat/lng etc etc. Also has good info on how Mercator data works (to deal with earth curvature when calculating distance between two or more points..)

So you can easily modify it to use the NMEA data instead of the GoogleMaps Waypoints.

The bigger question Im curious about - obviously the 'boundaries' of the polygon would need to be defined and stored. EEPROM would be an option, but I'd love to figure out how to read that data in from say an SD card so you could then just define the polygon say *with* googlemaps on a PC in a comfortable interface...

Anyway - I look forward to seeing what suggestions people come up with - I will have a similar requirement shortly (want to detect if current location is within the bounds of a couple of different polygons so that I can change 'operating modes'....)
13  Forum 2005-2010 (read only) / Interfacing / Re: filtering accelerometer data on: August 26, 2009, 03:40:28 am
thanks for that - the bitmath confused me for a bit...
14  Forum 2005-2010 (read only) / Interfacing / Re: filtering accelerometer data on: August 26, 2009, 03:17:37 am
Question from the peanut gallery: (great tips in this thread btw - thanks)
Quote
Or you could probably maintain a bit more precision with a 16.16 fixed point format:
<snip>
This example will give a rolling average over 64 samples.

I don't quite understand how that code extrapolates out to 64 samples - could you expand on how that comes out to 64 samples for me ?
15  Forum 2005-2010 (read only) / Interfacing / Re: Parse a KML file on an SD with a sketch ? on: September 01, 2009, 08:42:03 pm
Am I already on the right track and there is no better way ?

Or do I need to rephrase my question maybe and don't make sense (not unlikely!  ;D ) ?

Thanks everyone
Pages: [1] 2 3 ... 8