首页
统计
留言
Search
1
测试1
1,974 阅读
2
测试2
1,262 阅读
3
typecho内嵌B站视频
1,052 阅读
4
测试3神经猫
1,029 阅读
5
Matlab 计算机视觉实验-UI
978 阅读
Java学习记录
Matlab学习记录
测试
路径规划学习
登录
Search
Mango57
累计撰写
22
篇文章
累计收到
2
条评论
首页
栏目
Java学习记录
Matlab学习记录
测试
路径规划学习
页面
统计
留言
搜索到
22
篇与
mango57
的结果
2022-10-28
java日历学习
package Test4; import java.util.Scanner; import java.util.GregorianCalendar; import java.util.Calendar; public class Rili { final static String blank=" "; final static String border=" | "; public static void PrintWeek() { String [] week={"周日","周一","周二","周三","周四","周五","周六"}; for(int i=0;i<3;i++) { for(String element:week) { System.out.printf(" %s"+" ",element); } if(i<2) System.out.print(border); else System.out.println(blank); } } public static void PrintFestival(GregorianCalendar day,int month) { for(int i=7;i>=1;i--) { day.add(Calendar.DAY_OF_MONTH,-i); int monthday=day.get(Calendar.DAY_OF_MONTH); if(month-1==day.get(Calendar.MONTH)) {if(month==1&&monthday==1) System.out.print("元旦节"); else if (month==4&&monthday==1) System.out.print("愚人节"); else if (month==5&&monthday==1) System.out.print("劳动节"); else if (month==3&&monthday==8) System.out.print("妇女节"); else if (month==6&&monthday==1) System.out.print("儿童节"); else if (month==7&&monthday==1) System.out.print("建党节"); else if (month==8&&monthday==1) System.out.print("建军节"); else if (month==9&&monthday==10) System.out.print("教师节"); else if (month==10&&monthday==1) System.out.print("国庆节"); else if (month==11&&monthday==11) System.out.print("双十一"); else if (month==12&&monthday==25) System.out.print("圣诞节"); else System.out.print(blank); } else System.out.print(blank); day.add(Calendar.DAY_OF_MONTH,i); } } public static void PrintBorderLine(String symbol1,String symbol2,String symbol3) { for(int j=1;j<4;j++) { for(int k=1;k<8;k++) System.out.print(symbol1); if(j<3) System.out.print(symbol2); else System.out.println(symbol3); } } public static void PrintLine(GregorianCalendar day,int m,int month,int year) { int week = day.get(Calendar.DAY_OF_WEEK); GregorianCalendar today = new GregorianCalendar (); if(m==1) { for(int i=0;i<week-1;i++) System.out.print(blank); for(int i=0;i<=7-week;i++) { if(day==today) System.out.printf("%4d* ",day.get(Calendar.DAY_OF_MONTH)); else System.out.printf("%4d ",day.get(Calendar.DAY_OF_MONTH)); day.add(Calendar.DAY_OF_MONTH,1); } } if(m>=2&&m<=4) { for(int i=1;i<=7;i++) { if(year==today.get(Calendar.YEAR)&&month==today.get(Calendar.MONTH)&&today.get(Calendar.DAY_OF_MONTH)==day.get(Calendar.DAY_OF_MONTH)) System.out.printf("%4d* ",day.get(Calendar.DAY_OF_MONTH)); else System.out.printf("%4d ",day.get(Calendar.DAY_OF_MONTH)); day.add(Calendar.DAY_OF_MONTH,1); } } if(m>=5) { for(int i=1;i<=7;i++) { if(month==day.get(Calendar.MONTH)) { if(year==today.get(Calendar.YEAR)&&month==today.get(Calendar.MONTH)&&today.get(Calendar.DAY_OF_MONTH)==day.get(Calendar.DAY_OF_MONTH)) System.out.printf("%4d* ",day.get(Calendar.DAY_OF_MONTH)); else System.out.printf("%4d ",day.get(Calendar.DAY_OF_MONTH)); } else System.out.print(blank); day.add(Calendar.DAY_OF_MONTH,1); } } } public static void printmonth(int month) { for(int i=1;i<=3;i++) System.out.print(blank); if(month==1) System.out.print("*一月*"); else if (month==2) System.out.print("*二月*"); else if (month==3) System.out.print("*三月*"); else if (month==4) System.out.print("*四月*"); else if (month==5) System.out.print("*五月*"); else if (month==6) System.out.print("*六月*"); else if (month==7) System.out.print("*七月*"); else if (month==8) System.out.print("*八月*"); else if (month==9) System.out.print("*九月*"); else if (month==10) System.out.print("*十月*"); else if (month==11) System.out.print("*十一*"); else if (month==12) System.out.print("*十二*"); for(int i=1;i<=3;i++) System.out.print(blank); } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("请输入四位年份..."); int year = in.nextInt(); System.out.println(""); System.out.println(""); for (int i=1;i<=10;i++) System.out.print(blank); System.out.printf("***%4d年日历如下***",year); System.out.println(""); System.out.println(""); for(int i=1;i<=4;i++) { PrintWeek(); PrintBorderLine(blank," | ",blank); GregorianCalendar day1 = new GregorianCalendar(year,3*i-3,1); GregorianCalendar day2 = new GregorianCalendar(year,3*i-2,1); GregorianCalendar day3 = new GregorianCalendar(year,3*i-1,1); for(int m=1;m<=6;m++) { PrintLine(day1,m,3*i-3,year); System.out.print(border); PrintLine(day2,m,3*i-2,year); System.out.print(border); PrintLine(day3,m,3*i-1,year); System.out.println(blank); PrintFestival(day1,3*i-2); System.out.print(border); PrintFestival(day2,3*i-1); System.out.print(border); PrintFestival(day3,3*i); System.out.println(blank); PrintBorderLine(blank," | ",blank); } printmonth(3*i-2); System.out.print(border); printmonth(3*i-1); System.out.print(border); printmonth(3*i); System.out.println(blank); PrintBorderLine("------","--+---",blank); if(i<4) PrintBorderLine(blank," | ",blank); } } }
2022年10月28日
489 阅读
0 评论
0 点赞
2022-09-16
pve安装黑群晖
1、创建虚拟机2、分离删除硬盘和dvd3、引导4、添加硬盘选sata5、修改引导顺序6、启动打开群晖助手或 https://finds.synology.com/
2022年09月16日
587 阅读
0 评论
0 点赞
2022-07-27
Python CCD读取及计算偏移
from typing import re import serial # 导入串口包 import time # 导入时间包 ser = serial.Serial("COM4", 115200, timeout=5) # 开启com5口,波特率115200,超时5 ser.flushInput() # 清空缓冲区 def main(): #读取CCD数据 msg = ser.read(270).decode("gbk","ignore") a = msg[msg.find("*"):] if len(a) == 270: # print("a:%s" % a) a=a else: a = msg[msg.find("*"):] + ser.read(270).decode()[:270 - len(msg[msg.find("*"):])] # print(msg[msg.find("*"):]) # print("b:" + a) return a def max_length(*lst): return max(*lst, key=lambda v: len(v)) while True: b = main() # print(b) #完整信息 c = b[11:267] # print("16进制:"+c) d=[] n=0 # print(len(a)) while n<255 : c1=c[n:n+2] #两两分割 c2 = int(c[n:n + 2], 16) #进制转化 # print(c) d.append(c2) n=n+2 print("原灰度值列表:"+str(d)) #灰度值列表 d_max=str(max(d)) d_min=str(min(d)) # d_min_x=str(d.index(min(d)))#最小值索引 d_ts=str(round(min(d)*1.3)) #调整阈值 print("最大灰度值" + d_max, "最小灰度值:" + d_min, "阈值:"+d_ts) # 找出小于阈值的灰度值 list1 = [] temp = [] d_ts_z=[] for i in range(len(d)): if d[i] < round(min(d)*1.3): temp.append(d[i]) else: list1.append(temp) print("阈值以下列表:"+str(temp)," 个数:"+str(len(temp))) temp1=list(enumerate(d))#原灰度值列表元素元组化 # print("原灰度值列表元组化:"+str(temp1)) p=[i for i, j in enumerate(d) if j <min(d)*1.3] #找出列表中小于阈值的灰度值索引 print("阈值以下灰度值坐标:"+str(p)) # 方法1:判断坐标连续个数 ==1 # b = [] # for a in range(len(p) - 1): # # print(p[a], p[a] + 1) # # print(p[a-1],p[a]) # if p[a + 1] - p[a] <= 2: # b.append(p[a]) # # print("连续:" + str(a), p[a], p[a + 1], b) # # else: # # print("不连续:" + str(a)) # # print("连续个数为:" + str(a),"连续的坐标为:"+str(b)) # 方法2 判断坐标连续个数 s1 = [] # 定义一个空列表 s2 = [] for x in sorted(set(p)): s1.append(x) if x + 1 not in p: if len(s1) > 5:#判断连续多少个 # print(""+str(s1)) s2.append(s1) # else: # print("连续像素未大于6个") s1 = [] print("总"+str(s2)) move = None py_length= None if s2 !=[]: scan=True print("最长列表:"+str(max_length(s2))) s3=max_length(s2) if len(s3)%2==0: center = int(len(s3) / 2) center_z=s3[center-1] print("中心坐标为:"+str(center_z+0.5),"对应灰度值为:"+str(d[center_z])) # print("偶数", center) py_length=round(((center_z+0.5)-64.5)*1) if py_length<0: move="左移" # print(move,py_length) elif py_length==0: move = "中间" # print(move,py_length) else: move="右移" # print(move, str(py_length)+"\n") else: center = int((len(s3) + 1) / 2) center_z=s3[center-1] print("中心坐标为:"+str(center_z),"对应灰度值为:"+str(d[center_z])) # print("奇数", center) py_length=round(((center_z)-64.5)*1) if py_length<0: move="左移" # print(move,py_length) elif py_length==0: move = "中间" # print(move,py_length) else: move="右移" # print(move, str(py_length)+"\n") else: # print("未识别到\n") scan=False print(scan,move,str(py_length)+"\n") if __name__ == '__main__': main()
2022年07月27日
623 阅读
0 评论
0 点赞
2022-07-06
航迹推算张
import serial import time import math def get_date(): """ 此函数通过串口接收数据,并把每一帧数据提取出来,以列表的形式存储每一帧数据,为后续数据提取做基础 :return: a_list 每一帧数据的列表 """ ser = serial.Serial( # 下面这些参数根据情况修改 port='COM5', # 串口 baudrate=115200, # 波特率 parity=serial.PARITY_NONE, # 校验位 stopbits=serial.STOPBITS_ONE, # 停止位 bytesize=serial.EIGHTBITS, # 字节大小 timeout=1) while True: msg = ser.read_all() # 读取全部数据 # msg = ser.readline() # 读取遇换行符换行 # msg = b'\x00\x00\x00\x00\x00\x00\x00\xfb\xa6\xfe46(\x00\x00\x00\x01\x00\x01_\xe8E' 原始数据格式,后续要做转换 # print('raw', msg) """ 备用代码 d = 1 for key in msg: if d % 24 == 0: print(hex(key)) else: print(hex(key), end=' ') d = d + 1 """ a_list = [] # 空列表 for key in msg: a = hex(key) # 将stm32发来的原始数据转换为16进制 # 提取包含帧头帧尾24字节的16进制数据并保存到a_list列表中 while a == "0x7b" and len(a_list) < 25: for key01 in msg: a = hex(key01) a_list.append(a) if len(a_list) == 24 and a_list[2] != "0x7b": return a_list pos_x = 0 # 此处赋予小车初始位姿 接收二维码赋予的初值 pos_y = 0 theta = 0 sampling_time = 0.02 # 积分时间 while True: b_list = get_date() # 测试代码 # print(b_list[2], b_list[3]) # print(int(b_list[2], 16), int(b_list[3], 16), int(b_list[19], 16)) # print(type(int(b_list[3], 16))) # print("小车速度:%f 小车角速度:%f" % ((float(int(b_list[3], 16))) / 1000, (float(int(b_list[19], 16))) / 3753)) # 此处用来判断小车前进或者后退,逆时针旋转或者顺时针旋转。然后在此基础上赋予速度变量和角速度变量正负号 # print(type(bin(int(b_list[2], 16))[2])) 注意此处为字符串类型,需要做转换才能判断 【易搞错,重要!】 if int(bin(int(b_list[2], 16))[2]) == 0: # 判断高八位中的最高位二进制是否为0,若为0,则小车前进,在这里进行了二进制转换 robot_vel = (float(int(b_list[2] + b_list[3][2:], 16))) / 1000 else: robot_vel = -((int("0xffff", 16) - int(b_list[2] + b_list[3][2:], 16)) / 1000) if int(bin(int(b_list[18], 16))[2]) == 0: # 判断高八位中的最高位二进制是否为0,若为0,则小车绕Z轴逆时针旋转正方向,在这里进行了二进制转换 angular_velocity_z = (float(int(b_list[18] + b_list[19][2:], 16))) / 3753 else: angular_velocity_z = -((int("0xffff", 16) - int(b_list[18] + b_list[19][2:], 16)) / 3753) # robot_vel = (float(int(b_list[3], 16))) / 1000 此为未加判断速度和角速度方向时的旧代码 # angular_velocity_z = (float(int(b_list[19], 16))) / 3753 if robot_vel != float(0): # 有编码器的速度则进行计算 if angular_velocity_z < float(0.03): # imu静止时也会有微小输出,设置一个阈值来表示小车实际运动了 angular_velocity_z = float(0) theta += angular_velocity_z * sampling_time pos_x += (robot_vel * math.cos(theta)) * sampling_time pos_y += (robot_vel * math.sin(theta)) * sampling_time else: theta += angular_velocity_z * sampling_time pos_x += (robot_vel * math.cos(theta)) * sampling_time pos_y += (robot_vel * math.sin(theta)) * sampling_time else: angular_velocity_z = 0 # 若小车速度为0,此处应赋值等于初始位姿,即位姿不发生变化 print("小车速度是:%f 航向数据是:%f x轴数据是:%f y轴的数据是:%f" % (robot_vel, theta, pos_x, pos_y))
2022年07月06日
412 阅读
0 评论
0 点赞
2022-06-27
python A*
代码 import math import matplotlib.pyplot as plt from numpy import arange show_animation = True class AStarPlanner: def __init__(self, ox, oy, resolution, rr): """ Initialize grid map for a star planning ox: x position list of Obstacles [m] oy: y position list of Obstacles [m] resolution: grid resolution [m] rr: robot radius[m] """ self.resolution = resolution self.rr = rr self.min_x, self.min_y = 0, 0 self.max_x, self.max_y = 0, 0 self.obstacle_map = None self.x_width, self.y_width = 0, 0 self.motion = self.get_motion_model() self.calc_obstacle_map(ox, oy) class Node: def __init__(self, x, y, cost, parent_index): self.x = x # index of grid self.y = y # index of grid self.cost = cost self.parent_index = parent_index def __str__(self): return str(self.x) + "," + str(self.y) + "," + str( self.cost) + "," + str(self.parent_index) def planning(self, sx, sy, gx, gy): """ A star path search input: s_x: start x position [m] s_y: start y position [m] gx: goal x position [m] gy: goal y position [m] output: rx: x position list of the final path ry: y position list of the final path """ start_node = self.Node(self.calc_xy_index(sx, self.min_x), self.calc_xy_index(sy, self.min_y), 0.0, -1) goal_node = self.Node(self.calc_xy_index(gx, self.min_x), self.calc_xy_index(gy, self.min_y), 0.0, -1) open_set, closed_set = dict(), dict() open_set[self.calc_grid_index(start_node)] = start_node while 1: if len(open_set) == 0: print("Open set is empty..") break c_id = min( open_set, key=lambda o: open_set[o].cost + self.calc_heuristic(goal_node, open_set[ o])) current = open_set[c_id] # show graph if show_animation: # pragma: no cover plt.plot(self.calc_grid_position(current.x, self.min_x), self.calc_grid_position(current.y, self.min_y), "xc") # for stopping simulation with the esc key. plt.gcf().canvas.mpl_connect('key_release_event', lambda event: [exit( 0) if event.key == 'escape' else None]) if len(closed_set.keys()) % 10 == 0: plt.pause(0.001) if current.x == goal_node.x and current.y == goal_node.y: print("Find goal") goal_node.parent_index = current.parent_index goal_node.cost = current.cost break # Remove the item from the open set del open_set[c_id] # Add it to the closed set closed_set[c_id] = current # expand_grid search grid based on motion model for i, _ in enumerate(self.motion): node = self.Node(current.x + self.motion[i][0], current.y + self.motion[i][1], current.cost + self.motion[i][2], c_id) n_id = self.calc_grid_index(node) # If the node is not safe, do nothing if not self.verify_node(node): continue if n_id in closed_set: continue if n_id not in open_set: open_set[n_id] = node # discovered a new node else: if open_set[n_id].cost > node.cost: # This path is the best until now. record it open_set[n_id] = node rx, ry = self.calc_final_path(goal_node, closed_set) return rx, ry def calc_final_path(self, goal_node, closed_set): # generate final course rx, ry = [self.calc_grid_position(goal_node.x, self.min_x)], [ self.calc_grid_position(goal_node.y, self.min_y)] parent_index = goal_node.parent_index while parent_index != -1: n = closed_set[parent_index] rx.append(self.calc_grid_position(n.x, self.min_x)) ry.append(self.calc_grid_position(n.y, self.min_y)) parent_index = n.parent_index return rx, ry @staticmethod def calc_heuristic(n1, n2): w = 1.0 # weight of heuristic d = w * math.hypot(n1.x - n2.x, n1.y - n2.y) return d def calc_grid_position(self, index, min_position): """ calc grid position :param index: :param min_position: :return: """ pos = index * self.resolution + min_position return pos def calc_xy_index(self, position, min_pos): return round((position - min_pos) / self.resolution) def calc_grid_index(self, node): return (node.y - self.min_y) * self.x_width + (node.x - self.min_x) def verify_node(self, node): px = self.calc_grid_position(node.x, self.min_x) py = self.calc_grid_position(node.y, self.min_y) if px < self.min_x: return False elif py < self.min_y: return False elif px >= self.max_x: return False elif py >= self.max_y: return False # collision check if self.obstacle_map[node.x][node.y]: return False return True def calc_obstacle_map(self, ox, oy): self.min_x = round(min(ox)) self.min_y = round(min(oy)) self.max_x = round(max(ox)) self.max_y = round(max(oy)) print("min_x:", self.min_x) print("min_y:", self.min_y) print("max_x:", self.max_x) print("max_y:", self.max_y) self.x_width = round((self.max_x - self.min_x) / self.resolution) self.y_width = round((self.max_y - self.min_y) / self.resolution) print("x_width:", self.x_width) print("y_width:", self.y_width) # obstacle map generation self.obstacle_map = [[False for _ in range(self.y_width)] for _ in range(self.x_width)] for ix in range(self.x_width): x = self.calc_grid_position(ix, self.min_x) for iy in range(self.y_width): y = self.calc_grid_position(iy, self.min_y) for iox, ioy in zip(ox, oy): d = math.hypot(iox - x, ioy - y) if d <= self.rr: self.obstacle_map[ix][iy] = True break @staticmethod def get_motion_model(): # dx, dy, cost motion = [[1, 0, 1], [0, 1, 1], [-1, 0, 1], [0, -1, 1], [-1, -1, math.sqrt(2)], [-1, 1, math.sqrt(2)], [1, -1, math.sqrt(2)], [1, 1, math.sqrt(2)]] return motion def main(): print(__file__ + " start!!") # start and goal position #起点 sx = 10.0 # [dm] sy = 10.0 # [dm] #终点 gx = 112.0 # [dm] gy = 65.0 # [dm] grid_size = 2.0 # [dm] robot_radius = 1.5 # [dm] 机器人半径 # set obstacle positions ox, oy = [], [] for i in arange(0,136.79): #下 ox.append(i) oy.append(0.0) for i in arange(0, 72.70): #右 ox.append(136.79) oy.append(i) for i in arange(0, 137): #上 ox.append(i) oy.append(72.70) for i in arange(0, 72.70): #左 ox.append(0.0) oy.append(i) # 讲台桌子 for i in arange(25.43, 45.43):#左 ox.append(13.43) oy.append(i) for i in arange(25.43, 46):#右 ox.append(20.43) oy.append(i) for i in arange(13.43, 20.43):#下 ox.append(i) oy.append(25.43) for i in arange(13.43, 20.43):#上 ox.append(i) oy.append(45.43) # 1桌子(左下) for i in arange(13.43, 19.37):#左 ox.append(19.45) oy.append(i) for i in arange(13.43, 20):#右 ox.append(79.45) oy.append(i) for i in arange(19.45, 79.45):#下 ox.append(i) oy.append(13.43) for i in arange(19.37, 79.45):#上 ox.append(i) oy.append(19.45) # 2桌子(右下) for i in arange(13.43, 19.37):#左 ox.append(84.38) oy.append(i) for i in arange(13.43, 20):#右 ox.append(132.39) oy.append(i) for i in arange(84.38, 132.39):#下 ox.append(i) oy.append(13.43) for i in arange(84.38, 132.39):#上 ox.append(i) oy.append(19.37) # 3桌子(左上) for i in arange(53.72, 59.72):#左 ox.append(19.45) oy.append(i) for i in arange(53.72, 60):#右 ox.append(79.45) oy.append(i) for i in arange(19.45, 79.45):#下 ox.append(i) oy.append(53.72) for i in arange(19.45, 79.45):#上 ox.append(i) oy.append(59.72) # 4桌(右上) for i in arange(53.72, 59.72):#左 ox.append(84.38) oy.append(i) for i in arange(53.72, 60):#右 ox.append(132.39) oy.append(i) for i in arange(84.38, 132.39):#下 ox.append(i) oy.append(53) for i in arange(84.38, 132.39):#上 ox.append(i) oy.append(59.72) # 下桌 for i in arange(19.37, 31.38):#左 ox.append(119.95) oy.append(i) for i in arange(19.37, 31.38):#右 ox.append(125.95) oy.append(i) for i in arange(119.95, 125.95):#上 ox.append(i) oy.append(31.38) # 上桌 for i in arange(41.72, 53.72):#左 ox.append(119.95) oy.append(i) for i in arange(41.72, 53.72):#右 ox.append(125.95) oy.append(i) for i in arange(119.95, 125.95):#下 ox.append(i) oy.append(41.72) # 下空调 for i in arange(0, 4.47):#左 ox.append(55.53) oy.append(i) for i in arange(0, 4.47):#右 ox.append(60.58) oy.append(i) for i in arange(55.53, 60.58):#上 ox.append(i) oy.append(4.47) # 上空调 for i in arange(68.23, 72.70):#左 ox.append(57.49) oy.append(i) for i in arange(68.23, 72.70):#右 ox.append(62.54) oy.append(i) for i in arange(57.49, 62.54):#下 ox.append(i) oy.append(68.23) # 上空调 for i in arange(66.26, 72.70):#左 ox.append(118.22) oy.append(i) for i in arange(118.22, 136.79):#下 ox.append(i) oy.append(66.26) if show_animation: # pragma: no cover plt.plot(ox, oy, ".k") plt.plot(sx, sy, "og") plt.plot(gx, gy, "xb") plt.grid(True) plt.axis("equal") a_star = AStarPlanner(ox, oy, grid_size, robot_radius) rx, ry = a_star.planning(sx, sy, gx, gy) if show_animation: # pragma: no cover plt.plot(rx, ry, "-r") plt.pause(0.001) plt.title('6604 A*') plt.show() if __name__ == '__main__': main()pic
2022年06月27日
515 阅读
0 评论
0 点赞
1
2
...
5