diff --git a/src/index.ts b/src/index.ts index 11b4a8f..c1c63d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,3 +49,4 @@ export { MicrosdCardElement } from './microsd-card-element'; export { DipSwitch8Element } from './dip-switch-8-element'; export { StepperMotorElement } from './stepper-motor-element'; export { HX711Element } from './hx711-element'; +export { RoboticArmElement } from './robotic-arm-element'; diff --git a/src/react-types.ts b/src/react-types.ts index d01088b..c593875 100644 --- a/src/react-types.ts +++ b/src/react-types.ts @@ -48,6 +48,7 @@ import { MicrosdCardElement } from './microsd-card-element'; import { DipSwitch8Element } from './dip-switch-8-element'; import { StepperMotorElement } from './stepper-motor-element'; import { HX711Element } from './hx711-element'; +import { RoboticArmElement } from './robotic-arm-element'; type WokwiElement = Partial & React.ClassAttributes; @@ -101,6 +102,7 @@ declare global { 'wokwi-dip-switch-8': WokwiElement; 'wokwi-stepper-motor': WokwiElement; 'wokwi-hx711': WokwiElement; + 'wokwi-robotic-arm': WokwiElement; } } } diff --git a/src/robotic-arm-element.stories.ts b/src/robotic-arm-element.stories.ts new file mode 100644 index 0000000..469f7ae --- /dev/null +++ b/src/robotic-arm-element.stories.ts @@ -0,0 +1,55 @@ +import { html } from 'lit'; +import './robotic-arm-element'; + +export default { + title: 'Robotic Arm', + component: 'wokwi-robotic-arm', + argTypes: { + shoulderAngle: { control: { type: 'range', min: 240, max: 360 } }, + elbowAngle: { control: { type: 'range', min: 0, max: 134 } }, + gripperAngle: { control: { type: 'range', min: 264, max: 360 } }, + wristAngle: { control: { type: 'range', min: 0, max: 100 } }, + gripperColor: { control: { type: 'color' } }, + armColor: { control: { type: 'color' } }, + jointColor: { control: { type: 'color' } }, + }, + args: { + shoulderAngle: 240, + elbowAngle: 100, + gripperAngle: 280, + wristAngle: 56, + gripperColor: '#eeeedd', + armColor: '#ffffdd', + jointColor: '#111111', + }, +}; + +const Template = ({ + shoulderAngle, + elbowAngle, + wristAngle, + gripperAngle, + gripperColor, + armColor, + jointColor, +}) => + html``; + +export const Default = Template.bind({}); +Default.args = { + shoulderAngle: 297, + elbowAngle: 52, + wristAngle: 56, + gripperAngle: 270, + gripperColor: '#eeeedd', + armColor: '#ffffdd', + jointColor: '#111111', +}; diff --git a/src/robotic-arm-element.ts b/src/robotic-arm-element.ts new file mode 100644 index 0000000..f064e5b --- /dev/null +++ b/src/robotic-arm-element.ts @@ -0,0 +1,209 @@ +import { html, LitElement } from 'lit'; +import { customElement, property } from 'lit/decorators.js'; +import { ElementPin } from '.'; +import { GND, VCC } from './pin'; + +@customElement('wokwi-robotic-arm') +export class RoboticArmElement extends LitElement { + /** + * Angle of shoulder + */ + @property() shoulderAngle = 297; + + /** + * Angle of elbow + */ + @property() elbowAngle = 52; + + /** + * Angle of wrist + */ + @property() wristAngle = 56; + + /** + * Angle of gripper + */ + @property() gripperAngle = 270; + + /** + * The color of the gripper + */ + @property() gripperColor = '#eeeedd'; + + /** + * The color of the arm + */ + @property() armColor = '#ffffdd'; + + /** + * The color of the joints + */ + @property() jointColor = '#111111'; + + readonly pinInfo: ElementPin[] = [ + { name: 'PWM1', y: 195, x: 25, number: 1, signals: [{ type: 'pwm' }] }, + { name: 'PWM2', y: 195, x: 30, number: 2, signals: [{ type: 'pwm' }] }, + { name: 'PWM3', y: 195, x: 35, number: 3, signals: [{ type: 'pwm' }] }, + { name: 'PWM4', y: 195, x: 40, number: 3, signals: [{ type: 'pwm' }] }, + { name: 'VCC', y: 195, x: 44.5, number: 4, signals: [VCC()] }, + { name: 'GND', y: 195, x: 49, number: 5, signals: [GND()] }, + ]; + + render() { + const { elbowAngle, wristAngle, shoulderAngle, gripperAngle } = this; + return html` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `; + } +}