Read and Write a 4-20mA Analog input, directly from the robot

I am not using any sort of external code like python or c++. And i need to read and then write a anlog input(0) using a cb3. Like i said the input is 4-20ma and needs to control a line for the robot to pick up from a conveyor, anywhere on the conveyor.

Is the analog input a distance sensor? Or an encoder on the conveyor? Or what? :slight_smile:
And why do you need to write to the analog sensor? You can’t write to an input. Then you need to use an analog output.

If you’re using something like a distance sensor seeing an object on the conveyor, it’s not too difficult.
You will have to scale your analog input to the robot’s axis (your conveyor must be parallel to an axis on the robot. If it isn’t, it’s going to be a bit more difficult).

Before explaining more, you will have to elaborate a bit on your setup. Maybe take a picture?

I use a distance sensor, what i really mean is that i want to write it to a variable and then send it to a line or plane then the robot can pick it up, i know there are longer methods and less accurate ones but i want to learn more about this.

And no the robot it not parallel on any axis. tho i have set a Plane to the conveyor

And i know that i can just use for example events, so that if it is from 5-6ma it will go to a certain waypoint, but i want to compact it to where it can run on 1 plane and 1 move.

I don’t think there’s a built-in function for this. :slight_smile: I only know of the way I mentioned earlier. I have done the same before.

Go to the start of the pick up at the conveyor and place the robot where it would pick up the object. Then read the correct axis coordinate in the Move tab from your custom conveyor plane and read the distance sensor value.
For example X = 0.12 and AI[0] = 4,62 at the start of the conveyor.
Then move the robot and object to the other end of the conveyor and read the values.
For example X = 0.65 and AI[0] = 13.26 at the end of the conveyor.

Then you can scale the X value to the distance sensor value with a program like Graph (I honestly don’t know the math behind it and Graph is easy to use). :slight_smile: Plot the values and insert a linear curve. The program automatically makes the calculation for the linear curve.

Then you have a calculation 0.0613 * X - 0.163 which you can use in your program.
So if the sensor reads 6.5, then the math will look like this for calculating the X coordinate 0.0613 * 6.5 - 0.163 = 0.23545.
Then you can make a variable waypoint with that X coordinate. :slight_smile:

I hope this is what you’re looking for.

Thank you for your information. It has been very useful.