⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netnodesim.java

📁 利用JAVA编写的群体机器人局部通讯完成一定得队形控制
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        /**         * Clear the trail.         */        public void clearTrail()		{		trail.clear();		}        /**         * Draw the robot in a specific spot.         */        public void draw(Vec2 pos, Graphics g, int w, int h,                double t, double b, double l, double r)                {                Vec2 old_pos = position;                position = pos;                draw(g,w,h,t,b,l,r);                position = old_pos;                }	/**	 * Draw the robot.	 */	public void draw(Graphics g, int w, int h,		double t, double b, double l, double r)		{		top =t; bottom =b; left =l; right =r;		if (DEBUG) System.out.println("draw "+			w + " " +			h + " " +			t + " " +			b + " " +			l + " " +			r + " ");		double meterspp = (r - l) / (double)w;		if (DEBUG) System.out.println("meterspp "+meterspp);		int radius = (int)(RADIUS / meterspp);		int xpix = (int)((position.x - l) / meterspp);		int ypix = (int)((double)h - ((position.y - b) / meterspp));		if (DEBUG) System.out.println("robot at"+			" at "+xpix+","+ypix);		/*--- draw the main body ---*/		g.setColor(foreground);		g.fillOval(xpix - radius, ypix - radius,			radius + radius, radius + radius);		}	/**	 * Clean up.	 */	public void quit()		{		}	/**	 * Gets time elapsed since the robot was instantiated. 	 * Since this is simulation, it may not match real elapsed time.	 */	public long getTime()		{		return(time);		}	private	long	last_Obstaclest = 0;	private	Vec2	last_Obstacles[];	private	int	num_Obstacles;	/**	 * Get an array of Vec2s that point egocentrically from the	 * center of the robot to the obstacles currently sensed by the 	 * bumpers and sonars.	 * @param timestamp only get new information 	 *	if timestamp > than last call or timestamp == -1 .	 * @return the sensed obstacles.	 */	public Vec2[] getObstacles(long timestamp)		{		return(new Vec2[0]);		}	private	double	obstacle_rangeM = 1.0;	/**	 * Set the maximum range at which a sensor reading should be considered	 * an obstacle.  Beyond this range, the readings are ignored.	 * The default range on startup is 1 meter.	 * @param range the range in meters.	 */	public void setObstacleMaxRange(double range)		{		obstacle_rangeM = range;		}	private	long	last_VisualObjectst = 0;	private Vec2[]	last_VisualObjects;	private	int	num_VisualObjects = 0;	private	int	last_channel = 0;	/**	 * Get an array of Vec2s that represent the	 * locations of visually sensed objects egocentrically 	 * from center of the robot to the objects currently sensed by the 	 * vision system.		 * @param timestamp only get new information 	 *	if timestamp > than last call or timestamp == -1 .	 * @param channel (1-6) which type/color of object to retrieve.	 * @return the sensed objects.	 */	public Vec2[] getVisualObjects(long timestamp, int channel)		{		return(new Vec2[0]);		}	private	long	last_VisualSizest = 0;	/**	 * NOT IMPLEMENTED:	 * Get an array of doubles that represent an estimate of the	 * size in square meters of the visually sensed objects.	 * @param timestamp only get new information if 	 * 	timestamp > than last call or timestamp == -1 .	 * @param channel (1-6) which type/color of object to retrieve.	 * @return the sizes of the sensed objects.	 */	public double[] getVisualSizes(long timestamp, int channel)		{		/* todo */		return(new double[0]);		}	/**	 * Get the position of the robot in global coordinates.	 * @param timestamp only get new information 	 *	if timestamp > than last call or timestamp == -1.	 * @return the position.	 */	public Vec2 getPosition(long timestamp)		{		return(new Vec2(position.x, position.y));		}			/**	 * Get the position of the robot in global coordinates.	 * @return the position.	 */	public Vec2 getPosition()		{		return(new Vec2(position.x, position.y));		}			/**	 * Reset the odometry of the robot in global coordinates.	 * This might be done when reliable sensor information provides	 * a very good estimate of the robot's location, or if you	 * are starting the robot in a known location other than (0,0).	 * Do this only if you are certain you're right!	 * @param position the new position.	 */	public void resetPosition(Vec2 posit)		{		position.setx(posit.x);		position.sety(posit.y);		}	private boolean	in_reverse = false;	/**	*/	public double getSteerHeading(long timestamp)		{		return(0);		}		/**	*/	public void resetSteerHeading(double heading)		{		}	private double desired_heading;	/**	*/	public void setSteerHeading(long timestamp, double heading)		{		}		/**	*/ 	public void setSpeed(long timestamp, double speed)		{		}	/**	*/	public void setBaseSpeed(double speed)		{		}        /**         * Return an int represting the player's ID on the team.         * This value may not be valid if the simulation has not         * been "set up" yet.  Do not use it during initialization.         * @param timestamp only get new information if         *      timestamp > than last call or timestamp == -1 .         * @return the number.         */        public int getPlayerNumber(long timestamp)                {                return(kin_sensor.getPlayerNumber(all_objects));                }        /**	 * NOT IMPLEMENTED         * Get an array of Vec2s that point egocentrically from the         * center of the robot to the teammates currently sensed by the         * robot.         * @param timestamp only get new information if         *      timestamp > than last call or timestamp == -1 .         * @return the sensed teammates.         */        public Vec2[] getTeammates(long timestamp)                {                return(new Vec2[0]);                }        /**	 * NOT IMPLEMENTED         * Get an array of Vec2s that point egocentrically from the         * center of the robot to the opponents currently sensed by the         * robot.         * @param timestamp only get new information if         *      timestamp > than last call or timestamp == -1 .         * @return the sensed teammates.         */        public Vec2[] getOpponents(long timestamp)                {                return(new Vec2[0]);                }        private double  kin_rangeM = 4.0;        /**         * Set the maximum range at which a sensor reading should be considered         * kin.  Beyond this range, the readings are ignored.         * Also used by opponent sensor.         * The default range on startup is 1 meter.         * @param range the range in meters.         */        public void setKinMaxRange(double range)                {                kin_rangeM = range;                kin_sensor.setKinMaxRange(range);                }	  public Color getForegroundColor() { return foreground; }	  public Color getBackgroundColor() { return background; }        /*--- Transceiver methods ---*/        public void multicast(int[] ids, Message m)                throws CommunicationException                {                transceiver.multicast(ids, m, all_objects);                }        public void broadcast(Message m)                {                transceiver.broadcast(m, all_objects);                }        public void unicast(int id, Message m)                throws CommunicationException                {                transceiver.unicast(id, m, all_objects);                }        public CircularBufferEnumeration getReceiveChannel()                {                return(transceiver.getReceiveChannel());                }        public void setCommunicationMaxRange(double m)                {                transceiver.setCommunicationMaxRange(m);                }        public void receive(Message m)                {                transceiver.receive(m);                }        public boolean connected()                {                return(true);                }	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -