diff --git a/README.md b/README.md index e6d00d38a5540404257a6449d24505f0eb6b3859..8a6fb2ac1d4fc7a8420055d87b925e1fbecdcc4c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ pip install git+https://gitlab.control.lth.se/processes/omnibot/omnibot.py ## Usage ### Code -Import the connection-object with `from omnibot.tcp import Connection`. Use the `with Connection(HOST) as bot:` command, as this will automatically open and close the connection cleanly. To e.g. set the reference speed for servo 1 to 100, use `bot.set_speed(1,100)`. To set all servo speeds at once, use `bot.set_speeds([100,100,100])`. +Import the connection-object with `from omnibot.tcp import Connection`. Use the `with Connection(HOST, PORT) as bot:` command, as this will automatically open and close the connection cleanly. To e.g. set the reference speed for servo 1 to 100, use `bot.set_speed(1,100)`. To set all servo speeds at once, use `bot.set_speeds([100,100,100])`. To read positions from the crazyflie, use `x = bot.get_x()`, @@ -29,9 +29,10 @@ from omnibot.tcp import Connection from time import time, sleep # Insert suitable IP-adress -HOST = "localhost" +HOST = "192.168.0.101" +PORT = 9001 -with Connection(HOST) as bot: +with Connection(HOST, PORT) as bot: # Target speed for servos vset = 100 @@ -58,15 +59,16 @@ A pre-defined script which rotates first one way, then the other, and prints log from omnibot.dummybot import run_dummybot # Insert suitable IP-adress -HOST = "localhost" -run_dummybot(HOST) +HOST = "192.168.0.101" +PORT = 9001 +run_dummybot(HOST, PORT) ``` ### Maximum servo speed You can get the maximum absolute value of servo-speed-setpoints with `max_speed = bot.get_max_speed()`. Any value above (below) `max_speed` (`-max_speed`) is rounded down (up) on the server side. ### Network -At the department of automatic control, you should be connected to the omnibots via the same router. Currently this has been done with the router with name *robotlab*, where the IP naming conventions for the robots are `192.168.0.10X` for robot with name `omniX`, i.e. omnibot `omni6` has IP `192.168.0.106`. +At the department of automatic control, you should be connected to the omnibots via the same router. Currently this has been done with the router with name *robotlab*. IP and port conventions: Robot with name *omniX* has IP `192.168.0.10X` and port `900X` e.g.. omnibot `omni10` has IP `192.168.0.110`and port `9006`. ## Support felix.agner@control.lth.se diff --git a/src/omnibot/dummybot.py b/src/omnibot/dummybot.py index 0e52f96e0647a45e3294cc525d345ddbec7c8e8a..3986c16b1e886f4ccebbfb257146fcb2c27707b5 100644 --- a/src/omnibot/dummybot.py +++ b/src/omnibot/dummybot.py @@ -5,7 +5,7 @@ from time import time, sleep from .tcp import Connection -def run_dummybot(HOST,verbose=True): +def run_dummybot(HOST, PORT, verbose=True): """ Runs a dummybot at host HOST that rotates a bit while printing x and y coordinates. """ @@ -13,7 +13,7 @@ def run_dummybot(HOST,verbose=True): ts = 0.1 # sampling time tstart = time() - with Connection(HOST,verbose=verbose) as bot: + with Connection(HOST,PORT,verbose=verbose) as bot: print("Connected") # Target speed for servos @@ -40,11 +40,13 @@ def run_dummybot(HOST,verbose=True): if __name__ == '__main__': # Server settings HOST = "localhost" + PORT = 9998 - if len(sys.argv) > 1: + if len(sys.argv) > 2: # If an input is given to the script, it will be interpreted as the intended - # IP-address. Baseline is localhost. + # IP-address and port. Baseline is localhost, 9998. HOST = sys.argv[1] + PORT = sys.argv[2] print(f"HOST: \t {HOST}") - run_dummybot(HOST) \ No newline at end of file + run_dummybot(HOST,PORT) \ No newline at end of file diff --git a/src/omnibot/tcp.py b/src/omnibot/tcp.py index e35a8c7130c74b536860fc6390d30a88a4217abc..9105b9ce45247ae2e8f45e87487813cb736515d1 100644 --- a/src/omnibot/tcp.py +++ b/src/omnibot/tcp.py @@ -5,10 +5,10 @@ class Connection(object): to an omnibot. HOST: Host name of server (string) - PORT: Port to connect to (int) (default 9998) + PORT: Port to connect to (int) verbose: choose level of chit-chat (boolean) """ - def __init__(self,HOST,PORT=9998,verbose=False): + def __init__(self,HOST,PORT,verbose=False): self.HOST = HOST self.PORT = PORT self.verbose=verbose