#robotics Logs

Jan 10 2021

#robotics Calendar

12:54 AM rue_mohr: ok laplace transform for a RC low pass
01:01 AM rue_mohr: H(s) = \
02:36 AM mrdata_: .why
02:36 AM mrdata_: you have an app that wants a laplace transform?
02:38 AM rue_mohr: no I'm working on a coded filter that approximates a low pass filter with a 1k resistor and a 1uF cap
02:38 AM rue_mohr: the code is nice and simple but the effect of the constants doesn't make sense
03:37 AM mrdata_: ok, so in any particular delta-T interval you have voltage difference stored vs at the terminal and so current flowing in or out. you can calculate current flow with lumped elements
03:39 AM mrdata_: but make sure to include capacitor ESR
04:12 AM rue_mohr: hu?
04:12 AM rue_mohr: its code
06:26 AM mrdata_: rue_mohr, yes
06:26 AM mrdata_: lumpe element model is implemented programmatically
06:26 AM mrdata_: *lumped
06:28 AM rue_mohr: http://paste.debian.net/1180431/
06:28 AM rue_mohr: mrdata_, ^^^ what you on about
06:28 AM rue_mohr: thats my sweep of the low-pass code
06:28 AM rue_mohr: I spent hours and hours feeling out the magic constant that puts the -3db at the same place as a 1k/1uF lowpass filter
06:29 AM rue_mohr: I want to know how to just calculate the magic constant
06:29 AM mrdata_: you have an iterative solver; your delta-t is ((M_PI*2)/SR)
06:29 AM rue_mohr: ok
06:30 AM rue_mohr: (yes I understand and agree)
06:30 AM rue_mohr: I been at this a while today, its 4am
06:30 AM mrdata_: 10.4929582 is your magic constant?
06:30 AM rue_mohr: yea
06:30 AM mrdata_: ok
06:30 AM mrdata_: good
06:31 AM rue_mohr: the -3db is about 159.15494Hz
06:31 AM rue_mohr: but, if I knew thats where I wanted it, how could I calculate that constant?
06:31 AM mrdata_: so your ESR on your real cap is, what
06:31 AM rue_mohr: I'm ok with an ideal cap here
06:31 AM mrdata_: no youre not
06:31 AM rue_mohr: I have a pole
06:32 AM rue_mohr: it IS an RC system
06:32 AM rue_mohr: I'm not building this in the real world from parts, I'm leaving it as code
06:32 AM mrdata_: and the schematic is like, https://www.electronics-tutorials.ws/filter/filter_2.html ?
06:32 AM rue_mohr: yes
06:33 AM mrdata_: good
06:33 AM rue_mohr: there is no load on the divider and the cap is ideal
06:33 AM rue_mohr: http://ruemohr.org/~ircjunk/tempimage/foo.png
06:33 AM rue_mohr: thats with a different constant
06:33 AM rue_mohr: gain in db
06:34 AM mrdata_: ok, so load on output has infinite impedance, ok
06:34 AM rue_mohr: yep
06:34 AM mrdata_: (not very realistic tho)
06:34 AM rue_mohr: agreed, its not a simulation for building it in analog tho
06:34 AM mrdata_: but sure, sometimes that drives a FET so not far off
06:34 AM rue_mohr: its a digital filter
06:35 AM rue_mohr: the input is an ADC, the output is a PWM generator
06:36 AM rue_mohr: the goal is to flatline the freq response of the servo right up to the slew rate limit
06:44 AM mrdata_: the 2 pi factor as written is messing me up
06:44 AM mrdata_: whats your sample rate
06:45 AM rue_mohr: apparenltly the math libary doesn't have a premade 2Pi
06:45 AM mrdata_: in samples per second
06:45 AM rue_mohr: SR is the sample rate
06:45 AM rue_mohr: in samples per second
06:45 AM mrdata_: 10 k samples/second then
06:45 AM rue_mohr: there are 2 seconds of samples tested for each freq
06:45 AM rue_mohr: yes
06:46 AM mrdata_: so you have 0.0001 s = 1 interval
06:46 AM rue_mohr: the first second of samples is "discarded" for the filter to settle, the last second is run thru the peak thinger for the result
06:46 AM rue_mohr: 1s/10000
06:46 AM rue_mohr: so yes
06:47 AM rue_mohr: huh, my high pass version has gain
06:47 AM rue_mohr: heh
06:48 AM rue_mohr: that would imply I blew the formula
06:56 AM mrdata_: ugh. i am rusty with calculus
06:57 AM rue_mohr: :)
06:57 AM mrdata_: V/R = I; compute the charge moved thru the R in that time Q = I dt, into the cap; but the cap is filling up so as it does the voltage difference changes
06:58 AM mrdata_: Q = C dV
06:58 AM mrdata_: but also there is ESR
07:01 AM rue_mohr: oh I have a library for doing it all e^-t/RC
07:02 AM rue_mohr: I'm not using that cause its too cpu intensive
07:02 AM rue_mohr: I can foward that code if you want tho
07:04 AM rue_mohr: or did you mean for high pass
07:05 AM mrdata_: and E = .5 CV^2
07:06 AM rue_mohr: t?
07:06 AM rue_mohr: E goes up with capcitance?
07:07 AM mrdata_: energy stored in the cap is proportional to capacitance, yes
07:07 AM mrdata_: dt = 0.0001 here
07:07 AM rue_mohr: oh I thught you meant E is voltage
07:07 AM mrdata_: no
07:07 AM mrdata_: V is voltage
07:07 AM rue_mohr: k
07:08 AM mrdata_: so as the cap fills up, the voltage difference changes, so the current changes
07:09 AM mrdata_: and thats what is messing me up
07:09 AM rue_mohr: the voltage on the cap changes with current
07:10 AM mrdata_: yes
07:10 AM rue_mohr: Vc += Ic/C
07:10 AM rue_mohr: every loop
07:10 AM rue_mohr: which is why the sample rate messes with it so much
07:10 AM rue_mohr: the gain of the itterations needs to be balanced
07:11 AM mrdata_: ive been awake all night and i'm gapping out, here
07:11 AM rue_mohr: :)
07:11 AM rue_mohr: to make the low pass I did this:
07:12 AM rue_mohr: vi ---\/\/\/\----Vo-----||------- 0
07:12 AM rue_mohr: Vo = I/C
07:12 AM rue_mohr: (t is implied here)
07:13 AM rue_mohr: I = (Vi - Vo)/R
07:13 AM rue_mohr: so
07:13 AM rue_mohr: Vo = (Vi - Vo)/R / C
07:14 AM rue_mohr: if you then melt R and C into a constant you get that code
07:14 AM rue_mohr: er, something is missing
07:15 AM rue_mohr: maybe I cant think at 4am
07:15 AM rue_mohr: there should be an integrator for Vc
07:15 AM rue_mohr: ah its...
07:15 AM rue_mohr: mushed in
07:15 AM rue_mohr: hmm
07:16 AM rue_mohr: no, no I didn't need Vc
07:16 AM rue_mohr: Vc is Vo
07:16 AM rue_mohr: are you seeing what I did
07:17 AM rue_mohr: cause I don't know if I am
07:18 AM rue_mohr: the capcitor accumulates based on its current
07:57 AM mrdata_: ish; i'm just trying to derive a formula for that magic constant
07:59 AM mrdata_: oh! we can apply rise time formula to this
08:00 AM mrdata_: if the input signal is below the cutoff frequency then the cap will get chrged to the input voltage within the interval
08:00 AM mrdata_: but if the input signal exceeds the cutoff frequency then it wont
08:01 AM mrdata_: e^(-t/RC) is too intensive for this, but you are using trig anyway?
08:02 AM mrdata_: but you could fill out a table
08:02 AM mrdata_: whats your memory overhead
08:03 AM mrdata_: ie: precompute 10,000 values and store those, then just do table lookup with the microcontroller when needed
08:03 AM mrdata_: or 1000 values if it's very tight
08:04 AM mrdata_: anyway i must sleep
08:04 AM mrdata_: nn
12:16 PM rue_mohr: heh thats what my first itteration code does
12:16 PM rue_mohr: void timeStep( RCLP_t * this, double t) {
12:16 PM rue_mohr: // there is a more unified version of this calculation I can quite muster in my head.
12:16 PM rue_mohr: if (this->E > this->V0) {
12:16 PM rue_mohr: this->V0 = this->V0 + (this->E - this->V0) * (1.0 - exp( -(t /(this->R*this->C))) );
12:16 PM rue_mohr: } else {
12:16 PM rue_mohr: this->V0 = this->E + (this->V0 - this->E) * (exp( -(t /(this->R*this->C))) );
12:16 PM rue_mohr: }
12:16 PM rue_mohr: }
12:16 PM rue_mohr: charge vs discharge
12:17 PM rue_mohr: it actually works on either side of the cutoff freq
12:17 PM rue_mohr: then main() does
12:17 PM rue_mohr: for(t = 0; t < (M_PI*2*CYCLES); t += ((M_PI*2)/SR)) {
12:17 PM rue_mohr: Vi = sin(t*freq);
12:17 PM rue_mohr: F.E = Vi;
12:17 PM rue_mohr: timeStep( &F, 1.0/SR) ;
12:17 PM rue_mohr: Vo = F.V0;
08:48 PM rue_mohr: so it turns out, the low pass filter I made can be a high pass filter if I change the constants
11:37 PM flav0r: DUDES !
11:37 PM flav0r: WHATS NEW ???