Force Sensing Resistor

Hi, I have been working with a humanoid arm, using an SSC-32 programmed in C#. I would like the arm to be able to pick up different sized blocks and to be able to figure out what size the block is. I am having some difficulties with this, as I am unable to get my program to return the servo position.

I have tried creating the following method:

        public void Read(string cmd)
        {
                try
                {
                    port.WriteLine(cmd);
                    port.WriteLine("\r");
                    string message = port.ReadLine();
                    Console.WriteLine(message);
                }
                catch (TimeoutException) { System.Diagnostics.Debug.WriteLine("timeout"); }
        }

I then call the method with the following input:

sc.Read("QP7");

The problem is that my program gets stuck here and the console shows nothing.

Also, I was thinking of trying to use force sensing resistors on the gripper to determine if a block had been picked up. Can the FRS be used with the SSC-32 and how should it be set up?

Thanks

Okay, I found the link telling me how to attach the force sensing resistor to the gripper. This seems to work when I test it on RIOS. I cannot, however get the code i posted earlier to work. It is good that I have the fsr working, but I still need to be able to read the values from the input and be able to query the position. I think what i’ve been doing is on the right track. It seems that the problem is with the “ReadLine” command, as this is where my program stops. if I use “Read Existing” instead, it just skips that portion altogether, telling me that maybe it is not finding anything to read at all. If anyone has any idea what the problem might be, please let me know.

I know there are C programmer here that have successfully read the Query replies from the SSC-32. I’m not a PC programmer so I’m no help. :stuck_out_tongue: Have you tried searching the forum?

Yeah but this C# stuff is really weird! I’ll see if I can dig up some C code when I get back to my “home office”.

Alan KM6VV

The ssc-32 uery command returns a single byte value in binary.

The ReadLine() function is usually used with ASCII data that has a line terminator like ‘\r’ or ‘\n’.

You may want to give Read() a try instead of ReadLine().

Also should point out that I don’t remember if Read() blocks or not so you want to make sure it either waits for a character until timeout or you have some other method of determining it returned valid data or not.

trying the read() helped some. The program now gets past the read() command, and writes a “1” to the console no matter whether i write “Q” “QP0” or “VB” (the input location of the FSR).

This is my code:

        public void Read(string cmd)
        {
            
                try
                {
                    int size = 1;
                    byte] data = new byte[size=];
                    port.Write(cmd + "\r");
                    int value = port.Read(data,0,size);
                    Console.WriteLine(value);
                }
                catch (TimeoutException) { System.Diagnostics.Debug.WriteLine("timeout"); }
        }

What I want to get now is the “VB”, which is the fsr input. It should return just one byte of information i.e. 0 to 255 if I am correct. Still, the console is reading only 1. Any thoughts?[/size]

well, um, it’s because value has the number of bytes read and that is what you are displaying with WriteLine(value).

Try displaying the contents of data instead? :open_mouth:

edit: [], Int32, Int32)](http://msdn.microsoft.com/en-us/library/34t733fh.aspx)

At the bottom of the below post is some simple basic code that is probably close to what you want to do. The code puts the servo in an initial position, then a slow move command is given to the ssc-32 to move the servo to another position. While the servo is moving the analog input to the ssc-32 is queried for the analog value. When the analog value is below a certain threshhold, the ssc-32 is told to stop the servo, and the servo position is queried. Then the various info is printed, and then the sequence is repeated. I use it for simple hardware testing.

lynxmotion.net/phpbb/viewtopic.php?t=3655

Um zoomie he’s using C# :wink:

Yes, I know. :wink: I would think the programming logic would be be pretty much the same for c# and basic as far as interfacing with the ssc-32. I see no evidence of a delay in between the apparent write and read lines to allow the ssc-32 chip to generate and return data in the tiny piece of code provided. I think looking at working code logic might provide useful info.

ah. actually the port.Read() call waits for a byte or the timeout delay before returning to that thread so there is a delay it’s just not obviously coded. you are right of course that the general logic flow is probably very similar.

You were absolutely right. That was a silly mistake. However, it only made a small difference. Now, when I write “Q” I get back a “.” which is correct, but for “QP” or “VB” I get back a “?”. Also, I changed from a byte array to a char array. If I use a byte array, the console simply writes “System.Byte]”.
So, I’m still stuck.

Also, “zoomie”, thanks for the basic code, but I’ve already got the rest of my program laid out. But you’re right, that’s basically what I’m looking to do.

Sorry, I have not use C#, other than once playing with a hello world pgrogram.

But my guess here on why you are seeing a ? is because the character returned is a binary value. So for example if the value is to center the servo: 1500, the returned value will be: 150 or 0x96, which is probably not a displayable character. You may want to output the value in decimal or hex to see the contents.

Kurt

yeah it is actually spitting the binary byte to the console rather than the ascii representation. you need to cast or convert the binary value to a string. The brute force way is to set your variable size = data[0] and then WriteLine(size)… (since size isn’t used after the Read() completes). I’ve only dabbled in C# at most so the exact means to efficiently do this, unless it is as simple as a C style cast, has temporarily been replaced by some other tidbit of information. :unamused:

Console…::.WriteLine Method

If this were C or C++, I would simply use one of the variations of printfs, but not sure if this is available in C#

Kurt

nah it’s like a c++ stream where the default format is determined by the type of the object/class being passed. it’s supposed to be easier or something… until it doesn’t work the way they want you to write it then it’s your issue to resolve. man I don’t need to go down this road… sigh.

Never cared for the streams in C++ either. Actually, never cared for the bloat and mangling of C++!

Alan KM6VV