Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.Troxid:vrep-api-scala:0.1'
}
dependencies {
implementation("com.github.Troxid:vrep-api-scala:0.1")
}
<dependency>
<groupId>com.github.Troxid</groupId>
<artifactId>vrep-api-scala</artifactId>
<version>0.1</version>
</dependency>
libraryDependencies += "com.github.Troxid" % "vrep-api-scala" % "0.1"
:dependencies [[com.github.Troxid/vrep-api-scala "0.1"]]
Simple Scala/Java binding for Coppelia Robotics V-REP simulator (remote API)
Add the library in your project by adding the following dependency to your build file:
for SBT project:
libraryDependencies += "com.github.troxid" %% "vrepapiscala" % "0.3.6"
for Gradle project:
dependencies {
compile "com.github.troxid:vrepapiscala_2.12:0.3.6"
}
for Maven project:
<dependency>
<groupId>com.github.troxid</groupId>
<artifactId>vrepapiscala_2.12</artifactId>
<version>0.3.6</version>
</dependency>
Find the socket port number in V-REP/remoteApiConnections.txt
and use
it to connect to the server simulator
In the current version is not implemented features such as remote management GUI, additional configuration properties of objects and shapes, etc. Basically implemented those components that are required to control the robot:
import vrepapiscala._
object PioneerRemoteControlExample extends App {
val api = VRepAPI.connect("127.0.0.1", 19997).get
val robot = new PioneerP3dx(api)
api.simulation.start()
for(_ <- 0 to 500){
val resLS = robot.leftSensor.read
val resRS = robot.rightSensor.read
if(resLS.detectionState && resLS.detectedPoint.length < 0.5){
robot.rotateRight()
}else if(resRS.detectionState && resRS.detectedPoint.length < 0.5){
robot.rotateLeft()
} else {
robot.moveForward()
}
Thread.sleep(10)
}
api.simulation.stop()
}
class PioneerP3dx(api: VRepAPI) {
private val speed = 2f
private val leftMotor = api.joint.withVelocityControl("Pioneer_p3dx_leftMotor").get
private val rightMotor = api.joint.withVelocityControl("Pioneer_p3dx_rightMotor").get
private val frontSensors =
for(i <- 1 to 8)
yield api.sensor.proximity("Pioneer_p3dx_ultrasonicSensor" + i).get
def moveForward(): Unit = {
leftMotor.setTargetVelocity(speed)
rightMotor.setTargetVelocity(speed)
}
def moveBackward(): Unit = {
leftMotor.setTargetVelocity(-speed)
rightMotor.setTargetVelocity(-speed)
}
def rotateLeft(): Unit = {
leftMotor.setTargetVelocity(-speed)
rightMotor.setTargetVelocity(speed)
}
def rotateRight(): Unit = {
leftMotor.setTargetVelocity(speed)
rightMotor.setTargetVelocity(-speed)
}
def stop(): Unit = {
leftMotor.setTargetVelocity(0)
rightMotor.setTargetVelocity(0)
}
def leftSensor = frontSensors(1)
def rightSensor = frontSensors(6)
}