# Machsupport Forum

## Mach Discussion => Brains Development => Topic started by: lukejs on February 01, 2009, 08:21:18 AM

Title: Trying to make dro positive
Post by: lukejs on February 01, 2009, 08:21:18 AM
Hello,

I'm trying to use a brain to test whether the z DRO is negative, and if so multiply it by -1  (i.e. make it positive) before sending it to a modbus device. As you can see in the brainview screen shot attached, it's giving me an output of 0 rather than (in this case) 10.9079. If I make the z-axis DRO positive I get the same output (0). Surely this should work. Can anyone tell me what I'm doing wrong?

Any help is gratefully received.

Thanks,

Luke
Title: Re: Trying to make dro positive
Post by: poppabear on February 01, 2009, 09:18:44 PM
All you need is a single liine bring your Z axis dro in, then go through a formula, in that formula put Abs(A), then out to yoru modbus output

ZDro in ->Formula "Abs(A)"->your modbus address out.

scott
Title: Re: Trying to make dro positive
Post by: lukejs on February 02, 2009, 07:38:55 AM
Hi Scott,

That's great, thanks. Perhaps you can enlighten me on something else. What I'm actually trying to do is get a dro value to a modbus device. Now, if I use this formula in a brain I get the fractional part of the DRO: (A-Int(A))*10000. But it seems that DROs are actually stored to greater than 4 decimal places. So if for instance if the DRO actual value is 0.71539, what's displayed in mach3 is 0.7154, but what gets sent to my device is 7153 (i.e. the digits after the 4th dp get truncated rather than rounded). (This is all a supposition based on what's displayed in Brainview). I'm not clear which math operators I can use - for instance I would have thought Round() would be the solution but it doesn't seem to work. Do you know what math operators are available (I hadn't realised Abs worked until you suggested it), or alternatively another way to do what I'm trying to accomplish?

Thanks again,
Luke
Title: Re: Trying to make dro positive
Post by: ger21 on February 02, 2009, 11:20:09 AM
Try Format, pages 71-81 here. http://www.machsupport.com/MachCustomizeWiki/pdfs/VB-Script-Commands.pdf
Title: Re: Trying to make dro positive
Post by: lukejs on February 02, 2009, 01:59:35 PM
Surely that won't work as Format() returns a string?

Or will it automatically be converted back to a integer?
Title: Re: Trying to make dro positive
Post by: poppabear on February 02, 2009, 02:13:07 PM
you will have to change the Formatting of your DROs in you screen set to display more decimal places, read the customizing manual on how to do this.

scott
Title: Re: Trying to make dro positive
Post by: ger21 on February 02, 2009, 07:48:17 PM
Surely that won't work as Format() returns a string?

Or will it automatically be converted back to a integer?

I think your right. I was in a hurry and didn't look closely enough. I was looking for Formatnumber, but didn't see it.
Title: Re: Trying to make dro positive
Post by: poppabear on February 03, 2009, 10:33:26 AM
The "Registers" in Brains are Integer only and 16 bit.  If you want to seperate out for a "Float" or "Double" use the Modulo "%" function in your formulas.

the way I do it, is I will seperate my Double at the PLC with a modulo operator and send the interger across on register and the remainder across another, then I use
a Formula to combine them and drop that value in a DRO.  To send out a Float, I split it in Mach first then send it out, on two and recombine at the PLC........

DRO Displays:  You will have to set your DRO displays in Screen designer for how many decimal places it will show. BUT, if memory serves (and it may not), I think you are limited to a Max of 5 or 6 digits behind the decimal point.

So in desginer if you wanted to display a number like:  *********X.*********xx  you would put: 4.5f in the Format of the DRO type in designer.

scott