[Bug 548] New: Comedi Analog Out does not work anymore

For more infomation about this bug, visit
Summary: Comedi Analog Out does not work anymore
Product: OCL
Version: trunk
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Hardware
AssignedTo: orocos-dev [..] ...
ReportedBy: ruben [dot] smits [..] ...
CC: orocos-dev [..] ...
Estimated Hours: 0.0

Hi,

i'm experiencing some problems with my comedi analog out device (recent
problems due to ocl code change),

i checked the svn log of ComediSubDeviceAOut.cpp and saw a lot of changes which
are apparently only compile-checked, so for now i think these changes are the
reason for my problem. Can someone give me some explanation about these changes
so i can try to resolve this bug.

Ruben

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

--- Comment #9 from Peter Soetens
<peter [dot] soetens [..] ...> 2008-05-14 13:48:45 ---
This patch also checks ranges:

$ svn di ComediSubDeviceAOut.cpp
Index: ComediSubDeviceAOut.cpp
===================================================================
--- ComediSubDeviceAOut.cpp (revision 29276)
+++ ComediSubDeviceAOut.cpp (working copy)
@@ -117,6 +117,8 @@

int ComediSubDeviceAOut::rawWrite( unsigned int chan, int value )
{
+ if (value < 0) value = 0;
+ if (value > rrange) value = rrange;
if ( myCard )
return myCard->write( _subDevice, chan, _sd_range[chan],
_aref[chan], (unsigned int)(value) );
@@ -137,7 +139,10 @@

int ComediSubDeviceAOut::write( unsigned int chan, double dvalue )
{
- unsigned int value = (unsigned int)(dvalue - min[chan]) *
resolution(chan);
+ //limit dvalue to min and max values
+ if(dvalue + if(dvalue>max[chan]) dvalue=max[chan];
+ unsigned int value = (unsigned int)((dvalue - min[chan]) *
resolution(chan));
if ( myCard )
return myCard->write( _subDevice, chan, _sd_range[chan],
_aref[chan], value );

$ svn ci ComediSubDeviceAOut.cpp -m"Fix for bug #548: Comedi Analog Out does
not work anymore.
Check ranges of function arguments.
> "
Sending ComediSubDeviceAOut.cpp
Transmitting file data .
Committed revision 29277.

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

Peter Soetens
<peter [dot] soetens [..] ...> changed:

What |Removed |Added
--------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED

--- Comment #8 from Peter Soetens
<peter [dot] soetens [..] ...> 2008-05-14 13:24:46 ---
(In reply to comment #7)
> Created an attachment (id=289)
--> (https://www.fmtc.be/bugzilla/orocos/attachment.cgi?id=289) [details]
> fixes comediAOut write function
>
> This patch works perfectly for me.

You should use -min[chan] instead of +max[chan]. This is because your device
could be 0 -> 10V, (0->4096) in which case, your rule will be wrong.

The min/max check is indeed necessary. I'll commit that part.

Peter

Ruben Smits's picture

[Bug 548] Comedi Analog Out does not work anymore

On Wednesday May 14 2008 13:24:46 Peter Soetens wrote:
> For more infomation about this bug, visit
>
>
> Peter Soetens
<peter [dot] soetens [..] ...> changed:
>
> What |Removed |Added
> --------------------------------------------------------------------------
> Status|ASSIGNED |RESOLVED
> Resolution| |FIXED
>
>
>
> --- Comment #8 from Peter Soetens
<peter [dot] soetens [..] ...> 2008-05-14
> 13:24:46 --- (In reply to comment #7)
>
> > Created an attachment (id=289)
>
> --> (https://www.fmtc.be/bugzilla/orocos/attachment.cgi?id=289) [details]
>
> > fixes comediAOut write function
> >
> > This patch works perfectly for me.
>
> You should use -min[chan] instead of +max[chan]. This is because your
> device could be 0 -> 10V, (0->4096) in which case, your rule will be wrong.
>
> The min/max check is indeed necessary. I'll commit that part.

Ok, thanks. Our robot will be pleased to be able to move slow again ;)

Ruben

Ruben Smits's picture

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

--- Comment #7 from Ruben Smits <ruben [dot] smits [..] ...> 2008-05-14 13:11:39 ---
Created an attachment (id=289)
--> (https://www.fmtc.be/bugzilla/orocos/attachment.cgi?id=289)
fixes comediAOut write function

This patch works perfectly for me.

Ruben

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

--- Comment #6 from Peter Soetens
<peter [dot] soetens [..] ...> 2008-05-14 13:10:12 ---
I can't believe I wrote this...

$ svn di ComediSubDeviceAOut.cpp
Index: ComediSubDeviceAOut.cpp
===================================================================
--- ComediSubDeviceAOut.cpp (revision 29275)
+++ ComediSubDeviceAOut.cpp (working copy)
@@ -137,7 +137,7 @@

int ComediSubDeviceAOut::write( unsigned int chan, double dvalue )
{
- unsigned int value = (unsigned int)(dvalue * resolution(chan) -
min[chan]);
+ unsigned int value = (unsigned int)(dvalue - min[chan]) *
resolution(chan);
if ( myCard )
return myCard->write( _subDevice, chan, _sd_range[chan],
_aref[chan], value );

$ svn ci ComediSubDeviceAOut.cpp -m"Fix for bug #548: Comedi Analog Out does
not work anymore.
> correct double->int conversion.
> "
Sending ComediSubDeviceAOut.cpp
Transmitting file data .
Committed revision 29276.

Ruben Smits's picture

[Bug 548] Comedi Analog Out does not work anymore

On Wednesday May 14 2008 13:10:12 Peter Soetens wrote:
> For more infomation about this bug, visit
>
>
>
>
> --- Comment #6 from Peter Soetens
<peter [dot] soetens [..] ...> 2008-05-14
> 13:10:12 --- I can't believe I wrote this...
>
> $ svn di ComediSubDeviceAOut.cpp
> Index: ComediSubDeviceAOut.cpp
> ===================================================================
> --- ComediSubDeviceAOut.cpp (revision 29275)
> +++ ComediSubDeviceAOut.cpp (working copy)
> @@ -137,7 +137,7 @@
>
> int ComediSubDeviceAOut::write( unsigned int chan, double dvalue )
> {
> - unsigned int value = (unsigned int)(dvalue * resolution(chan) -
> min[chan]);
> + unsigned int value = (unsigned int)(dvalue - min[chan]) *
> resolution(chan);

it should be:
(unsigned int)((dvalue + max[chan])*resolution)
or
(unsigned int)((dvalue - min[chan])*resolution)

because resolution is also a double, or am i completely wrong here?

Ruben

Ruben Smits's picture

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

--- Comment #5 from Ruben Smits <ruben [dot] smits [..] ...> 2008-05-14 12:07:55 ---
After adding some log messages i get the following:

resolution(0)=204.75
min[0]=-10
max[0]=10

unsigned int value = (unsigned int)(dvalue * resolution(chan) - min[chan]);

value should be 2048 if dvalue is 0.0, this equation results in (uint)(10)
which is completely wrong, my guess would be that the equation should look
something like this:

unsigned int value = (unsigned int)((dvalue + max[chan])*resolution)

value is 0 if dvalue = -10
value is 2048 if dvalue = 0.0
value is 4096 if dvalue = 10

i do not know yet what value should become if dvalue exceeds max or min.

Ruben

Ruben Smits's picture

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

--- Comment #4 from Ruben Smits <ruben [dot] smits [..] ...> 2008-05-14 11:43:30 ---
It is still not completely fixed,

if i ask a value of 0.0, the ComediSubDevAOut still sends -10V
if i ask a value of 1.0 the voltage increases, increasing the value makes the
voltage go through zero to its maximum voltage and then goes back to -10V,

still not the desired behaviour.

Ruben

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

Peter Soetens
<peter [dot] soetens [..] ...> changed:

What |Removed |Added
--------------------------------------------------------------------------
Status|NEW |ASSIGNED
Target Milestone|--- |1.6.0

--- Comment #3 from Peter Soetens
<peter [dot] soetens [..] ...> 2008-05-13 22:47:43 ---
(In reply to comment #0)
> Hi,
>
> i'm experiencing some problems with my comedi analog out device (recent
> problems due to ocl code change),
>
> i checked the svn log of ComediSubDeviceAOut.cpp and saw a lot of changes which
> are apparently only compile-checked, so for now i think these changes are the
> reason for my problem. Can someone give me some explanation about these changes
> so i can try to resolve this bug.

I'll commit this fix to trunk:

$ svn di hardware/comedi/dev/ComediSubDeviceAIn.cpp
hardware/comedi/dev/ComediSubDeviceAOut.cpp
Index: hardware/comedi/dev/ComediSubDeviceAIn.cpp
===================================================================
--- hardware/comedi/dev/ComediSubDeviceAIn.cpp (revision 29271)
+++ hardware/comedi/dev/ComediSubDeviceAIn.cpp (working copy)
@@ -88,6 +88,8 @@
highest(i);
lowest(i);
}
+ // Load rrange value.
+ rawRange();
}

void ComediSubDeviceAIn::rangeSet(unsigned int chan, unsigned int range
/*=0*/)
Index: hardware/comedi/dev/ComediSubDeviceAOut.cpp
===================================================================
--- hardware/comedi/dev/ComediSubDeviceAOut.cpp (revision 29271)
+++ hardware/comedi/dev/ComediSubDeviceAOut.cpp (working copy)
@@ -89,6 +89,8 @@
highest(i);
lowest(i);
}
+ // Load rrange value.
+ rawRange();
}

void ComediSubDeviceAOut::rangeSet(unsigned int chan, unsigned int range
/*=0*/)

'We' forgot to initialise the rrange parameter, used for resolution
calculation. It was set to '0' by default.

Sorry for hurting your robot :-(

Peter

$ svn ci hardware/comedi/dev/ComediSubDeviceAIn.cpp
hardware/comedi/dev/ComediSubDeviceAOut.cpp -m"Fix for bug #548: Comedi Analog
Out does not work anymore
> Initialise the range calculation.
> "
Sending hardware/comedi/dev/ComediSubDeviceAIn.cpp
Sending hardware/comedi/dev/ComediSubDeviceAOut.cpp
Transmitting file data ..
Committed revision 29275.

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

--- Comment #2 from Peter Soetens
<peter [dot] soetens [..] ...> 2008-05-13 17:49:53 ---
(In reply to comment #0)
> Hi,
>
> i'm experiencing some problems with my comedi analog out device (recent
> problems due to ocl code change),

If you want people to help out, you could also provide some details, like what
'some problems' are and which functions you are calling.

Peter

[Bug 548] Comedi Analog Out does not work anymore

For more infomation about this bug, visit

Peter Soetens
<peter [dot] soetens [..] ...> changed:

What |Removed |Added
--------------------------------------------------------------------------
CC| |peter [dot] soetens [..] ...

--- Comment #1 from Peter Soetens
<peter [dot] soetens [..] ...> 2008-05-13 17:45:37 ---
(In reply to comment #0)
> Hi,
>
> i'm experiencing some problems with my comedi analog out device (recent
> problems due to ocl code change),
>
> i checked the svn log of ComediSubDeviceAOut.cpp and saw a lot of changes which
> are apparently only compile-checked, so for now i think these changes are the
> reason for my problem. Can someone give me some explanation about these changes
> so i can try to resolve this bug.

They were discussed in bug report #488. You can check the attached patches for
any causes.