[Opensim-users] Vehicle script stops after about 5 secs
marcel verhagen
marceled9 at gmail.com
Wed Dec 9 11:25:38 UTC 2009
could it be the sleep function ?
2009/12/8 Marco Otte <m.otte at camera.vu.nl>
> Hi everyone,
>
> I've got a simple car (works fine in SL).
> I've created a small LSL script (see below) that listens to channel 9 for
> information about speed and direction. The script inputs this into the
> standard physics commands to move and turn the car.
> Because I want outside (of OpenSIM) control of the car, I've created a
> small C# program that simply types the speed and direction into the chat box
> (/9 speed_direction). This because a HTTPrequest from LSL is limited to
> about 1 call per second and that is too slow.
> The whole setup seems to work. The car moves and turns smoothly, BUT after
> about 5 secs (give or take) moving the script stops responding and the
> vehicle stops. After StandUp-Sit it resumes for another 5 secs.
> If the vehicle does not move, the script keeps running.
> ----- script -----
> //This car uses a C# program that send keypresses containing the speed and
> direction.
> //A Listen() event picks up these numbers and pushes these into the VEHICLE
> string sit_message = "Ride"; //Sit message
> string not_owner_message = "You are not the owner of this vehicle ...";
> //Not owner message
> key requestid; //Used for the HTTPREQUEST
> float SpeedSet = 0; //Translated speed from bike speed
> float TurnRatioSet = 0; //Calculated turn adjustment
> integer TurnLeftThreshold = 1070; //Upper bound for straight ahead from
> bike
> integer TurnRightThreshold = 1050; //Lower bound for straight ahead from
> bike
> integer TurnLeftMax = 1243; //Maximum value from bike at full left steering
> integer TurnRightMin = 809; //Minimum value from bike at full right
> steering
> integer Handle = 0;
>
> default
> {
> state_entry()
> {
> llSetSitText(sit_message);
> llSitTarget(<0.2,0.2,0.5>, ZERO_ROTATION ); //
> forward-back,left-right,updown, ZERO_ROTATION
>
> llSetCameraEyeOffset(<-0.2, 0.0, 1.0>);
> llSetCameraAtOffset(<5.0, 0.0, 0.0>);
>
> //car
> llSetVehicleType(VEHICLE_TYPE_CAR);
>
> llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY,
> 0.8);//0.8
> llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE,
> 0.10);//0.1
> llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.1);//1.0
> Lower is more responsive
> llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE,
> 0.1);//0.2
> llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <20.0,
> 20.0, 10.0>);//1000,2,1000
>
> llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY,
> 0.2);//0.2 - not much difference on its own
> llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE,
> 0.10);//0.1
> llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);//0.1
> Low is better, less after turning
> llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE,
> 0.1);//0.5
> llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <20.0,
> 20.0, 20.0>);//20,20,1000
>
> llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY,
> 0.10);//0.5
> llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE,
> 0.50);//0.5
> }
>
> changed(integer change)
> {
> if (change & CHANGED_LINK)
> {
> key agent = llAvatarOnSitTarget();
> if (llKey2Name(agent) == "Blithe Crosswater")
> {
> if (agent != llGetOwner())
> {
> llSay(0, not_owner_message);
> llUnSit(agent);
> llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE);
> }
> else
> {
> llListenRemove(Handle);
> llSetStatus(STATUS_PHYSICS, TRUE);
> llSleep(.1);
> llListen(9,"","","");
> requestid = llHTTPRequest("
> http://127.0.0.1:8002/?1",[HTTP_METHOD,"GET"],"");<http://127.0.0.1:8002/?1%22,%5BHTTP_METHOD,%22GET%22%5D,%22%22%29;>[
> ^ <http://127.0.0.1:8002/?1%22,%5BHTTP_METHOD,%22GET%22%5D,%22%22%29;>]
> //This is to start the C# program inputting Speed and Direction
> llSleep(.4);
> }
> }
> else
> {
> llListenRemove(Handle);
> llSetStatus(STATUS_PHYSICS, FALSE);
> llSleep(.4);
> llTargetOmega(<0,0,0>,PI,0);
> requestid = llHTTPRequest("
> http://127.0.0.1:8002/?0",[HTTP_METHOD,"GET"],"");<http://127.0.0.1:8002/?0%22,%5BHTTP_METHOD,%22GET%22%5D,%22%22%29;>[
> ^ <http://127.0.0.1:8002/?0%22,%5BHTTP_METHOD,%22GET%22%5D,%22%22%29;>]
> //Stops the C# program
> llResetScript();
> }
> }
>
> }
>
> http_response(key request_id, integer status, list metadata, string
> body)
> {
> //Catch the response of the C# program, a dummy method
> }
>
> listen(integer chan, string name, key id, string message)
> {
> //llSay(0,message);
> integer Separator = llSubStringIndex(message,"-");
> float speed = llGetSubString(message, 0, Separator - 1); //Extract
> speed
> float direction = llGetSubString(message, Separator + 1,
> llStringLength(message)); //Extract DIRECTION
>
> SpeedSet = (30 * speed) / 7000; //Transform to [0-30] range
>
> if (direction > TurnRightThreshold && direction <
> TurnLeftThreshold) //Is steering in the middle?
> {
> //Straight ahead
> TurnRatioSet = 0;
> }
> if (direction > TurnLeftThreshold) //Steering left?
> {
> //Set steering in VR to [0-1.65]
> TurnRatioSet = (direction - TurnLeftThreshold) /
> ((TurnLeftMax - TurnLeftThreshold)/1.65);
> }
> if (direction < TurnRightThreshold) //Steering right?
> {
> TurnRatioSet = (TurnRightThreshold - direction) /
> ((TurnRightThreshold - TurnRightMin)/1.65);
> }
>
> if(SpeedSet < 0.5) {TurnRatioSet = 0;} //Low speed then no
> steering
>
> vector angular_motor; //use vector
>
> llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION,
> <SpeedSet,0,0>); //Set speed
>
> if (direction > TurnLeftThreshold) //If left
> {
> angular_motor.z += TurnRatioSet; //then increase rotation
> angle
> }
> if (direction < TurnRightThreshold) //If right
> {
> angular_motor.z -= TurnRatioSet; //decrease rotation angle
> }
>
> //llSay(0,(string)SpeedSet + " --- " +
> (string)angular_motor.z); //Diagnostic
>
> llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,
> angular_motor); //Set rotation
> }
> ---- end script ---
>
>
> With kind regards,
>
> Marco Otte
> CAMeRA @ VU University Amsterdam
> De Boelelaan 1081
> 1081 HV AMSTERDAM
> Netherlands
>
> Visiting address:
> Metropolitan Building
> Buitenveldertselaan 3
> 1082 VA Amsterdam (room Z539)
> T +31 (0)20 598 6807
> M +31 (0)6 46025037
> E m.otte at camera.vu.nl
>
>
> _______________________________________________
> Opensim-users mailing list
> Opensim-users at lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/opensim-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://opensimulator.org/pipermail/opensim-users/attachments/20091209/efe2775a/attachment.html>
More information about the Opensim-users
mailing list