# RESOURCES
* YUVRAJ'S TURTLE BOT
https://hackmd.io/@UltraViolet/r1Tt_VJF9/edit
* STEPPER MOTOR TESTING
https://lastminuteengineers.com/drv8825-stepper-motor-driver-arduino-tutorial/
**Code** *--for testing of stepper motors*
```
const int stepPin = 3;
const int dirPin = 4;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
digitalWrite(dirPin,HIGH);
}
void loop() {
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
```
Buck booster are used to covert high AC voltage to 5V DC,it was done by adjusting the W103 screws which is behind the toroid,and inserting the wires of smps to IN of buck booster and OUT were connected to multimerer.and by checking and adjusting we got 15v to 5 v and 5v to 2v
* MODERN C++ RESOURCES
https://youtu.be/sZK6ouwREXA?si=w-dDjVPBbZ4Cm6oq
* CONTROLL OF DC MOTOR WITH RASBERRY PI
https://maker.pro/raspberry-pi/tutorial/how-to-control-a-dc-motor-with-an-l298-controller-and-raspberry-pi
* ROVER EXPLORATION RESOURCE
https://www.sciencedirect.com/science/article/pii/S0094576510000676
motor torque analysis
* ROVER DIMENSIONS

https://a360.co/48EfZKh
ALL DIMENSIONS ARE IN mm
* github resource
https://github.com/ai-winter/ros_motion_planning
https://github.com/addy1997/Robotics-Resources
***Resources***


# Designing ideas:
Methods to make design modular so as to print big stuff:
https://www.youtube.com/watch?v=RTQjvYENR7w
https://www.youtube.com/watch?v=VKZoNRtd_5I
Snap-Fit joints: https://www.youtube.com/watch?v=XaKEC93i_9A
Metal joints without welding: https://www.youtube.com/watch?v=S2dRHK53RM0
# Hardware Requirements
https://docs.google.com/spreadsheets/d/1ckFS2nRfz8N4lwitKCr55SV3ceahfh4EPK2FV2YXLgg/edit#gid=0
* Valve Regulated Lead Acid Battery Management
Battery charging:
https://www.youtube.com/watch?v=Ajt1ElIw8Qg
https://www.youtube.com/watch?v=4Bnr6a1qDWo
https://www.power-sonic.com/blog/how-to-charge-a-lead-acid-battery/#:~:text=The%20battery%20is%20fully%20charged,voltage%20while%20this%20current%20flows
Internal working: https://www.youtube.com/watch?v=hObLxlXJPPM
* OG 555 DC motors, L298N motor driver, PCA9685




* Rpi, NRF24L01 (communication module)

* Arduino UNO, NRF24L01 (communication module)

# SOFTWARE
**Transferring files from device to device**
scp /home/tphanir/motor.py rover@10.87.58.84:/home/rover/rf
scp \<sourcelocation> \<destination>(username@ip:location)
**Rpi Code** *--for testing of all 3 components together - Motor Driver L298N, PCA9685, Rpi*
```
import Adafruit_PCA9685
pwm = Adafruit_PCA9685.PCA9685()
def set_high(channel):
pwm.set_pwm(channel,4096,0)
def set_low(channel):
pwm.set_pwm(channel,0,4096)
set_high(0)
set_low(1)
```
**Rpi Code** *--for connecting 3 L298N motors from Rpi using PCA*
```
import Adafruit_PCA9685
import time
# Initialize PCA9685
pwm = Adafruit_PCA9685.PCA9685()
pwm.set_pwm_freq(60) # Set frequency to 60Hz
# Define PWM channels for motor control (6 motors)
# Assuming each motor uses 2 channels (IN1, IN2) for direction control
left_motor_channels = [
(0, 1), # Motor 1
(2, 3), # Motor 2
(4, 5) # Motor 3
]
right_motor_channels = [
(6, 7), # Motor 1
(8, 9), # Motor 2
(10, 11) # Motor 3
]
# Set a channel high (motor forward)
def set_high(channel):
pwm.set_pwm(channel, 4096, 0)
# Set a channel low (motor backward)
def set_low(channel):
pwm.set_pwm(channel, 0, 4096)
# Stop a motor (set both channels low)
def stop_motor(channel1, channel2):
pwm.set_pwm(channel1, 0, 0)
pwm.set_pwm(channel2, 0, 0)
# Move forward by setting all motors to move forward
def move_forward():
for ch1, ch2 in left_motor_channels + right_motor_channels:
set_high(ch1) # IN1
set_low(ch2) # IN2
# Move backward by setting all motors to move backward
def move_backward():
for ch1, ch2 in left_motor_channels + right_motor_channels:
set_low(ch1) # IN1
set_high(ch2) # IN2
# Stop all motors
def stop():
for ch1, ch2 in left_motor_channels + right_motor_channels:
stop_motor(ch1, ch2)
# Rotate in place (left or right direction)
def rotate(angle, direction='left', time_constant=0.1):
rotation_time = angle * time_constant
if direction == 'left':
# Left motors backward, right motors forward
for ch1, ch2 in left_motor_channels:
set_low(ch1)
set_high(ch2)
for ch1, ch2 in right_motor_channels:
set_high(ch1)
set_low(ch2)
elif direction == 'right':
# Left motors forward, right motors backward
for ch1, ch2 in left_motor_channels:
set_high(ch1)
set_low(ch2)
for ch1, ch2 in right_motor_channels:
set_low(ch1)
set_high(ch2)
# Wait for the calculated rotation time
time.sleep(rotation_time)
stop()
# Main loop
try:
while True:
command = input("Enter command (w/a/s/d/q to quit): ")
if command == 'w':
move_forward()
elif command == 's':
move_backward()
elif command == 'a':
rotate(90, direction='left') # Rotate left by 90 degrees
elif command == 'd':
rotate(90, direction='right') # Rotate right by 90 degrees
elif command == 'q':
stop()
break
else:
print("Invalid command!")
time.sleep(1)
stop()
except KeyboardInterrupt:
pass
finally:
stop()
print("Stopping motors and cleaning up.")
```
**Rpi Code** *--for connecting 3 L298N motors directly from Rpi*
```
import RPi.GPIO as GPIO
import time
# Define GPIO pins for motor control
# Left motors (3 motors)
left_motor_pins = [
(17, 18), # Motor 1
(27, 22), # Motor 2
(23, 24) # Motor 3
]
# Right motors (3 motors)
right_motor_pins = [
(5, 6), # Motor 1
(13, 19), # Motor 2
(26, 21) # Motor 3
]
# Set up GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Set pins as outputs
for pin_pair in left_motor_pins + right_motor_pins:
GPIO.setup(pin_pair[0], GPIO.OUT)
GPIO.setup(pin_pair[1], GPIO.OUT)
# Function to move forward using for loop
def move_forward():
for pin1, pin2 in left_motor_pins + right_motor_pins:
GPIO.output(pin1, GPIO.HIGH)
GPIO.output(pin2, GPIO.LOW)
# Function to move backward using for loop
def move_backward():
for pin1, pin2 in left_motor_pins + right_motor_pins:
GPIO.output(pin1, GPIO.LOW)
GPIO.output(pin2, GPIO.HIGH)
# Stop all motors
def stop():
for pin1, pin2 in left_motor_pins + right_motor_pins:
GPIO.output(pin1, GPIO.LOW)
GPIO.output(pin2, GPIO.LOW)
def rotate(angle, direction='left', time_constant=0.1):
rotation_time = angle*time_constant
if direction == 'left':
# Turn left: left motors backward, right motors forward
for pin1, pin2 in left_motor_pins:
GPIO.output(pin1, GPIO.LOW)
GPIO.output(pin2, GPIO.HIGH)
for pin1, pin2 in right_motor_pins:
GPIO.output(pin1, GPIO.HIGH)
GPIO.output(pin2, GPIO.LOW)
elif direction == 'right':
# Turn right: left motors forward, right motors backward
for pin1, pin2 in left_motor_pins:
GPIO.output(pin1, GPIO.HIGH)
GPIO.output(pin2, GPIO.LOW)
for pin1, pin2 in right_motor_pins:
GPIO.output(pin1, GPIO.LOW)
GPIO.output(pin2, GPIO.HIGH)
# Wait for the calculated rotation time
time.sleep(rotation_time)
stop()
# Main loop
try:
while True:
command = input("Enter command (w/a/s/d/q to quit): ")
if command == 'w':
move_forward()
elif command == 's':
move_backward()
elif command == 'a':
turn_left() # Same logic can be applied to turning functions if needed
elif command == 'd':
turn_right() # Same logic can be applied to turning functions if needed
elif command == 'q':
stop()
break
else:
print("Invalid command!")
time.sleep(1)
stop()
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
```
**Remote Controller for Motors**
```
import serial
import time
ser = serial.Serial("/dev/ttyUSB0", 57600, timeout=1)
ser.flush()
print('dir:')
print('w - Front')
print('a - Left')
print('s - Back')
print('d - Right')
try:
while True:
data = input("Enter: <dir> <time>\n")
ser.write(data.encode())
finally:
ser.close()
```
**Connecting Ublox Neo 6m with Rpi**
```
import serial
import time
import string
import pynmea2
while True:
port=“/dev/ttyAMA0”
ser=serial.Serial(port,baudrate=9600,timeout=0.5)
dataout =pynmea2.NMEAStreamReader()
newdata=ser.readline()
if newdata[0:6]==“$GPRMC”:
newmsg=pynmea2.parse(newdata)
lat=newmsg.latitude
lng=newmsg.longitude
gps=“Latitude=” +str(lat) + “and Longitude=” +str(lng)
print(gps)
```
**Jetson Nano YDLiDAR Code**
```
import os
import math
import ydlidar
import time
import sys
from matplotlib.patches import Arc
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import socket
# Socket Setup
server_socket = socket.socket((socket.AF_INET), socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind(('0.0.0.0', 54321))
server_socket.listen(1)
client_socket, client_address = server_socket.accept()
RMAX = 30
rancorr = 80 / 3.2
rad2deg = 180 / math.pi
deg2rad = math.pi / 180
fig = plt.figure()
fig.canvas.set_window_title('YDLidar LIDAR Monitor')
lidar_polar = plt.subplot(polar=True)
lidar_polar.autoscale_view(True, True, True)
lidar_polar.set_rmax(RMAX)
lidar_polar.grid(True)
ports = ydlidar.lidarPortList()
port = "/dev/ydlidar"
for key, value in ports.items():
port = value
laser = ydlidar.CYdLidar()
laser.setlidaropt(ydlidar.LidarPropSerialPort, port)
laser.setlidaropt(ydlidar.LidarPropSerialBaudrate, 128000)
laser.setlidaropt(ydlidar.LidarPropLidarType, ydlidar.TYPE_TOF)
laser.setlidaropt(ydlidar.LidarPropDeviceType, ydlidar.YDLIDAR_TYPE_SERIAL)
laser.setlidaropt(ydlidar.LidarPropScanFrequency, 6.0)
laser.setlidaropt(ydlidar.LidarPropSampleRate, 5)
laser.setlidaropt(ydlidar.LidarPropSingleChannel, False)
laser.setlidaropt(ydlidar.LidarPropMaxAngle, 90.0)
laser.setlidaropt(ydlidar.LidarPropMinAngle, -90.0)
laser.setlidaropt(ydlidar.LidarPropMaxRange, 4.0)
laser.setlidaropt(ydlidar.LidarPropMinRange, 0.01)
scan = ydlidar.LaserScan()
x_thresh = 40.0
y_thresh = 60.0
objr = None
def mov(r, theta, x_thresh, angle_thresh, move_direction):
if x_thresh > r:
return None
curr = theta
if move_direction == 'left':
while abs(r * math.sin(deg2rad * curr)) < x_thresh:
curr += 1
else:
while abs(r * math.sin(deg2rad * curr)) < x_thresh:
curr -= 1
return theta - curr
def detect(angle, ran):
mmap = {}
for idx, val in enumerate(ran):
if val > 5.0:
mmap[-angle[idx] * rad2deg] = val
mmap = dict(sorted(mmap.items()))
left = {}
right = {}
for ang in mmap.keys():
x = mmap[ang] * math.sin(ang * deg2rad)
y = mmap[ang] * math.cos(ang * deg2rad)
if(abs(x) < x_thresh and abs(y) < y_thresh):
if(ang > 0):
right[ang] = mmap[ang]
else:
left[ang] = mmap[ang]
if len(list(left)) > len(list(right)):
objr = False
elif len(list(right)) > len(list(left)):
objr = True
else:
objr = None
if objr == True:
objs = list(right)[0]
obje = list(right)[-1]
if len(list(left)) > 0:
objs = list(left)[0]
elif objr == False:
objs = list(left)[-1]
obje = list(left)[0]
if len(list(right)) > 0:
objs = list(right)[-1]
if objr == True or objr == False:
y_s = mmap[objs] * math.cos(deg2rad * objs)
y_e = mmap[obje] * math.cos(deg2rad * obje)
y_diff = y_s - y_e
if objr:
angle = mov(mmap[objs], objs, x_thresh, 5, 'left')
else:
angle = mov(mmap[objs], objs, x_thresh, 5, 'right')
if angle == None:
client_socket.sendall("R".encode())
time.sleep(2)
else:
client_socket.sendall(str(angle).encode())
time.sleep(10)
else:
client_socket.sendall("F".encode())
time.sleep(2)
def animate(num):
r = laser.doProcessSimple(scan)
if r:
angle = []
ran = []
intensity = []
with open('data.txt', 'w') as file:
for point in scan.points:
dist = point.range * rancorr
ang = point.angle
angle.append(-ang)
ran.append(dist)
intensity.append(point.intensity)
file.write(f'ang:{ang * rad2deg:.2f}, dist:{dist:.2f}\n')
detect(angle, ran)
time.sleep(2)
#lidar_polar.clear()
#lidar_polar.scatter(angle, ran, c=intensity, cmap='hsv', alpha=0.95)
ret = laser.initialize()
if ret:
ret = laser.turnOn()
if ret:
ani = animation.FuncAnimation(fig, animate, interval=50)
plt.show()
laser.turnOff()
client_socket.close()
server_socket.close()
laser.disconnecting()
plt.close()
```
**Laptop Controller Code**
**Jetson Nano MOTOR CONTROL CODE**
```
#!/usr/bin/env python3
import Jetson.GPIO as GPIO
import time
import serial
right_motor_pins = [
(26, 20),
(17, 18),
(6, 12)
]
left_motor_pins = [
(22, 23),
(8, 11),
(25, 9)
]
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
ser = serial.Serial('/dev/ttyUSB0', 57600, timeout=1)
for pin_pair in left_motor_pins + right_motor_pins:
GPIO.setup(pin_pair[0], GPIO.OUT)
GPIO.setup(pin_pair[1], GPIO.OUT)
def move_forward():
for pin1, pin2 in left_motor_pins + right_motor_pins:
GPIO.output(pin1, GPIO.HIGH)
GPIO.output(pin2, GPIO.LOW)
def move_backward():
for pin1, pin2 in left_motor_pins + right_motor_pins:
GPIO.output(pin2, GPIO.HIGH)
GPIO.output(pin1, GPIO.LOW)
def stop():
for pin1, pin2 in left_motor_pins + right_motor_pins:
GPIO.output(pin1, GPIO.LOW)
GPIO.output(pin2, GPIO.LOW)
def rotate(angle, direction='left', time_constant=0.1):
rotation_time = angle*time_constant
if direction == 'left':
for pin1, pin2 in left_motor_pins:
GPIO.output(pin1, GPIO.LOW)
GPIO.output(pin2, GPIO.HIGH)
for pin1, pin2 in right_motor_pins:
GPIO.output(pin1, GPIO.HIGH)
GPIO.output(pin2, GPIO.LOW)
elif direction == 'right':
for pin1, pin2 in left_motor_pins:
GPIO.output(pin1, GPIO.HIGH)
GPIO.output(pin2, GPIO.LOW)
for pin1, pin2 in right_motor_pins:
GPIO.output(pin1, GPIO.LOW)
GPIO.output(pin2, GPIO.HIGH)
time.sleep(rotation_time)
stop()
def receive_data():
if ser.in_waiting > 0:
data = ser.readline().decode().strip()
return data
def mov(direction, t):
if direction == 'w':
move_forward()
time.sleep(t)
elif direction == 's':
move_backward()
time.sleep(t)
elif direction == 'a':
rotate(90, 'left')
elif direction == 'd':
rotate(90, 'right')
elif direction == 'q':
stop()
return
else:
print("Invalid command!")
stop()
try:
while True:
data = receive_data()
if data:
d, t = data.split(" ")
mov(d, int(t))
finally:
ser.close()
GPIO.cleanup()
```
**RPI Real VNC Server**
10.87.65.120
**Related videos:**
How to use Neo 6M GPS module with Raspberry Pi and Python: https://www.youtube.com/watch?v=N8fH0nc9v9Q&t=363s
Interfacing GPS Module with Raspberry Pi 3 Microcontroller: https://www.youtube.com/watch?v=bsNQK1o2tPU&t=314s
**Ethernet connection with IP addresses and ports - socket communication or TCP/IP communication**
RPi Code:
```
import socket
# Create a socket object
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Get the Raspberry Pi's IP address and port
host = '10.87.58.84' # Listen on all interfaces
port = 12345 # Choose an available port
# Bind the socket to the port
server_socket.bind((host, port))
# Listen for incoming connections
server_socket.listen(5)
print(f"Server listening on {host}:{port}")
# Accept incoming connection
client_socket, addr = server_socket.accept()
print(f"Connection from {addr}")
# Open a text file to save the received data
with open("received_data.txt", "w") as file:
while True:
# Receive data in chunks
data = client_socket.recv(1024).decode('utf-8')
if not data:
break # Exit if no more data is received
print(f"Received: {data}")
# Write data to file
file.write(data + "\n")
# Close the sockets
client_socket.close()
server_socket.close()
```
To find IP address of Rpi, put this in terminal:
```
hostname -I
```
Standard Ports: TCP/UDP port numbers range from 0 to 65535. However, ports below 1024 are typically reserved for system services, so you should choose a port number above 1024. Common ranges are 1025 to 49151 for user applications.
Example Port Selection: For example, you can use port 12345 as long as it's not already in use by another service. Ports like 8080, 5000, or 3000 are also commonly used in networking.
Show all the ports currently in use:
```
sudo netstat -tuln
```
or
```
sudo ss -tuln
```
Jetson Code:
```
import socket
# Create a socket object
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Specify the Raspberry Pi's IP address and port
host = '192.168.x.x' # Replace with the actual IP address of the Raspberry Pi
port = 12345
# Connect to the Raspberry Pi
client_socket.connect((host, port))
# Send data
message = "Hello Raspberry Pi!"
client_socket.send(message.encode('utf-8'))
# Close the socket
client_socket.close()
```
**Radio Telemetry using 3DR 433Mhz between laptop and Rpi**
Rpi:
```
import serial
# Set up the serial connection (adjust /dev/ttyUSB0 if needed)
ser = serial.Serial('/dev/ttyUSB0', 57600, timeout=1) # 57600 baud rate is standard for 3DR radios
ser.flush()
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
print(line)
```
If your device is connected, it will appear in the list as /dev/ttyUSB0. If not, it may be assigned to another port like /dev/ttyUSB1, etc.
```
ls /dev/ttyUSB*
```
Laptop:
```
import serial
# Set up serial communication on the correct port
ser = serial.Serial('COM3', 57600, timeout=1) # Replace 'COM3' with your actual port name
ser.flush()
while True:
# Send a message
ser.write(b"Hello from laptop\n")
# Receive message
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
print(line)
```
Modern C++ for robotics: https://youtu.be/sZK6ouwREXA?si=zhzZ2yOm9z1ZkLzR
BFS Python: https://www.youtube.com/watch?v=D14YK-0MtcQ
DFS Python: https://www.youtube.com/watch?v=sTRK9mQgYuc
A-Star Python: https://www.youtube.com/watch?v=W9zSr9jnoqY
RRT* intro: https://www.youtube.com/watch?v=gP6MRe_IHFo
BFS C++: https://www.youtube.com/watch?v=b5kij1Akf9I&list=PLDzeHZWIZsTryvtXdMr6rPh4IDexB5NIA&index=94
DFS C++:
Harsh's person tracking code implementation:
* Open CV installation in VS code: https://www.youtube.com/watch?v=ZQcIFCBeSgM
* Pytorch installation: https://www.youtube.com/watch?v=n0P0rIlABOM
# MOM
https://docs.google.com/document/d/1podJ0GV0wFYhOYMR7kRajd_NngMmhun780ZkaKjJZ-w/edit?usp=sharing
# **INSTALLATION OF JETSON NANO**
https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit
first install baleno etcher
https://etcher.balena.io/

download the image
https://developer.nvidia.com/jetson-nano-sd-card-image
flash the image in sd card
* the minimum 32 gb is required
* don't close the baleno etcher window untill it gets uploaded and flashing is completed
insert the card in jetson as follows
https://d29g4g2dyqv443.cloudfront.net/sites/default/files/akamai/embedded/images/jetsonNano/gettingStarted/Jetbot_animation_500x282_2.gif

installation of
* ROS
https://www.waveshare.com/wiki/Install_ROS_System_on_Jetson_Nano_&_Environment_Cofiguration
* GAZEBO
https://www.theconstruct.ai/all-about-gazebo-9-with-ros/
* LIDAR PACKAGES
YOU can get so many errors while installing
# ERRORS
* port is not connected to the lidar
### USB0 error
```
to be added
```
### Battery error sol
```
to be added
```
First one is risky (dont try)
```
sudo ubuntu-drivers autoinstall
```
```
bash .devcontainer/post_create_commands.sh
```
```
roslaunch turtlebot_bringup minimal.launch
```
Run Teleop
```
roslaunch turtlebot_teleop keyboard_teleop.launch
```
ydlidar error sol (put in error file)
```
#include <sys/sysmacros.h>
```
https://github.com/Ebiroll/qemu_esp32/issues/12
Change lidar.launch to:
```
<launch>
<node name="ydlidar_node" pkg="ydlidar" type="ydlidar_node" output="screen" respawn="false" >
<param name="port" type="string" value="/dev/ttyUSB0"/>
<param name="baudrate" type="int" value="128000"/>
<param name="frame_id" type="string" value="base_scan"/>
<param name="resolution_fixed" type="bool" value="true"/>
<param name="auto_reconnect" type="bool" value="true"/>
<param name="reversion" type="bool" value="true"/>
<param name="angle_min" type="double" value="-180" />
<param name="angle_max" type="double" value="180" />
<param name="range_min" type="double" value="0.1" />
<param name="range_max" type="double" value="16.0" />
<param name="ignore_array" type="string" value="" />
<param name="frequency" type="double" value="10"/>
<param name="isTOFLidar" type="bool" value="false"/>
</node>
<node pkg="tf" type="static_transform_publisher" name="base_link_to_laser4"
args="0.2245 0.0 0.2 0.0 0.0 0.0 /base_footprint /base_scan 40" />
</launch>
```
https://github.com/samialperen/oko_slam/blob/master/doc/hector_slam_tutorial.md
Hector Slam Using RPLidar
https://automaticaddison.com/how-to-build-an-indoor-map-using-ros-and-lidar-based-slam/
- Hector-SLAM is an algorithm that uses laser scan data to create a map. The advantage of Hector-SLAM over other SLAM techniques is that it only requires laser scan data to do its job. It doesn’t need odometry data.
# OR
https://github.com/Slamtec/rplidar_sdk/issues/45
# STRUCTURAL ANALYSIS(ANSYS,STATIC)
https://youtube.com/playlist?list=PLICzjIuc4UqH3hllQc1kEF19YoBfAkEBQ&si=B8yL63N1MJbPeays
# Resources for Stepper motor control using arduino and raspberry pi
https://youtu.be/7spK_BkMJys?si=XY3HIAx56px0sVxG
## Crater Detection
### Using Classical CV
https://answers.opencv.org/question/236378/is-there-an-ellipse-detection-algorithm-that-is-robust-to-partially-occluded-objects/
https://docs.opencv.org/3.4/df/d0d/tutorial_find_contours.html
# **Contacts**
Alif Trading-8793139382
Jhulele Hardware-8657777764
++ Aiden's bag has some card
# SSH connection between RPI and Jetson Nano
## On Jetson Nano
### sudo nano /etc/network/interfaces
```
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
```
command to connect directly to the laptop with same network
Edit the Wi-Fi configuration:
bash
Copy code
`sudo nano /etc/wpa_supplicant/wpa_supplicant.conf`
Add your laptop’s hotspot network details:
bash
Copy code
```
network={
ssid="your_hotspot_ssid"
psk="your_hotspot_password"
key_mgmt=WPA-PSK
}
```
Save the file and restart the Wi-Fi interface:
bash
Copy code
`sudo wpa_cli -i wlan0 reconfigure`
3. Assign a Static IP Address to the Jetson Nano
Assigning a static IP ensures the IP address doesn’t change each time you connect to your laptop’s hotspot.
YASH
`ssh jetson@192.168.27.157`
PHANI
```
ssh jetson@192.168.77.20
```
## On RPi 3
### sudo nano /etc/dhcpcd.conf
```
interface eth0
static ip_address=192.168.1.101/24
static routers=192.168.1.1
```
### COMUNICATION
USING NRF24 MODULE
connection of ardiuno to nrf24 module

* first we installed a github repo
https://nrf24.github.io/pyRF24/ as a referense and
<@1075408935739211786> https://pyrf24.readthedocs.io/en/latest/rf24_api.html#pyrf24.rf24.RF24.open_tx_pipe
https://docs.python.org/3/library/stdtypes.html#bytearray
LINKS
https://pyrf24.readthedocs.io/en/latest/rf24_api.html
### detecting the cube using realsense depth camera using jetson nano
we tested the nrf24 modules by using the repository
we sent signals form the laptop to rpi
**PROCESS**
connect the nrf24 module as per the connection in the image
## Cube Detection using LiDAR only
```
#include "ros/ros.h"
#include "sensor_msgs/LaserScan.h"
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
class coordinate
{
public:
float x;
float y;
coordinate(){}
coordinate(float x, float y)
{
this->x = x;
this->y = y;
}
};
class obstacle
{
public:
float THETA;
float THETA_DASH;
float DIMENSION;
coordinate initial;
coordinate final;
obstacle(){}
obstacle(float THETA, float THETA_DASH, float DIMENSION, coordinate initial, coordinate final)
{
this->THETA = THETA;
this->THETA_DASH = THETA_DASH;
this->DIMENSION = DIMENSION;
this->initial = initial;
this->final = final;
}
void display()
{
printf("X: %.2f\t X': %.2f\n", initial.x, final.x);
printf("Y: %.2f\t Y': %.2f\n", initial.y, final.y);
printf("THETA: %.2f\t THETA': %.2f\n", THETA, THETA_DASH);
printf("Length : %.4f\n", DIMENSION);
printf("\n");
}
};
int counter;
float deg2rad(float degrees);
vector<obstacle> detection(vector<float> data);
vector<float> POSSIBLE_AT_ANGLE;
vector<float> POSSIBLE_AT_DISTANCE;
int POSSIBILITIES = 0;
int OBSTACLES = 0;
const float BOUNDARY = 150.0;
float deg2rad(float degrees)
{
return M_PI * degrees / 180.0;
}
vector<obstacle> detection(vector<float> data)
{
vector<obstacle> obstacles;
// REARRANGE
for(int i=0; i<180; i++)
{
float val = data[0];
data.erase(data.begin());
data.push_back(val);
}
for(int i=0; i<360; i+=1)
{
float distance = data[i] * 100;
float vertical_distance = distance * sin(deg2rad(i/2));
float horizontal_distance = distance * cos(deg2rad(i/2));
if((distance > 10.0) && (distance < BOUNDARY))
{
POSSIBLE_AT_DISTANCE.push_back(vertical_distance);
POSSIBLE_AT_ANGLE.push_back(i/2.0);
POSSIBILITIES++;
}
}
// CHECKING OUT POSITION
// for(int i=0; i<POSSIBILITIES; i++)
// {
// ROS_INFO("Angle: %.2f\t Vertical Distance: %.2f \n", POSSIBLE_AT_ANGLE[i], POSSIBLE_AT_DISTANCE[i]);
// }
// FILTERING
for(int i=0; i<POSSIBILITIES - 1; i++)
{
float THETA = POSSIBLE_AT_ANGLE[i];
float DISTANCE = data[THETA * 2] * 100;
float X_COORDINATE = DISTANCE * cos(deg2rad(THETA));
float Y_COORDINATE = DISTANCE * sin(deg2rad(THETA));
coordinate initial(X_COORDINATE, Y_COORDINATE);
while(abs(POSSIBLE_AT_DISTANCE[i] - POSSIBLE_AT_DISTANCE[i+1]) < 5.0 && abs(POSSIBLE_AT_ANGLE[i] - POSSIBLE_AT_ANGLE[i+1]) < 5.0)
{
i++;
}
float THETA_DASH = POSSIBLE_AT_ANGLE[i];
float DISTANCE_DASH = data[THETA_DASH * 2] * 100;
float X_COORDINATE_DASH = DISTANCE_DASH * cos(deg2rad(THETA_DASH));
float Y_COORDINATE_DASH = DISTANCE_DASH * sin(deg2rad(THETA_DASH));
coordinate final(X_COORDINATE_DASH, Y_COORDINATE_DASH);
float length = sqrt(pow((X_COORDINATE - X_COORDINATE_DASH),2) + pow((Y_COORDINATE - Y_COORDINATE_DASH),2));
// printf("X: %.2f\t X': %.2f\n", X_COORDINATE, X_COORDINATE_DASH);
// printf("Y: %.2f\t Y': %.2f\n", Y_COORDINATE, Y_COORDINATE_DASH);
// printf("THETA: %.2f\t THETA': %.2f\n", THETA, THETA_DASH);
// printf("Length : %.4f\n", length);
// printf("\n");
if(length > 18.0 && length < 22.0))
{
obstacles.push_back(obstacle(THETA, THETA_DASH, length, initial, final));
}
}
return obstacles;
}
void scan_callback(const sensor_msgs::LaserScan::ConstPtr msg)
{
ROS_INFO("Scan : [%d] \n", ++counter);
ros::Rate loop(0.25);
vector<float> scan = msg->ranges;
vector<obstacle> found;
found = detection(scan);
for(int i=0; i<found.size() && found.size()==1; i++)
{
found[i].display();
cout << "\n";
}
loop.sleep();
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "scan_detect");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe<sensor_msgs::LaserScan>("/scan",1, scan_callback);
ros::spin();
return 0;
}
```
### 10th May 2024
## Installing librealsense for Jetson Nano
Following source : https://dev.intelrealsense.com/docs/nvidia-jetson-tx2-installation
```
sudo apt-key adv --keyserver keys.gnupg.net --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE
```
```
sudo add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo bionic main" -u
```
```
sudo apt-get install librealsense2-utils
sudo apt-get install librealsense2-dev
```
### 10th May 2024
## Installing opencv on Jetson Nano
```
git clone https://github.com/opencv/opencv.git
git -C opencv checkout 4.x
```
```
cd opencv
mkdir build && cd build
cmake ..
```
```
make -j4
```

**RPI**

https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up/0
# CONTROL OF ROVER
```
systemctl enable control.service
```
this line is to enable control.py to run after jetson reboot
```
systemctl start control.service
```
to start the service
`systemctl status control.service `
to check the status and finding error if it is not starting
# HMC5883L Magnetometer
Library to be used in Arduino -
**QMC5883LCompass** by MPrograms
https://github.com/mprograms/QMC5883LCompass
1. Calibrate the Magnetometer.
2. Find the offsets.
3. Run the main compass with proper offsets.
#### While working with the module, it should be kept away from electronics for calibration and as well as direction. On the robot, it should be mounted on a elevation.
# YDLiDAR SDK - X2
Open Terminal on Jetson Nano
### Step 1:
```
git clone https://github.com/YDLIDAR/YDLidar-SDK.git
```
### Step 2:
```
cd YDLidar-SDK
```
### Step 3:
If there is a file named **ydlidar_config.h**, skip this step
```
cp ydlidar_config.h.in ydlidar_config.h
```
### Step 4:
```
mkdir build && cd build
cmake ..
make
sudo make install
```
#### Available at : https://github.com/YDLIDAR/YDLidar-SDK/blob/master/doc/Dataset.md
| **Model** | **Baudrate** | **Sample Rate (K)** | **Range (m)** | **Frequency (Hz)** | **Intensity (bit)** | **Single Channel** | **Voltage (V)** |
|-------------|--------------|---------------------|---------------|--------------------|---------------------|--------------------|-----------------|
| X4 | 128000 | 5 | 0.12~10.0 | 5~12 (PWM) | false | false | 4.8~5.2 |
### Step 5:
Making a udev file to setup the LiDAR
**Follow this : https://github.com/YDLIDAR/YDLidar-SDK/blob/master/doc/howto/how_to_create_a_udev_rules.md**
# pyrealsense2 on Jetson Nano
```
git clone https://github.com/JetsonHacksNano/installLibrealsense.git
cd installLibrealsense/
./installLibrealsense.sh
./buildLibrealsense.sh
```
Find the path to pyrealsense in /usr/local/lib
(in /usr/local/lib/python__version__)
e.g. **/usr/local/lib/python3.6**
Then,
```
echo "export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.6" >> ~/.bashrc
source ~/.bashrc
```
## DETECTNET
github cloning
[https://github.com/dusty-nv/jetson-inference/blob/master/docs/detectnet-camera-2.md
](https://)
## jetson voice
[https://www.youtube.com/watch?v=QXIwdsyK7Rw](https://)
## control of rover
using GUI
```
import tkinter as tk
from tkinter import ttk, messagebox, PhotoImage
from PIL import Image, ImageTk
import serial
from serial.tools import list_ports
import time
# Constants for Styling
TITLE_FONT = ("Segoe UI", 36, "bold") # Increased font size
LABEL_FONT = ("Segoe UI", 14) # Increased font size
BG_COLOR = "#2C3E50"
FG_COLOR = "#FFFFFF"
class SerialHandler:
def __init__(self, port, baud_rate=57600, timeout=1):
"""
Initialize a serial port connection.
Args:
port (str): The serial port (e.g., '/dev/ttyACM0').
baud_rate (int): The baud rate for the serial communication.
timeout (float): Timeout for read operations, in seconds.
"""
self.port = port
self.baud_rate = baud_rate
self.timeout = timeout
self.serial_connection = None
def open(self):
"""
Open the serial connection.
"""
try:
self.serial_connection = serial.Serial(self.port, self.baud_rate, timeout=self.timeout)
print(f"[INFO] Serial connection opened on {self.port} at {self.baud_rate} baud.")
#self.write(f'[INFO] Serial Radio connection established on {self.port} at {self.baud_rate} baud.\n')
except serial.SerialException as e:
print(f"[ERROR] Failed to open serial port {self.port}:\n{e}")
def close(self):
"""
Close the serial connection.
"""
if self.serial_connection and self.serial_connection.is_open:
print(f"[INFO] Serial connection on {self.port} closed.")
#self.write(f'[INFO] Radio connection on {self.port} closed.\n')
self.serial_connection.close()
else:
print(f"[WARNING] Serial connection on {self.port} is already closed.")
def write(self, data):
"""
Write data to the serial port.
Args:
data (str or bytes): Data to send.
"""
if self.serial_connection and self.serial_connection.is_open:
if isinstance(data, str):
data = data.encode() # Convert string to bytes
self.serial_connection.write(data)
print(f"[INFO] Sent data: {data}")
else:
print(f"[ERROR] Serial connection on {self.port} is not open.")
time.sleep(0.25)
def is_open(self):
"""
Check if the serial connection is open.
Returns:
bool: True if the serial connection is open, False otherwise.
"""
return self.serial_connection and self.serial_connection.is_open
class GenesisGUI:
def __init__(self, root):
self.root = root
self.selected_port = tk.StringVar()
self.motion_var = tk.StringVar(value="No motion detected")
self.current_motion = None
self.in_home_menu = True
self.radio = None
self.auto = False
self.manual = False
self.root.title("Genesis Control Panel")
self.root.geometry("900x900") # Increased window size
self.root.configure(bg=BG_COLOR)
self.create_widgets()
# Bind Esc key to exit the application
self.root.bind("<Escape>", self.exit_application)
def create_widgets(self):
"""Create all widgets in the GUI."""
self.clear_window()
self.in_home_menu = True
# Title
title = tk.Label(self.root, text="Genesis Control", font=TITLE_FONT, fg=FG_COLOR, bg=BG_COLOR)
title.pack(pady=30)
# Serial Port Selection
port_frame = tk.Frame(self.root, bg=BG_COLOR)
port_frame.pack(pady=30)
tk.Label(port_frame, text="Select Serial Port:", font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR).pack(side=tk.LEFT, padx=10)
self.port_dropdown = ttk.Combobox(port_frame, textvariable=self.selected_port, state="readonly", width=40)
self.port_dropdown.pack(side=tk.LEFT, padx=20)
ttk.Button(port_frame, text="Refresh", command=self.refresh_ports).pack(side=tk.LEFT, padx=10)
self.refresh_ports()
# Mode Selection Buttons
mode_frame = tk.Frame(self.root, bg=BG_COLOR)
mode_frame.pack(pady=50)
# Manual Mode Button
manual_button = tk.Canvas(mode_frame, width=150, height=150, bg=BG_COLOR, highlightthickness=0)
manual_button.grid(row=0, column=0, padx=30)
manual_button.create_oval(10, 10, 120, 120, fill="#007BFF", outline="")
manual_button_text = manual_button.create_text(65, 65, text="Manual", fill=FG_COLOR, font=("Segoe UI", 14, "bold"))
manual_button.tag_bind(manual_button_text, "<Button-1>", lambda e: self.activate_manual_mode())
# Autonomous Mode Button
autonomous_button = tk.Canvas(mode_frame, width=150, height=150, bg=BG_COLOR, highlightthickness=0)
autonomous_button.grid(row=0, column=1, padx=30)
autonomous_button.create_oval(10, 10, 120, 120, fill="#28A745", outline="")
autonomous_button_text = autonomous_button.create_text(65, 65, text="Auto", fill=FG_COLOR, font=("Segoe UI", 14, "bold"))
autonomous_button.tag_bind(autonomous_button_text, "<Button-1>", lambda e: self.activate_autonomous_mode())
# Status Bar
self.status_var = tk.StringVar(value="Status: Ready")
self.status_bar = tk.Label(self.root, textvariable=self.status_var, font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR, anchor="w", relief=tk.SUNKEN)
self.status_bar.pack(side=tk.BOTTOM, fill=tk.X)
# Start polling serial data
#self.poll_serial_data()
def refresh_ports(self):
"""Refresh the list of available serial ports."""
ports = list_ports.comports()
serial_ports = [port.device for port in ports if port.description.lower() != 'n/a']
self.port_dropdown['values'] = serial_ports
self.selected_port.set(serial_ports[0] if serial_ports else "")
self.radio = SerialHandler(self.selected_port.get())
def activate_manual_mode(self):
"""Activate manual mode."""
self.radio.open()
self.radio.write("Manual\n")
self.manual = True
self.in_home_menu = False
self.clear_window()
# Instructions
instructions = tk.Label(self.root, text="Use W, A, S, D for movement. Press B to go back. Release keys to stop.", font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR)
instructions.pack(pady=30)
# Motion Status
motion_status = tk.Label(self.root, textvariable=self.motion_var, font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR)
motion_status.pack(pady=30)
# Bind keypress and keyrelease events
self.root.bind("<KeyRelease>", self.handle_keyrelease)
self.root.bind("<KeyPress>", self.handle_keypress)
def activate_autonomous_mode(self):
"""Activate autonomous mode."""
self.radio.open()
self.clear_window()
instructions = tk.Label(self.root, text="Select Navigation Mode", font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR)
instructions.pack(pady=30)
# Buttons for GPS and Non-GPS options
gps_button = ttk.Button(self.root, text="With GPS", command=self.activate_with_gps)
gps_button.pack(pady=20)
non_gps_button = ttk.Button(self.root, text="Without GPS", command=self.activate_without_gps)
non_gps_button.pack(pady=20)
def activate_with_gps(self):
"""Menu for GPS-based navigation."""
self.clear_window()
instructions = tk.Label(self.root, text="GPS Navigation", font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR)
instructions.pack(pady=20)
# Buttons for Set and Go
set_button = ttk.Button(self.root, text="Set Coordinates", command=self.set_coordinates)
set_button.pack(pady=20)
go_button = ttk.Button(self.root, text="Go", command=self.send_go_message)
go_button.pack(pady=20)
# Bind keypress and keyrelease events
self.root.bind("<KeyPress>", self.handle_keypress)
def set_coordinates(self):
"""Set target GPS coordinates."""
self.radio.write(f"set\n")
self.clear_window()
instructions = tk.Label(self.root, text="Enter Target GPS Coordinates", font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR)
instructions.pack(pady=20)
self.gps_entry = tk.Entry(self.root, font=LABEL_FONT)
self.gps_entry.pack(pady=10)
set_button = ttk.Button(self.root, text="Set", command=self.store_coordinates)
set_button.pack(pady=20)
self.root.bind("<KeyPress>", self.handle_keypress)
def store_coordinates(self):
"""Store and display target GPS coordinates."""
self.target_coordinates = self.gps_entry.get() # Store the coordinates
if not self.target_coordinates:
messagebox.showerror("Error", "Please enter valid GPS coordinates.")
return
self.clear_window()
instructions = tk.Label(self.root, text=f"Target Coordinates Set: {self.target_coordinates}", font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR)
instructions.pack(pady=20)
go_button = ttk.Button(self.root, text="Go", command=self.send_go_message)
go_button.pack(pady=20)
def send_go_message(self):
"""Send the 'Go' message with the target coordinates."""
if hasattr(self, "target_coordinates") and self.target_coordinates:
self.radio.write(f"gps {self.target_coordinates}\n")
messagebox.showinfo("Message Sent", f"Sent GO command with coordinates: {self.target_coordinates}")
self.clear_window()
instructions = tk.Label(self.root, text="Auto GPS Activated", font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR)
instructions.pack(pady=20)
else:
messagebox.showerror("Error", "Target coordinates not set.")
def activate_without_gps(self):
"""Menu for non-GPS autonomous mode."""
self.clear_window()
instructions = tk.Label(self.root, text="Non-GPS Autonomous Navigation Started", font=LABEL_FONT, fg=FG_COLOR, bg=BG_COLOR)
instructions.pack(pady=30)
self.radio.write('Semi-Autonomous'.encode('utf-8') + b'\n')
# Bind keypress and keyrelease events
self.root.bind("<KeyPress>", self.handle_keypress)
self.root.bind("<KeyRelease>", self.handle_keyrelease)
def handle_keyrelease(self, event):
key = event.char.upper()
motions = {
"W": "Moving Forward",
"A": "Turning Left",
"S": "Moving Backward",
"D": "Turning Right",
"B": "Returning to Main Menu",
}
if key in motions:
self.motion_var.set("Stop")
self.radio.write('stop\n')
def handle_keypress(self, event):
"""Handle keypress events for manual control."""
key = event.char.upper()
self.clicked = time.time()
motions = {
"W": "Moving Forward",
"A": "Turning Left",
"S": "Moving Backward",
"D": "Turning Right",
"B": "Returning to Main Menu",
}
if key in motions:
if key == "B":
self.radio.write('stop\n')
self.back_to_menu()
return
if self.current_motion != key:
self.current_motion = key
self.motion_var.set(motions[key])
self.radio.write(f'{key}\n')
def back_to_menu(self):
"""Return to the main menu."""
self.clear_window()
self.radio.close()
self.create_widgets()
self.auto = False
self.manual = False
self.root.unbind("<KeyPress>")
self.root.unbind("<KeyRelease>")
def poll_serial_data(self):
"""Poll the serial port for incoming data."""
if self.ser and self.ser.is_open:
try:
data = self.ser.readline().decode('utf-8').strip()
if data:
self.status_var.set(f"Received: {data}")
except Exception as e:
self.status_var.set(f"Error: {str(e)}")
self.root.after(100, self.poll_serial_data) # Poll every 100 ms
def clear_window(self):
"""Clear all widgets from the window."""
for widget in self.root.winfo_children():
widget.destroy()
def exit_application(self, event=None):
"""Exit the application when Esc is pressed in the home menu."""
if self.in_home_menu:
self.root.quit()
else:
messagebox.showwarning("Exit Denied", "You can only exit from the home menu.")
def run(self):
"""Run the GUI main loop."""
self.root.mainloop()
if __name__ == "__main__":
root = tk.Tk()
app = GenesisGUI(root)
app.run()
```
# gps navigation code
# obstacle avoidance code