Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

USARBot.TouchSensor


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
class TouchSensor extends Sensor config (USARBot);

const TouchRange = 0.16; // 3mm
const ScanStep = 0.25; // 4.7mm
const PointsPerCircle = 6;

var config float Diameter;
var config bool bDebug;
var float uuRadius;
var int nCircles;
var float CircleStep;

function ConvertParam(USARConverter converter)
{
    if (converter!=NONE) {
        uuRadius = converter.LengthToUU(Diameter)/2;
    }
    else {
        uuRadius = Diameter/2;
    }
    nCircles = int(uuRadius/ScanStep)+1;
    CircleStep = 2*pi/PointsPerCircle;
}

function bool isTouch()
{
    local vector HitLocation, HitNormal;
    local actor Bumper;
    local vector RotX, RotY, RotZ;
    local rotator curRot;
    local vector startVec;
    local float radius;
    local int i, j; 

    curRot = Rotation;
    startVec = Location;
    GetAxes(Rotation, RotX, RotY, RotZ);
    
    // send one Trace straight ahead
    Bumper = Trace(HitLocation, HitNormal, startVec + touchRange * vector(curRot), startVec, true);
    if (Bumper != NONE) {
        if (bDebug) log("Bump with "$Bumper);
        return true;
    }
    
    // detect along the circle from the edge to the center with step ScanStep;
    for (i = 0; i < nCircles; i++) {
        radius = (nCircles - i) * ScanStep;
        for (j = 0; j < PointsPerCircle; j++) {
            startVec = Location + uuRadius * cos(j * CircleStep) * RotY + uuRadius * sin(j * CircleStep) * RotZ;
            Bumper = Trace(HitLocation, HitNormal, startVec + touchRange * vector(curRot), startVec, true);
            if (Bumper != NONE) {
                if (bDebug) log("Bump with "$Bumper);
                return true;
            }
        }
    }
    
    return false;
}

function String GetData()
{
    local string outstring;
    outstring="{Name "$ItemName$" Touch "$isTouch()$"}";
    return outstring;
}

function String GetConfData()
{
    local string outstring;
    outstring = Super.GetConfData();
    outstring = outstring@"{Diameter "$converter.FloatString(Diameter)$"}";
    return outstring;
}

defaultproperties
{
//Scaled with 4.762 at Mon Sep 25 14:21:52 EDT 2006
    bUseGroup=True
    ItemType="Touch"
    HiddenSensor=true
    DrawScale3D=(X=0.1)
    Diameter=0.01 // 1 cm
    drawscale=0.4762
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Di 26.9.2006 15:50:12.000 - Creation time: Mo 16.4.2007 11:20:54.968 - Created with UnCodeX