RUVIDEO
Поделитесь видео 🙏

Forward Kinematics 2R robotic arm using python

python code is below
#Python code to show simualtion of forward kinematics 2R robotic arm

import math #due to use of pi,trigonometric function
import matplotlib.pyplot as plt #for plotting graph

#inputs:-

l1=1 #link 1 length
l2=0.5 #link 2 length

n_theta=10
theta_start=0 #from +ve x-axis
theta_end=math.pi/2 #to +ve y-axis i.e 1st quadrant

#Generating theta1 and theta2 array

import numpy as np #due to use of linspace command
theta1=np.linspace(theta_start, theta_end, n_theta) #n_theta values with equal spacing in 1st quadrant
theta2=theta1


"""
#Another option for generating theta1 and theta2 array
theta1=[]
theta2=[]
for i in range(0,n_theta):
tmp=theta_start+i*(theta_end-theta_start)/(n_theta-1)
theta1.append(tmp)
theta2.append(tmp)

"""

#plotting
#fixed point of link 1
x0=0
y0=0
ct=1 #Counter variable to count number of plots
for t1 in theta1: #for all values of theta1
for t2 in theta2: #for all values of theta2

#plotting x1 and y1 position
x1=l1*math.cos(t1)
y1=l1*math.sin(t1)

#plotting x2 and y2 position
x2=x1+l2*math.cos(t2)
y2=y1+l2*math.sin(t2)

#Giving name to figure
filename='figure %05d.png' %ct #one way to give name to figures generated using string and integer format specifier

#Alternate way to give name to figures generated
#filename=str(ct) + '.png' #giving name using integer to string command

ct=ct+1 #incrementing counter variable to store next position figure
#print(filename) #to print file name in command window

plt.figure() #to save each position in seperate figures
plt.plot(x0,y0,'o',color='r')
plt.plot([x0,x1],[y0,y1],linewidth=3) #plotting link 1 position and increase link thickness
plt.plot(x1,y1,'o',color='r')
plt.plot([x1,x2],[y1,y2],linewidth=3) #plotting link 2 position and increase link thickness
plt.plot(x2,y2,'o',color='r')
plt.xlim([0,2]) #giving x-axis limit
plt.ylim([0,2]) #giving y-axis limit
#plt.title('Position of links for particular value of theta') #to give title to figure
#plt.show() #to show the plot after running code
plt.savefig(filename) #to save each figure file in particular code saved folder


#collection, sorting and animation

import glob #for collection of specified type of file
#Create the frames
#Collecting all same type of files from code saved folder
imgs=glob.glob("*.png") # to include all the .png files #it collect all number of .png files from that folder, it might contain other program .png files also
print(imgs) #and finally it displays all files randomly arranged in output window


#Sorting
import natsort #to use natsorted command we imported natsort module
images = natsort.natsorted(imgs,reverse=False) #For sorting files saved by glob name in ascending(descending reverse=True)
print(images) #displays all files in sorted order in output window


from PIL import Image
frames=[] #empty array assigned
for i in images: #i from 0 to length of images-1
new_frame=Image.open(i) # open all the png files one by one using open command from Image module and store in new_frame
frames.append(new_frame) # append all the png files to an empty array 'frames' from 'new_frame'

#print(frames) #it displays array address in output window

print(type(frames)) #it displays type/class of frame array and output says 'list'

#byHeight = sorted(filename, key=lambda x: Image.open(x).height)

#Animation

#save into a GIF file
frames[0].save('png_to_gif.gif', format='GIF', append_images=frames[1:], save_all=True, duration=500)

#save_all=True/False for true it saves all frames and animation works and if False gif file of only first image is saved and
#no gif work since no gif is made of only one position

#frames[0] means it start from index 0 of frame array and
#append_images=frames[1:] then append list from index 1 onwards.

#duration decide duration b/w to position in millisecond

#"png_to_gif.gif" is filename of gif with .gif extension is must to play animation.

#format='GIF' is not required when we use filename with extension type you can also remove it no issue

#loop=2 to play 2 loops and loop=0 means the loop goes on forever and
#if you want the loop to go on for one time you will have to equate the loop to 1

#gif to mp4 conversion
import moviepy.editor as mp

clip=mp.VideoFileClip('png_to_gif.gif') #enter name of gif file with extension

clip.write_videofile("Forward_Kinematics_2R_robotic_arm.mp4") #give name with .mp4 extension

#END

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Forward Kinematics 2R robotic arm using python», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.