- Forum
- RIO I/O Expansion Card and Navigation Computer
- Linux Installation & Programming
- reading analog input from a sensor
reading analog input from a sensor
- aarontan
- Topic Author
5 years 2 months ago #29533871
by aarontan
reading analog input from a sensor was created by aarontan
Hello,
I have a sensor that is outputting between 0 to 5v. I connected this to my roboteq controller (sdc2130) on pin 11, which I believe is ANA4. All the other analog pins are taken up with the encoders. I'd like to modify this github.com/ecostech/roboteq_diff_driverpackage to read analog input from my sensor.
From the github package, it seems that when I want to control the motors, I can simply write the following in the cpp file to send a specified rpm command.
From this, I assume I can read with the following (I got this syntax from the manual as attached at the bottom)? I get a compile error when I do this.
I have already written the following to set up the analog inputs (i want to read as an absolute value bettween 0-5v, and the input will not be used as a command or feedback, I just want to read the values to do additional calculations):
The following is the information obtained from the roboteq manual. I am wondering, how do i use this? Please let me know what is the proper way to incorporate this into the cpp file from the package.
AI - Read Analog Inputs
Alias: ANAIN
HexCode: 10
CANOpen id: 0x6401
Description:
Reports the raw value in mV of each of the analog inputs that are enabled. Input that is
disabled will report 0. The total number of Analog input channels varies from one control-
ler model to another and can be found in the product datasheet.
Syntax Serial:
?AI [cc]
Argument: InputNbr
Min: 1 Max: Max Number of Analog Inputs
Syntax Scripting: result = getvalue(_AI, cc)
result = getvalue(_ANAIN, cc)
Reply:
AI=nn
Type: Signed 16-bit
Min: 0 Max: 5300
Where:
cc = Analog Input number
nn = Millivolt for each channel
I have a sensor that is outputting between 0 to 5v. I connected this to my roboteq controller (sdc2130) on pin 11, which I believe is ANA4. All the other analog pins are taken up with the encoders. I'd like to modify this github.com/ecostech/roboteq_diff_driverpackage to read analog input from my sensor.
From the github package, it seems that when I want to control the motors, I can simply write the following in the cpp file to send a specified rpm command.
controller.write("!S 1 rpm \r");
From this, I assume I can read with the following (I got this syntax from the manual as attached at the bottom)? I get a compile error when I do this.
double L1 = controller.read("?AI, 4");
I have already written the following to set up the analog inputs (i want to read as an absolute value bettween 0-5v, and the input will not be used as a command or feedback, I just want to read the values to do additional calculations):
controller.write("^AMOD 4 1\r");
controller.write("~AINA 4");
The following is the information obtained from the roboteq manual. I am wondering, how do i use this? Please let me know what is the proper way to incorporate this into the cpp file from the package.
AI - Read Analog Inputs
Alias: ANAIN
HexCode: 10
CANOpen id: 0x6401
Description:
Reports the raw value in mV of each of the analog inputs that are enabled. Input that is
disabled will report 0. The total number of Analog input channels varies from one control-
ler model to another and can be found in the product datasheet.
Syntax Serial:
?AI [cc]
Argument: InputNbr
Min: 1 Max: Max Number of Analog Inputs
Syntax Scripting: result = getvalue(_AI, cc)
result = getvalue(_ANAIN, cc)
Reply:
AI=nn
Type: Signed 16-bit
Min: 0 Max: 5300
Where:
cc = Analog Input number
nn = Millivolt for each channel
Please Log in or Create an account to join the conversation.
- Gabriel_Isko
5 years 2 months ago - 5 years 2 months ago #29533873
by Gabriel_Isko
Replied by Gabriel_Isko on topic reading analog input from a sensor
We recommend taking a look at our
C++ API documentation
. We provide the GetValue() function, which should be able to read your analog pin value. I am surprised that the ROS driver isn't using it. I suspect it is using a different serial library, which you will have to refer to in order to set up a stream to and from the IO stream Linux will set up with our controller.
I will also be moving this to the Linux section of our forum.
I will also be moving this to the Linux section of our forum.
Please Log in or Create an account to join the conversation.
- Forum
- RIO I/O Expansion Card and Navigation Computer
- Linux Installation & Programming
- reading analog input from a sensor
Time to create page: 0.051 seconds