# Jupyter Notebook \[Melodic]

## Installation

Run the below code in terminal to install

```
$ sudo apt install python-pip
```

{% hint style="info" %}
Remember the robot's password is the single digit number "1".
{% endhint %}

After installing, upgrade pip by running the below command in the terminal shell.

```
$ pip install --upgrade pip
```

Next, we install jupyter, matplotib, pandas, and numpy by running the below command in the terminal shell. This may take a while.

```
$ pip install jupyter matplotlib numpy pandas
```

## Open Jupyter Notebook

In the command line, run the below line to open Jupyter Notebook. Jupyter Notebook is a \_\_ that will run on your browser.&#x20;

```
$ jupyter notebook
```

Running the command, you should see output like above, before being redirected to a webpage like the image below.

![](https://3827101858-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-McPC4jDSGGTd1f6bAav%2F-Me42-gOEuLSlONyKCYi%2F-Me45gXPtZ4kEIgdGyEe%2Fimage.png?alt=media\&token=2b1b4630-08b7-4ab7-8fba-9bd662196955)

Next, navigate to the Documents folder and press the "New" button like below. Then press "Python 2" to create a new Python 2 script.

![](https://3827101858-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-McPC4jDSGGTd1f6bAav%2F-Me42-gOEuLSlONyKCYi%2F-Me45vIhm1HX8gjAFg5c%2Fimage.png?alt=media\&token=e5cbc0b0-c791-4e68-8174-8b099fb88be9)

## Control R1mini with Jupyter Notebook

#### Moving Robot

Import necessary libaries -- rospy to control all ROS-based functions in Python, and Twist and Point datatypes of geometry\_msgs.msg

```
import rospy
from geometry_msgs.msg import Point, Twist
```

Initialize necessary variables. Instantiating speed as a variable of the Twist datatype, initializing a rosnode called "test\_cmd\_vel", setting the rate (how frequently to run the program) to 100, and initialize a publisher to the /cmd\_vel topic of Twist datatype called pub.

```
speed = Twist()
rospy.init_node("test_cmd_vel")
rate = rospy.Rate(100)
pub = rospy.Publisher("/cmd_vel", Twist, queue_size=1)
```

Next, set speed in the x-direction to 0.5

```
speed.linear.x = 0.5
```

Next, type the below three lines to move the robot.

```
while True:
    pub.publish(speed)
    rate.sleep()
```

Press the square to stop the robot.

![Image courtesy of Omorobot.](https://3827101858-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-McPC4jDSGGTd1f6bAav%2F-Me48Pw25fMMiTishw0m%2F-Me4OGq5gNXHyNo_FiBL%2Fimage.png?alt=media\&token=a7f6f917-dddc-4146-a812-4728d6febbef)

#### Checking Battery State

To check the battery state of the R1mini, run the below code.&#x20;

```
from omo_r1mini_bringup.srv import Battery

bat_status = rospy.ServiceProxy("/battery_status", Battery)
bat_status()
```

![](https://3827101858-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-McPC4jDSGGTd1f6bAav%2F-Me4yTRo2vfnVxdi_pYq%2F-Me52uxKT_PQP-yFfzmx%2Fimage.png?alt=media\&token=3be09daf-7010-4707-bd5e-1c71011f1bc8)

The output should look like the image above.

#### Changing LED Colors

To change the colors of the LED at the front of the robot, enter the below code into the a code block. The below code sets the LEDs to an RGB value of 250, 50, 50. You can change what color you would like by adjusting the RGB values in line 4.

```
from omo_r1mini_bringup.srv import Color

set_led = rospy.ServiceProxy("/set_led_color", Color)
set_led(250, 50, 50)
```

## Video Demonstration

To see a a video demonstration for this page, check out this link: [https://www.youtube.com/watch?v=LY0JIf\_0XQ4](https://www.youtube.com/watch?v=LY0JIf_0XQ4)
