Cancel
Showing results for 
Search instead for 
Did you mean: 

Using a drag and drop method to initialize sensors on a track

Genius
Genius

Hello everybody,

 

I would like to initilize sensors on a track with a drag and drop method (see the attached screenshot). Unfortunatly, my code does not put the sensors at the right postions.

 

Unbenannt.JPG

 

Here is my code, which I got from the book from Steffen Bangsow:

 

(obj:string)
is
	posi:real;
	station:object;
	found:boolean;
	sensorID:integer;		
do
	--create reference
	station:=str_to_obj(obj);
	-- calculate x position 
	posi:=(station.xPos-self.~.segmentsTable[1,1])*
	self.~.location.scalingFactor;
	-- look in the sensorList
	self.~.sensorlist.setCursor(1,1);
	found:=self.~.sensorlist.find(station);
	-- found, move sensor
	if found then
		self.~.sensorID(self.~.sensorList[1,
			self.~.sensorlist.zeigerY]).position:=posi;
		
	else
		-- create new Sensor
		sensorId:=self.~.createSensor(posi,"Länge","sensorControl");
		-- create entry
		self.~.sensorlist.writeRow(1,self.~.sensorList.yDim+
		        1,sensorID,station);		
	end;	
end;

I know that my definition of the y-Position is wrong, but I am not sure how to change it. I appreciate every suggestion or hint!

 

Thank you very much in advance!

2 REPLIES

Re: Using a drag and drop method to initialize sensors on a track

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

you need to change it for tracks in y direction:

 

posi:=(self.~.segmentsTable[2,1]-station.YPos)* self.~.location.scalingFactor;

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: Using a drag and drop method to initialize sensors on a track

Genius
Genius
Perfect, thank you!