| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.utils.Utils; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.config.RedisProperties; |
| | | import com.zy.acs.manager.common.utils.MapDataUtils; |
| | | import com.zy.acs.manager.core.constant.MapDataConstant; |
| | | import com.zy.acs.manager.core.service.astart.DynamicNodeType; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.time.StopWatch; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.core.io.Resource; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.PreDestroy; |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | |
| | | private CodeService codeService; |
| | | @Autowired |
| | | private MapService mapService; |
| | | @Autowired |
| | | private RedisProperties redisProperties; |
| | | |
| | | @PostConstruct |
| | | @SuppressWarnings("all") |
| | |
| | | return; |
| | | } |
| | | |
| | | // python |
| | | AgvModel agvModel = agvModelService.selectByType(AgvModelType.CTU_BOX_TRANSPORT_AGV.toString()); // can be optimized |
| | | |
| | | Double avoidDistance = MapDataUtils.getVehicleWaveSafeDistance(agvModel.getDiameter(), MapDataConstant.MAX_DISTANCE_BETWEEN_ADJACENT_AGV_FACTOR); |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | |
| | | ProcessBuilder processBuilder = new ProcessBuilder("python" |
| | | , "D:\\tmp\\pyagv\\agv4.py" |
| | | , String.valueOf(avoidDistance) |
| | | ); |
| | | processBuilder.redirectErrorStream(true); |
| | | Resource resource = new ClassPathResource("agv.py"); |
| | | |
| | | File tempScript = null; |
| | | |
| | | try { |
| | | InputStream is = resource.getInputStream(); |
| | | tempScript = File.createTempFile("agv", ".py"); |
| | | tempScript.deleteOnExit(); |
| | | |
| | | Files.copy(is, tempScript.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | | tempScript.setExecutable(true); |
| | | |
| | | ProcessBuilder processBuilder = new ProcessBuilder( |
| | | "python" // 或者 "python3" 取决于系统配置 |
| | | , tempScript.getAbsolutePath() |
| | | , String.valueOf(avoidDistance) |
| | | , redisProperties.getHost() |
| | | , redisProperties.getPassword() |
| | | , String.valueOf(redisProperties.getPort()) |
| | | , String.valueOf(redisProperties.getIndex()) |
| | | ); |
| | | |
| | | processBuilder.redirectErrorStream(true); |
| | | |
| | | // File file = resource.getFile(); |
| | | // ProcessBuilder processBuilder = new ProcessBuilder( |
| | | // "python" |
| | | // , file.getAbsolutePath() |
| | | // , String.valueOf(avoidDistance) |
| | | // , redisProperties.getHost() |
| | | // , redisProperties.getPassword() |
| | | // , String.valueOf(redisProperties.getPort()) |
| | | // , String.valueOf(redisProperties.getIndex()) |
| | | // ); |
| | | // processBuilder.redirectErrorStream(true); |
| | | |
| | | Process process = processBuilder.start(); |
| | | |
| | | // 读取Python脚本的输出 |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| | | String line; |
| | | StringBuilder builder = new StringBuilder(); |
| | |
| | | builder.append(line); |
| | | } |
| | | |
| | | // 等待Python脚本执行完成 |
| | | int exitCode = process.waitFor(); |
| | | if (exitCode != 0) { |
| | | System.out.println("Python script exited with error code: " + exitCode); |
| | | log.error("Python script exited with error code: {}", exitCode); |
| | | log.error("python error:{}", builder.toString()); |
| | | return; |
| | | } |
| | | reader.close(); |
| | |
| | | } |
| | | log.error("python finish {}", System.currentTimeMillis() - startTime); |
| | | |
| | | // java |
| | | // String[][] codeMatrix = mapDataDispatcher.getCodeMatrix(lev); |
| | | // String[][] waveMatrix = mapDataDispatcher.initWaveMatrix(lev); |
| | | // |