diff --git a/README.md b/README.md index d16785a00b2028800eade989d51283b2e3f7032c..74487255b1828b353053192c481bd8b92250f8f1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Here we want to implement a simple avoidance algorithm to robot. We use e-puck r ## ROBOT AND SENSORS -### Robot +### [Robot](https://cyberbotics.com/doc/guide/epuck) E-puck is a miniature mobile robot originally developed at EPFL for teaching purposes by the designers of the successful Khepera robot. The hardware and software of e-puck is fully open source, providing low level access to every electronic device and offering unlimited extension possibilities. diff --git a/controllers/my_controller/my_controller.py b/controllers/my_controller/my_controller.py index 57ca747dbf51b2da642adb0fd4755a097109486e..08c88531776b44b897034d8ffab50ba5604f7c45 100644 --- a/controllers/my_controller/my_controller.py +++ b/controllers/my_controller/my_controller.py @@ -22,6 +22,15 @@ for i in range(8): ps[i].enable(TIME_STEP) ls[i].enable(TIME_STEP) +gps = robot.getDevice('gps') +gps.enable(TIME_STEP) + + +leftEncoder = robot.getDevice('left wheel sensor') +leftEncoder.enable(TIME_STEP) +rightEncoder = robot.getDevice('right wheel sensor') +rightEncoder.enable(TIME_STEP) + leftMotor = robot.getDevice('left wheel motor') rightMotor = robot.getDevice('right wheel motor') leftMotor.setPosition(float('inf')) @@ -35,6 +44,17 @@ while robot.step(TIME_STEP) != -1: leftSpeed = 0.5 * MAX_SPEED rightSpeed = 0.5 * MAX_SPEED + # read encoders + rightEncoderValue = rightEncoder.getValue() + leftEncoderValue = leftEncoder.getValue() + + # read position + x = gps.getValues()[0] + y = gps.getValues()[1] + print("x: " + str(x)) + print("y: " + str(y)) + + # read sensors outputs psValues = [] lsValues = [] @@ -45,9 +65,6 @@ while robot.step(TIME_STEP) != -1: # detect light left_light = np.mean([lsValues[5], lsValues[6], lsValues[7]]) right_light = np.mean([lsValues[0], lsValues[1], lsValues[2]]) - print("LEFT LIGHT: " + str(left_light)) - print("RIGHT LIGHT: " + str(right_light)) - # detect obstacles diff --git a/worlds/.world.jpg b/worlds/.world.jpg index dac7e8b82e20087e410b3af0392aa348f2094a02..121b4567e4970c611c97ad30e9119f73c8aac4fe 100644 Binary files a/worlds/.world.jpg and b/worlds/.world.jpg differ diff --git a/worlds/.world.wbproj b/worlds/.world.wbproj index 9b2e8c06aea9bd8ebb5da5cac5c28bce8f7d19d7..a8b5d6047427857b2c0981e2deebb9b441b0b8fa 100644 --- a/worlds/.world.wbproj +++ b/worlds/.world.wbproj @@ -1,10 +1,10 @@ Webots Project File version R2022b -perspectives: 000000ff00000000fd0000000200000001000001a50000031cfc0200000001fb0000001400540065007800740045006400690074006f007201000000130000031c0000008900ffffff0000000300000768000000d9fc0100000001fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000000007680000006900ffffff000005c10000031c00000001000000020000000100000008fc00000000 +perspectives: 000000ff00000000fd0000000100000001000001c00000082bfc0200000002fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000013000007780000003900fffffffb0000001400540065007800740045006400690074006f0072010000078d000000b10000008900ffffff00000ba60000082b00000001000000020000000100000008fc00000000 simulationViewPerspectives: 000000ff00000001000000020000014a0000061c0100000002010000000100 sceneTreePerspectives: 000000ff00000001000000030000001c000000c0000000fa0100000002010000000200 maximizedDockId: -1 centralWidgetVisible: 1 orthographicViewHeight: 1 -textFiles: 0 "controllers/my_controller/my_controller.py" +textFiles: 0 "../obsavoid/controllers/my_controller/my_controller.py" consoles: Console:All:All -renderingDevicePerspectives: e-puck:camera;1;3.82051;0;0 +renderingDevicePerspectives: e-puck:camera;0;3.38462;0;0 diff --git a/worlds/world.wbt b/worlds/world.wbt index 03ac569c12d8a7ed11adebc0a3001e7368e9aac5..5e16f5186bc537384c322b892ac1488826879ab5 100644 --- a/worlds/world.wbt +++ b/worlds/world.wbt @@ -7,12 +7,13 @@ EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/project EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/objects/obstacles/protos/OilBarrel.proto" EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/appearances/protos/Parquetry.proto" EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/objects/factory/containers/protos/WoodenBox.proto" +EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/robots/gctronic/e-puck/protos/E-puckGroundSensors.proto" WorldInfo { } Viewpoint { orientation -0.5773502691896258 0.5773502691896258 0.5773502691896258 2.0944 - position 0.2886112430982633 0.30112288717536395 4.7561144404849145 + position 0.0003051560168778658 3.501262190645565e-06 5.043498464270635 } TexturedBackground { } @@ -25,19 +26,21 @@ RectangleArena { } } E-puck { - hidden position_0_0 28.033302105971305 - hidden position_0_1 27.431657135094095 - hidden linearVelocity_0 -0.01040089258177146 0.0005189791645317463 -0.00010164286476468898 - hidden angularVelocity_0 -0.012580145309195254 -0.6870843501448997 -2.2292946089286447 - hidden rotation_1 0 -1 0 6.162461784455415 - hidden linearVelocity_1 0.043782987222245516 -0.0016398885897364905 -2.215561220686446e-05 - hidden angularVelocity_1 0.09747530080179415 2.4512349752960945 -2.23409528946547 - hidden rotation_2 0 1 0 6.147970605148766 - hidden linearVelocity_2 -0.07125569725759662 0.002336362298856977 -3.4872247586914343e-06 - hidden angularVelocity_2 -0.12270046057049977 -3.8254049928433136 -2.2324546810944326 - translation 0.6222753536792252 0.3401916142101004 -6.850241694632969e-05 - rotation 0.004217783566957383 -0.029762230724924357 -0.9995481078587757 0.09378488003841622 + hidden position_0_0 173.12431056902832 + hidden position_0_1 169.71291435045296 + hidden rotation_1 0 1 0 0.6984699206507091 + hidden rotation_2 0 -0.9999999999999999 0 2.367219551802442 + translation 0 0 -6.39533e-05 + rotation 0.0004724657719699007 -0.00047245231765368986 0.999999776782426 1.5708248738206394 controller "my_controller" + turretSlot [ + GPS { + } + ] + groundSensorsSlot [ + E-puckGroundSensors { + } + ] } OilBarrel { translation 0 -0.34 0.11