-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 777a7747fe61f9446533480b9fb092ca | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 8e797e08234635f9396beb70db152ca4 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
#TODO 1 Modify this header so that the correct information is displayed | ||
#Name | ||
#Name of code | ||
#For lab1, this will subscribe to mouse_client and publish to cmd_vel | ||
#Will convert messages of type MouseController to Twist | ||
#Deactivates when mouse wheel is scrolled up | ||
#last modified DATE 2023 | ||
|
||
|
||
import rospy | ||
#TODO 2 Import the appropriate message types that we will need | ||
|
||
|
||
class Controller: | ||
"""Class that controls subsystems on Turtlebot3""" | ||
def __init__(self): | ||
#TODO 3 initialize the appropriate Controller class attributes | ||
|
||
|
||
|
||
|
||
self.pub = rospy.Publisher('cmd_vel', Twist, queue_size = 1) | ||
|
||
rospy.Subscriber('mouse_info', MouseController, self.callback_mouseControl) | ||
|
||
self.ctrl_c = False | ||
rospy.on_shutdown(self.shutdownhook) | ||
|
||
def callback_mouseControl(self, mouseInfo): | ||
#TODO 4 Scale xPos from -1 to 1 to -.5 to .5 | ||
|
||
#TODO 5 set angular z in Twist message to the scaled value in the appropriate direction | ||
|
||
#TODO 6 Scale yPos from -1 to 1 to -.5 to .5 | ||
|
||
#TODO 7 set linear x in Twist message to the scaled value in the appropriate direction | ||
|
||
#TODO 8 publish the Twist message | ||
|
||
|
||
|
||
def shutdownhook(self): | ||
print("Controller exiting. Halting robot.") | ||
self.ctrl_c = True | ||
#TODO 9 force the linear x and angular z commands to 0 before halting | ||
|
||
|
||
self.pub.publish(self.cmd) | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
rospy.init_node('controller') | ||
c = Controller() | ||
#!/usr/bin/env python3 | ||
|
||
#TODO 1 Modify this header so that the correct information is displayed | ||
#Name | ||
#Name of code | ||
#For lab1, this will subscribe to mouse_client and publish to cmd_vel | ||
#Will convert messages of type MouseController to Twist | ||
#Deactivates when mouse wheel is scrolled up | ||
#last modified DATE 2023 | ||
|
||
|
||
import rospy | ||
#TODO 2 Import the appropriate message types that we will need | ||
|
||
|
||
class Controller: | ||
"""Class that controls subsystems on Turtlebot3""" | ||
def __init__(self): | ||
#TODO 3 initialize the appropriate Controller class attributes | ||
|
||
|
||
|
||
|
||
self.pub = rospy.Publisher('cmd_vel', Twist, queue_size = 1) | ||
|
||
rospy.Subscriber('mouse_info', MouseController, self.callback_mouseControl) | ||
|
||
self.ctrl_c = False | ||
rospy.on_shutdown(self.shutdownhook) | ||
|
||
def callback_mouseControl(self, mouseInfo): | ||
#TODO 4 Scale xPos from -1 to 1 to -.5 to .5 | ||
|
||
#TODO 5 set angular z in Twist message to the scaled value in the appropriate direction | ||
|
||
#TODO 6 Scale yPos from -1 to 1 to -.5 to .5 | ||
|
||
#TODO 7 set linear x in Twist message to the scaled value in the appropriate direction | ||
|
||
#TODO 8 publish the Twist message | ||
|
||
|
||
|
||
def shutdownhook(self): | ||
print("Controller exiting. Halting robot.") | ||
self.ctrl_c = True | ||
#TODO 9 force the linear x and angular z commands to 0 before halting | ||
|
||
|
||
self.pub.publish(self.cmd) | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
rospy.init_node('controller') | ||
c = Controller() | ||
rospy.spin() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,109 @@ | ||
#!/usr/bin/env python3 | ||
|
||
#TODO 0 Update the header below with your information | ||
#Name | ||
#ROS Enabled mouse client | ||
#Activates when mouse wheel is scrolled down and | ||
#Deactivates when mouse wheel is scrolled up | ||
#last modified 8 Jan 2023 | ||
#mouse_client.py | ||
|
||
import rospy | ||
import pyautogui | ||
import sys | ||
import time | ||
import os | ||
from pynput.mouse import Listener | ||
# TODO 1 Import the lab1 message file you created for the Mouse Controller data | ||
|
||
|
||
#Initialize global variable that will keep track of mouse button status | ||
global activate | ||
activate = False | ||
|
||
|
||
#get dimensions of screen so that we can scale for (-1,1) in both x and y | ||
xDim,yDim = pyautogui.size() | ||
|
||
class Mouse: | ||
def __init__(self): | ||
global activate | ||
listener = Listener(on_move=self.on_move, on_click=self.on_click, on_scroll=self.on_scroll) | ||
listener.start() | ||
self.ctrl_c = False | ||
rospy.on_shutdown(self.shutdownhook) | ||
|
||
# TODO 2 Create class variables to store activation status, and x and y position | ||
# Initialize the controller status to False, and in the center of the screen | ||
|
||
# TODO 3 Create a publisher to publish MouseController data on the mouse_info topic | ||
|
||
|
||
|
||
# Handle the event of the user moving the mouse | ||
def on_move(self,x,y): | ||
#We need to establish the use of the global variable for button activation | ||
global activate | ||
|
||
|
||
if(activate == False): | ||
messageString = "No movement sent, activate cursor first by scrolling down on the mouse wheel" | ||
print(messageString, end='') | ||
# overwrite same line | ||
print('\b' *len(messageString), end='', flush=True) | ||
xScale = 0.0 | ||
yScale = 0.0 | ||
else: | ||
# Use the dimensions of the monitor to convert output into x & y between -1 and 1 | ||
xScale = ((x/(xDim/2))-1) | ||
yScale = -((y/(yDim/2))-1) | ||
xFormat = "{:+.3f}".format(xScale) | ||
yFormat = "{:+.3f}".format(yScale) | ||
# create 19 byte message with x,y coordinates embedded and print to screen | ||
positionStr = 'X: ' + str(xFormat) + ' Y: ' + str(yFormat) + " " | ||
print(positionStr, end='') | ||
# overwrite same line | ||
print('\b' *len(positionStr), end='', flush=True) | ||
# TODO 4 Update the appropriate class variables and publish | ||
|
||
|
||
#Currently I'm not doing anything with the button click. | ||
#Eventually we could add additional modes if we wanted to. | ||
def on_click(self,x,y,button,pressed): | ||
pass | ||
|
||
# Handle the event of the user using the scroll wheel on the mouse | ||
def on_scroll(self,x,y,dx,dy): | ||
global activate | ||
if dy == 1: | ||
os.system("clear") | ||
print("Welcome to the mouse controller!\n\n") | ||
print("In order to ACTIVATE the controller scroll down on the mouse wheel.\n\n") | ||
print("In order to DEACTIVATE the controller scroll up on the mouse wheel.\n\n") | ||
print("To close the program, left-click on the terminal window and type ctrl-c.\n\n") | ||
activate = False | ||
if dy == -1: | ||
activate = True | ||
# TODO 5 Update the appropriate class variables and publish | ||
|
||
|
||
# Handle the event of the user pressing ctrl_c | ||
def shutdownhook(self): | ||
# TODO 6 Update the appropriate class variables and publish before shutdown | ||
|
||
|
||
print("Shutting down the client ") | ||
self.ctrl_c = True | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
os.system("clear") | ||
print("Welcome to the mouse controller!\n\n") | ||
print("In order to ACTIVATE the controller scroll down on the mouse wheel.\n\n") | ||
print("In order to DEACTIVATE the controller scroll up on the mouse wheel.\n\n") | ||
print("To close the program, left-click on the terminal window and type ctrl-c.\n\n") | ||
rospy.init_node('Mouse') | ||
Mouse() | ||
#!/usr/bin/env python3 | ||
|
||
#TODO 0 Update the header below with your information | ||
#Name | ||
#ROS Enabled mouse client | ||
#Activates when mouse wheel is scrolled down and | ||
#Deactivates when mouse wheel is scrolled up | ||
#last modified 8 Jan 2023 | ||
#mouse_client.py | ||
|
||
import rospy | ||
import pyautogui | ||
import sys | ||
import time | ||
import os | ||
from pynput.mouse import Listener | ||
# TODO 1 Import the lab1 message file you created for the Mouse Controller data | ||
|
||
|
||
#Initialize global variable that will keep track of mouse button status | ||
global activate | ||
activate = False | ||
|
||
|
||
#get dimensions of screen so that we can scale for (-1,1) in both x and y | ||
xDim,yDim = pyautogui.size() | ||
|
||
class Mouse: | ||
def __init__(self): | ||
global activate | ||
listener = Listener(on_move=self.on_move, on_click=self.on_click, on_scroll=self.on_scroll) | ||
listener.start() | ||
self.ctrl_c = False | ||
rospy.on_shutdown(self.shutdownhook) | ||
|
||
# TODO 2 Create class variables to store activation status, and x and y position | ||
# Initialize the controller status to False, and in the center of the screen | ||
|
||
# TODO 3 Create a publisher to publish MouseController data on the mouse_info topic | ||
|
||
|
||
|
||
# Handle the event of the user moving the mouse | ||
def on_move(self,x,y): | ||
#We need to establish the use of the global variable for button activation | ||
global activate | ||
|
||
|
||
if(activate == False): | ||
messageString = "No movement sent, activate cursor first by scrolling down on the mouse wheel" | ||
print(messageString, end='') | ||
# overwrite same line | ||
print('\b' *len(messageString), end='', flush=True) | ||
xScale = 0.0 | ||
yScale = 0.0 | ||
else: | ||
# Use the dimensions of the monitor to convert output into x & y between -1 and 1 | ||
xScale = ((x/(xDim/2))-1) | ||
yScale = -((y/(yDim/2))-1) | ||
xFormat = "{:+.3f}".format(xScale) | ||
yFormat = "{:+.3f}".format(yScale) | ||
# create 19 byte message with x,y coordinates embedded and print to screen | ||
positionStr = 'X: ' + str(xFormat) + ' Y: ' + str(yFormat) + " " | ||
print(positionStr, end='') | ||
# overwrite same line | ||
print('\b' *len(positionStr), end='', flush=True) | ||
# TODO 4 Update the appropriate class variables and publish | ||
|
||
|
||
#Currently I'm not doing anything with the button click. | ||
#Eventually we could add additional modes if we wanted to. | ||
def on_click(self,x,y,button,pressed): | ||
pass | ||
|
||
# Handle the event of the user using the scroll wheel on the mouse | ||
def on_scroll(self,x,y,dx,dy): | ||
global activate | ||
if dy == 1: | ||
os.system("clear") | ||
print("Welcome to the mouse controller!\n\n") | ||
print("In order to ACTIVATE the controller scroll down on the mouse wheel.\n\n") | ||
print("In order to DEACTIVATE the controller scroll up on the mouse wheel.\n\n") | ||
print("To close the program, left-click on the terminal window and type ctrl-c.\n\n") | ||
activate = False | ||
if dy == -1: | ||
activate = True | ||
# TODO 5 Update the appropriate class variables and publish | ||
|
||
|
||
# Handle the event of the user pressing ctrl_c | ||
def shutdownhook(self): | ||
# TODO 6 Update the appropriate class variables and publish before shutdown | ||
|
||
|
||
print("Shutting down the client ") | ||
self.ctrl_c = True | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
os.system("clear") | ||
print("Welcome to the mouse controller!\n\n") | ||
print("In order to ACTIVATE the controller scroll down on the mouse wheel.\n\n") | ||
print("In order to DEACTIVATE the controller scroll up on the mouse wheel.\n\n") | ||
print("To close the program, left-click on the terminal window and type ctrl-c.\n\n") | ||
rospy.init_node('Mouse') | ||
Mouse() | ||
rospy.spin() |