Hi,
I want to make the cursor as a line and as soon as the line reach the target it changes color. Right now, I have created line but it only changes the color when the start point of that line reach the target. My question is how to make the target change color whenever one point of the line touch it.
Thanks
Hi Michael,
The Hand In Target block just considers whether the point for the hand position is in a target or not. If you have used that hand position as the start of the line, that is why you are registering hits only when the start point is in your destination target.
The easiest way to fix this issue is going to involve some Embedded MATLAB. Exactly how to do the calculation is going to depend on what your target shape is. I suspect that the embedded MATLAB would need as inputs:
-The VCode for the hand (you need this to get the shape of the hand feedback)
-The actual hand position from KINData_bus (the VCode’s position has a 50ms feedforward that you may not want to use)
-The VCode of the target
If, for instance, your target is a circle, then you need to determine the closest point on your line to the center of the circle and compare that distance to the radius of the circle. Here is an article that discusses how to find the closest point on the line:
https://math.stackexchange.com/questions/717746/closest-point-on-a-line-to-another-point
Depending on the thickness of your line you may need to check the bounds of your line (i.e. treat it like a rectangle).
When working on this sort of problem I highly recommend writing a MATLAB script to test the code at the MATLAB prompt before moving it into a working model. This will save you quite a bit of time over compiling and testing in a model.
Please let me know if we can help more.
Cheers!
Duncan
Hi Duncan,
Thank you for your answer. Just one more question. For the Vcode, where can I check the meaning of each role. For example Vcode(2) is enable or disable. I would like to know the whole thing.
Thanks,
Michael
Hi Michael,
The best place to look at the VCode format at the moment is the Show Targets block. If you look under the mask you will see there is an embedded MATLAB block. The comments at the top of the embedded MATLAB have the complete description of the VCode format and how to use it. There are example tasks on the support site if you want to add text to your VCodes as well as the Show target with Label block.
Cheers!
Duncan
Hi Duncan,
It works fine with single target. But it does not work when multi-targets showing at same time. I used the sample code (target in background block) to show multi-target. Or do I have to create many show_target_block to deal with this problem.
Thanks,
Jinyang
Hi Jinyang,
I’m not sure I understand your problem. If you are only showing a few targets (<25) you shouldn't need to use the set target in background code. That code is only intended for showing large numbers of targets simultaneously.
If you want to show multiple targets at one time you have lots of options:
1. Multiple show target blocks (using matrix concatenation to put together the VCodes)
2. A single show target block with an array input for the target to enable.
3. Embedded MATLAB where you create your own 70 element arrays and manage VCodes on your own
Does this help?
Cheers!
Duncan
Hi Duncan,
Thanks for your quick reply. Since I want to reach target with line cursor, I need to apply it to a embedded MATLAB function to determine the closest point on the line as you said before. But when it turns to multiple targets showing at same time. How to decide which target need to be compared?
Thanks,
Jinyang
Hi Jinyang,
The sort answer is that you need to compare all of the targets and output an array for which target(s) the hand is in. If your method of checking for intersections is very complex then you can do tricks to figure out if it’s worth doing the more complex checks. However, I suspect for what you are doing those optimizations would not be required.
Cheers!
Duncan