Robot Class
This will guide the basic Methods available for a Java Virtual Robot implementations.
Table of content
- Introduction
- Sensors
- Communication
- Indicators
- Helpers
- Coordinate(int robotId, double x, double y, double heading, RobotMqttClient m)
- MotionController(Coordinate c)
- rotate(int speed, int interval)
- move(int leftSpeed, int rightSpeed, int interval)
- rotateDegree(int speed, float degree)
- moveDistance(int speed, float distance)
- goToGoal(double targetX, double targetY, int velocity)
- isSpeedInRange(int speed)
- delay(int interval)
- getSlope(double x1, double y1, double x2, double y2)
- debug(String msg, int level)
- RobotMqtt(int robotId,RobotMqttClient mqtt, char reality)
Introduction
The Robot Class implements a collection of sensors, communication methods, output devices, Helper functions to emulate a real hardware robot in the virtual space.
Robot(int id, double x, double y, double heading, char reality)
id - id of the robot (unique in virtual and real)
x - x cordinates on the arena
y - y cordinates on the arena
heading - The absolute angle of the robot from the positive direction of the x axis
reality - specify whether real or virtual
Defines robotMqttClient for MQTT connection to create a robot instance in the Simulator.
Sensors
Sensor modules are written with physical hardware implementations in mind. The Sensors available can be used as direct inputs in designing the robot logic.
DistanceSensor(Robot robot, RobotMqttClient m)
DistanceSensor distSensor = new DistanceSensor(this, robotMqttClient);
getDistance()
Description
Returns double type value for the distance of obstacle or robot in front.
Syntax
distSensor.getDistance()
Parameter
None
Returns
Double
Example Code
ProximitySensor(Robot robot, RobotMqttClient m)
ProximitySensor proximitySensor = new ProximitySensor(this, robotMqttClient);
getProximity()
Description
Returns ProximityReadingType value indicating …….
Syntax
proximitySensor.getProximity();
Parameter
None
Returns
swarm.robot.types.ProximityReadingType
ColorSensor(Robot robot, RobotMqttClient m)
ColorSensor colorSensor = new ColorSensor(this, robotMqttClient);
getColor()
Description
Returns RGBColor type value indicating the color detected at the front of the robot.
Syntax
colorSensor.getColor()
Parameter
None
Returns
swarm.robot.types.RGBColorType
Communication
SimpleCommunication(int robotId, RobotMqttClient m)
SimpleCommunication simpleComm = new SimpleCommunication(id, robotMqttClient);
sendMessage(String msg, int distance)
Description
Broadcasts message to robots within the defined radius.
Syntax
simpleComm.sendMessage(String msg, int distance);
simpleComm.sendMessage(String msg);
Parameter
String msg : message to be passed
int distance : radius that will receive the broadcasted message
Returns
Void
DirectedCommunication(int robotId, RobotMqttClient m)
DirectedCommunication directedComm = new DirectedCommunication(id, robotMqttClient);
sendMessage(String msg, int distance)
Description
Sends a broadcast type message to robots at front within [-15,15] angle
Syntax
directedComm.sendMessage(String msg, int distance);
directedComm.sendMessage(String msg);
Parameter
String msg : message to be passed
int distance : radius that will receive the broadcasted message.
Returns
Void
Indicators
Indicators used signify various states of the robots.
NeoPixel(Robot robot, RobotMqttClient m)
NeoPixel neoPixel = new NeoPixel(this, robotMqttClient);
changeColor(int r, int g, int b)
Description
Used to change colors of the neopixel by inputing RGB values as integers.
Syntax
neoPixel.changeColor(int r,int g,int b);
Parameter
int r : red
int g : green
int b : blue
Returns
Void
Helpers
Helper and Controller objects
Coordinate(int robotId, double x, double y, double heading, RobotMqttClient m)
Coordinate coordinates = new Coordinate(int robotId, double x, double y, double heading, RobotMqttClient m);
getX()
Description
Get x coordinate of the robot.
Syntax
cordinates.getX()
Parameter
None
Returns
double
getY()
Description
Get y coordinate of the robot.
Syntax
cordinates.getY()
Parameter
None
Returns
double
setX(double x)
Description
Set x coordinate of the robot.
Syntax
cordinates.setX(double x)
Parameter
double
Returns
Void
setY(double y)
Description
Set y coordinate of the robot.
Syntax
cordinates.setY(double y)
Parameter
double
Returns
Void
getHeading()
Description
Get heading of the robot.
Syntax
cordinates.getHeading()
Parameter
Void
Returns
double
getHeadingRad()
Description
Get heading of the robot in Radians.
Syntax
cordinates.getHeadingRad()
Parameter
Void
Returns
double
setHeading(double heading)
Description
Set heading of the robot.
Syntax
cordinates.setHeading(double heading)
Parameter
double
Returns
Void
setHeadingRad(double heading)
Description
Set heading of the robot in Radians.
Syntax
cordinates.setHeadingRad(double heading)
Parameter
double
Returns
Void
setCoordinate(double x, double y, double heading)
Description
Set x and y cordinates.
Syntax
cordinates.setCoordinate(ddouble x, double y)
cordinates.setCoordinate(ddouble x, double y, double heading)
Parameter
double x : x cordinate
double y : y cordinate
double heading : heading of cordinate
Returns
Void
toString()
Description
return string of x , y and heading.
Syntax
cordinate.toString()
Parameter
Void
Returns
String
publishCoordinate()
Description
Publish cordinate details under topic localization/update.
Syntax
cordinate.publishCoordinate()
Parameter
Void
Returns
Void
MotionController(Coordinate c)
MotionController motion = new MotionController(Communication(c));
rotate(int speed, int interval)
Description
Rotate virtual roboot with a given speed and interval.
Syntax
motion.rotate(int speed)
motion.rotate(int speed, int interval)
Parameter
int speed : speed of roataion
int interval : time interval for all steps to occur?
Returns
Void
move(int leftSpeed, int rightSpeed, int interval)
Description
Move virtual roboot with a given speed and interval.
Syntax
motion.move(int leftSpeed, int rightSpeed, int interval)
motion.move(int leftSpeed, int rightSpeed)
Parameter
int leftSpeed : speed of left motor?
int rightSpeed : speed of right motor?
int interval : ...................
Returns
Void
rotateDegree(int speed, float degree)
//To be implemented
moveDistance(int speed, float distance)
//To be implemented
goToGoal(double targetX, double targetY, int velocity)
Description
Move virtual robot to defined location
Syntax
motion.gotoGoal(double targetX, int targetY, int velocity,in t interval )
motion.gotoGoal(double targetX, int targetY, int velocity)
Parameter
double targetX : target x coordinate
double targetY : target y coordinate
int velocity : velcoity of robot
int interval : ............................
Returns
boolean
isSpeedInRange(int speed)
Description
Check if given speed is in acceptable range (if speed within ROBOT_SPEED_MIN && ROBOT_SPEED_MAX).
Syntax
motion.isSpeedInRange(int speed)
Parameter
int speed : Speed of the robot
Returns
boolean
delay(int interval)
Description
Delay to hold thread.
Syntax
motion.delay(int interval)
Parameter
int interval : sleep for a defined interval
Returns
Void
getSlope(double x1, double y1, double x2, double y2)
Description
Angle in degrees between two points.
Syntax
motion.getSlop(idouble x1, double y1, double x2, double y2)
Parameter
double x1 : start x cordinate
double y1 : start y cordinate
double x2 : goal x cordinate
double y2 : goal y cordinate
Returns
double
debug(String msg, int level)
RobotMqtt(int robotId,RobotMqttClient mqtt, char reality)
RobotMQTT robotMQTT = new RobotMqtt(int robotId,RobotMqttClient mqtt, char reality)
robotCreate(double x, double y, double heading)
Description
Create a robot in the simulator.
Syntax
robotMQTT.robotCreate(double x, double y,double heading)
Parameter
double x : position x cordinate
double y : position y cordinate
double heading : heading of the robot
Returns
Void
subscribe(mqttTopic key, String topic)
Description
Subsribe to a topic.
Syntax
robotMQTT.subscribe(mqttTopic key, String topic)
Parameter
mqttTopic key :......
String topic : topic to subscribe
Returns
Void
handleSubscription(Robot r, MqttMsg m)
Description
Handle the mqtt subsription of the robots.
Syntax
robotMQTT.handleSubscription(Robot r, MqttMsg m)
Parameter
Robot r : considerd robot
Mqttmsg m: topic and message (Calling out various functions through MQTT)
Returns
Void