feat: added message for move
This commit is contained in:
12
app.py
12
app.py
@@ -46,10 +46,16 @@ def image_stream():
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
@sio.on("camera")
|
||||||
|
def camera_message(directions):
|
||||||
|
walle.set_movement(directions['angle'], directions['force'])
|
||||||
|
print(f"Moving camera in direction {directions['angle']:f} with velocity {directions['force']}")
|
||||||
|
|
||||||
|
|
||||||
@sio.on("move")
|
@sio.on("move")
|
||||||
def message(directions):
|
def move_message(directions):
|
||||||
walle.set_movement(directions['angle'], directions['distance'])
|
walle.set_movement(directions['angle'], directions['force'])
|
||||||
print(f"Moving in direction {directions['angle']:f} with velocity {directions['distance']}")
|
print(f"Moving in direction {directions['angle']:f} with velocity {directions['force']}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ export default {
|
|||||||
window.document.body.requestFullscreen();
|
window.document.body.requestFullscreen();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
moveCamera({ distance, angle }) {
|
moveCamera({ force, angle }) {
|
||||||
console.log({ action: 'camera', distance, angle });
|
console.log({ action: 'camera', force, angle });
|
||||||
},
|
},
|
||||||
moveWalle({ distance, angle }) {
|
moveWalle({ force, angle }) {
|
||||||
this.$socket.emit('move', {
|
this.$socket.emit('move', {
|
||||||
angle, distance,
|
force, angle,
|
||||||
});
|
});
|
||||||
// console.log({ action: 'walle', distance, angle });
|
// console.log({ action: 'walle', distance, angle });
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ export default {
|
|||||||
});
|
});
|
||||||
this.nipple.on('move', (evt, data) => {
|
this.nipple.on('move', (evt, data) => {
|
||||||
this.$emit('move', {
|
this.$emit('move', {
|
||||||
distance: data.distance,
|
force: data.force,
|
||||||
angle: data.angle.degree,
|
angle: data.angle.radian,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.nipple.on('end', () => {
|
this.nipple.on('end', () => {
|
||||||
this.$emit('move', {
|
this.$emit('move', {
|
||||||
distance: 0,
|
force: 0,
|
||||||
angle: 0,
|
angle: 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,31 +30,30 @@ class WallE:
|
|||||||
self.servo_controller = ServoController()
|
self.servo_controller = ServoController()
|
||||||
self.servo_controller.setup()
|
self.servo_controller.setup()
|
||||||
|
|
||||||
def set_movement(self, angle: float, distance: float):
|
def set_movement(self, angle: float, force: float):
|
||||||
if distance > 0:
|
if force > 1:
|
||||||
distance = distance/50.0 # map 0 - 50 to 0 - 1
|
force = 1.0
|
||||||
|
|
||||||
angle_rad = math.radians(angle)
|
cos_angle = math.cos(angle)
|
||||||
cos_angle = math.cos(angle_rad)
|
sin_angle = math.sin(angle)
|
||||||
sin_angle = math.sin(angle_rad)
|
|
||||||
|
|
||||||
velocity_l = 0
|
velocity_l = 0
|
||||||
velocity_r = 0
|
velocity_r = 0
|
||||||
|
|
||||||
if cos_angle > 0 and sin_angle > 0:
|
if cos_angle > 0 and sin_angle > 0:
|
||||||
if cos_angle > sin_angle:
|
if cos_angle > sin_angle:
|
||||||
velocity_r = cos_angle * distance
|
velocity_r = cos_angle * force
|
||||||
velocity_l = sin_angle * distance
|
velocity_l = sin_angle * force
|
||||||
elif cos_angle < sin_angle:
|
elif cos_angle < sin_angle:
|
||||||
velocity_r = sin_angle * distance
|
velocity_r = sin_angle * force
|
||||||
velocity_l = cos_angle * distance
|
velocity_l = cos_angle * force
|
||||||
elif cos_angle < 0 and sin_angle > 0:
|
elif cos_angle < 0 and sin_angle > 0:
|
||||||
if cos_angle < sin_angle:
|
if cos_angle < sin_angle:
|
||||||
velocity_r = 1 - sin_angle * distance
|
velocity_r = 1 - sin_angle * force
|
||||||
velocity_l = sin_angle * distance
|
velocity_l = sin_angle * force
|
||||||
elif cos_angle > abs(sin_angle):
|
elif cos_angle > abs(sin_angle):
|
||||||
velocity_r = sin_angle * distance
|
velocity_r = sin_angle * force
|
||||||
velocity_l = cos_angle * distance
|
velocity_l = cos_angle * force
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
self.motor_a.set(velocity_l)
|
self.motor_a.set(velocity_l)
|
||||||
|
|||||||
Reference in New Issue
Block a user